filename
stringlengths
3
9
code
stringlengths
4
2.03M
390553.c
#include <stdio.h> #include <math.h> #define EPSILON 1e-6 int main(void) { int n = 4091721929; float x = 2.0; int p = (int)(n/2); while(p*p > n) p = (int)(p/2); if(p*p == n){ printf("根号%u = %.6f\n", n, p); return 0; } x = p; for(int i=0; i<10; i++){ x = (x + n/x)/2; } printf("根号%u = %.6f\n", n, x); return 0; }
670848.c
/** * Copyright (C) 2008 Seapeak.Xu / [email protected] * * FastLib may be copied only under the terms of the GNU General * Public License V3, which may be found in the FastLib source kit. * Please visit the FastLib Home Page http://www.csource.org/ for more detail. **/ #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <unistd.h> #include <string.h> #include <sys/stat.h> #include "io_opt.h" int mkdir_by_cascading(const char *path, mode_t mode) { int length,pointer_postion = 0; char *postion; // some compiler reports warning without(char *) char *path_temp = (char *)path; char cwd[MAX_PATH_SIZE]; char *subfolder; int result = 0; if(NULL == getcwd(cwd,sizeof(cwd))) { return -1; } if(*path_temp == '/') { if(-1 == chdir("/")) { return -2; } pointer_postion ++; } while(pointer_postion != strlen(path_temp)) { postion = strchr(path_temp+pointer_postion,'/'); if(NULL == postion) { length = strlen(path_temp) - pointer_postion; } else { length = postion - path_temp - pointer_postion; } do { subfolder = (char *)calloc(length,sizeof(char)); if(NULL == subfolder) { result = -3; break; } memcpy(subfolder,path_temp+pointer_postion,length); if(is_dir(subfolder)) { // if subfolder exists, do not create, just chdir to it if(-1 == chdir(subfolder)) { result = -2; break; } } else { // if subfolder not exists, creates it if(-1 == mkdir(subfolder,mode)) { result = -4; break; } if(-1 == chdir(subfolder)) { result = -2; break; } } }while(0); if(NULL != subfolder) { free(subfolder); subfolder = NULL; } pointer_postion += 0 == postion ? length : length + 1; } return result; } int is_dir(const char *dir_path) { struct stat buf; if (0 != stat(dir_path, &buf)) { return 0; } return S_ISDIR(buf.st_mode); }
158805.c
// SPDX-License-Identifier: GPL-2.0+ /* * Driver for Realtek PCI-Express card reader * * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved. * * Author: * Wei WANG ([email protected]) * Micky Ching ([email protected]) */ #include <linux/blkdev.h> #include <linux/kthread.h> #include <linux/sched.h> #include <linux/workqueue.h> #include "rtsx.h" #include "ms.h" #include "sd.h" #include "xd.h" MODULE_DESCRIPTION("Realtek PCI-Express card reader rts5208/rts5288 driver"); MODULE_LICENSE("GPL"); static unsigned int delay_use = 1; module_param(delay_use, uint, 0644); MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device"); static int ss_en; module_param(ss_en, int, 0644); MODULE_PARM_DESC(ss_en, "enable selective suspend"); static int ss_interval = 50; module_param(ss_interval, int, 0644); MODULE_PARM_DESC(ss_interval, "Interval to enter ss state in seconds"); static int auto_delink_en; module_param(auto_delink_en, int, 0644); MODULE_PARM_DESC(auto_delink_en, "enable auto delink"); static unsigned char aspm_l0s_l1_en; module_param(aspm_l0s_l1_en, byte, 0644); MODULE_PARM_DESC(aspm_l0s_l1_en, "enable device aspm"); static int msi_en; module_param(msi_en, int, 0644); MODULE_PARM_DESC(msi_en, "enable msi"); static irqreturn_t rtsx_interrupt(int irq, void *dev_id); /*********************************************************************** * Host functions ***********************************************************************/ static const char *host_info(struct Scsi_Host *host) { return "SCSI emulation for PCI-Express Mass Storage devices"; } static int slave_alloc(struct scsi_device *sdev) { /* * Set the INQUIRY transfer length to 36. We don't use any of * the extra data and many devices choke if asked for more or * less than 36 bytes. */ sdev->inquiry_len = 36; return 0; } static int slave_configure(struct scsi_device *sdev) { /* * Scatter-gather buffers (all but the last) must have a length * divisible by the bulk maxpacket size. Otherwise a data packet * would end up being short, causing a premature end to the data * transfer. Since high-speed bulk pipes have a maxpacket size * of 512, we'll use that as the scsi device queue's DMA alignment * mask. Guaranteeing proper alignment of the first buffer will * have the desired effect because, except at the beginning and * the end, scatter-gather buffers follow page boundaries. */ blk_queue_dma_alignment(sdev->request_queue, (512 - 1)); /* Set the SCSI level to at least 2. We'll leave it at 3 if that's * what is originally reported. We need this to avoid confusing * the SCSI layer with devices that report 0 or 1, but need 10-byte * commands (ala ATAPI devices behind certain bridges, or devices * which simply have broken INQUIRY data). * * NOTE: This means /dev/sg programs (ala cdrecord) will get the * actual information. This seems to be the preference for * programs like that. * * NOTE: This also means that /proc/scsi/scsi and sysfs may report * the actual value or the modified one, depending on where the * data comes from. */ if (sdev->scsi_level < SCSI_2) { sdev->scsi_level = SCSI_2; sdev->sdev_target->scsi_level = SCSI_2; } return 0; } /*********************************************************************** * /proc/scsi/ functions ***********************************************************************/ /* we use this macro to help us write into the buffer */ #undef SPRINTF #define SPRINTF(args...) \ do { \ if (pos < buffer + length) \ pos += sprintf(pos, ## args); \ } while (0) /* queue a command */ /* This is always called with scsi_lock(host) held */ static int queuecommand_lck(struct scsi_cmnd *srb, void (*done)(struct scsi_cmnd *)) { struct rtsx_dev *dev = host_to_rtsx(srb->device->host); struct rtsx_chip *chip = dev->chip; /* check for state-transition errors */ if (chip->srb) { dev_err(&dev->pci->dev, "Error: chip->srb = %p\n", chip->srb); return SCSI_MLQUEUE_HOST_BUSY; } /* fail the command if we are disconnecting */ if (rtsx_chk_stat(chip, RTSX_STAT_DISCONNECT)) { dev_info(&dev->pci->dev, "Fail command during disconnect\n"); srb->result = DID_NO_CONNECT << 16; done(srb); return 0; } /* enqueue the command and wake up the control thread */ srb->scsi_done = done; chip->srb = srb; complete(&dev->cmnd_ready); return 0; } static DEF_SCSI_QCMD(queuecommand) /*********************************************************************** * Error handling functions ***********************************************************************/ /* Command timeout and abort */ static int command_abort(struct scsi_cmnd *srb) { struct Scsi_Host *host = srb->device->host; struct rtsx_dev *dev = host_to_rtsx(host); struct rtsx_chip *chip = dev->chip; dev_info(&dev->pci->dev, "%s called\n", __func__); scsi_lock(host); /* Is this command still active? */ if (chip->srb != srb) { scsi_unlock(host); dev_info(&dev->pci->dev, "-- nothing to abort\n"); return FAILED; } rtsx_set_stat(chip, RTSX_STAT_ABORT); scsi_unlock(host); /* Wait for the aborted command to finish */ wait_for_completion(&dev->notify); return SUCCESS; } /* * This invokes the transport reset mechanism to reset the state of the * device */ static int device_reset(struct scsi_cmnd *srb) { struct rtsx_dev *dev = host_to_rtsx(srb->device->host); dev_info(&dev->pci->dev, "%s called\n", __func__); return SUCCESS; } /* * this defines our host template, with which we'll allocate hosts */ static struct scsi_host_template rtsx_host_template = { /* basic userland interface stuff */ .name = CR_DRIVER_NAME, .proc_name = CR_DRIVER_NAME, .info = host_info, /* command interface -- queued only */ .queuecommand = queuecommand, /* error and abort handlers */ .eh_abort_handler = command_abort, .eh_device_reset_handler = device_reset, /* queue commands only, only one command per LUN */ .can_queue = 1, /* unknown initiator id */ .this_id = -1, .slave_alloc = slave_alloc, .slave_configure = slave_configure, /* lots of sg segments can be handled */ .sg_tablesize = SG_ALL, /* limit the total size of a transfer to 120 KB */ .max_sectors = 240, /* emulated HBA */ .emulated = 1, /* we do our own delay after a device or bus reset */ .skip_settle_delay = 1, /* module management */ .module = THIS_MODULE }; static int rtsx_acquire_irq(struct rtsx_dev *dev) { struct rtsx_chip *chip = dev->chip; dev_info(&dev->pci->dev, "%s: chip->msi_en = %d, pci->irq = %d\n", __func__, chip->msi_en, dev->pci->irq); if (request_irq(dev->pci->irq, rtsx_interrupt, chip->msi_en ? 0 : IRQF_SHARED, CR_DRIVER_NAME, dev)) { dev_err(&dev->pci->dev, "rtsx: unable to grab IRQ %d, disabling device\n", dev->pci->irq); return -1; } dev->irq = dev->pci->irq; pci_intx(dev->pci, !chip->msi_en); return 0; } #ifdef CONFIG_PM /* * power management */ static int rtsx_suspend(struct pci_dev *pci, pm_message_t state) { struct rtsx_dev *dev = pci_get_drvdata(pci); struct rtsx_chip *chip; if (!dev) return 0; /* lock the device pointers */ mutex_lock(&dev->dev_mutex); chip = dev->chip; rtsx_do_before_power_down(chip, PM_S3); if (dev->irq >= 0) { free_irq(dev->irq, (void *)dev); dev->irq = -1; } if (chip->msi_en) pci_disable_msi(pci); pci_save_state(pci); pci_enable_wake(pci, pci_choose_state(pci, state), 1); pci_disable_device(pci); pci_set_power_state(pci, pci_choose_state(pci, state)); /* unlock the device pointers */ mutex_unlock(&dev->dev_mutex); return 0; } static int rtsx_resume(struct pci_dev *pci) { struct rtsx_dev *dev = pci_get_drvdata(pci); struct rtsx_chip *chip; if (!dev) return 0; chip = dev->chip; /* lock the device pointers */ mutex_lock(&dev->dev_mutex); pci_set_power_state(pci, PCI_D0); pci_restore_state(pci); if (pci_enable_device(pci) < 0) { dev_err(&dev->pci->dev, "%s: pci_enable_device failed, disabling device\n", CR_DRIVER_NAME); /* unlock the device pointers */ mutex_unlock(&dev->dev_mutex); return -EIO; } pci_set_master(pci); if (chip->msi_en) { if (pci_enable_msi(pci) < 0) chip->msi_en = 0; } if (rtsx_acquire_irq(dev) < 0) { /* unlock the device pointers */ mutex_unlock(&dev->dev_mutex); return -EIO; } rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03, 0x00); rtsx_init_chip(chip); /* unlock the device pointers */ mutex_unlock(&dev->dev_mutex); return 0; } #endif /* CONFIG_PM */ static void rtsx_shutdown(struct pci_dev *pci) { struct rtsx_dev *dev = pci_get_drvdata(pci); struct rtsx_chip *chip; if (!dev) return; chip = dev->chip; rtsx_do_before_power_down(chip, PM_S1); if (dev->irq >= 0) { free_irq(dev->irq, (void *)dev); dev->irq = -1; } if (chip->msi_en) pci_disable_msi(pci); pci_disable_device(pci); } static int rtsx_control_thread(void *__dev) { struct rtsx_dev *dev = __dev; struct rtsx_chip *chip = dev->chip; struct Scsi_Host *host = rtsx_to_host(dev); for (;;) { if (wait_for_completion_interruptible(&dev->cmnd_ready)) break; /* lock the device pointers */ mutex_lock(&dev->dev_mutex); /* if the device has disconnected, we are free to exit */ if (rtsx_chk_stat(chip, RTSX_STAT_DISCONNECT)) { dev_info(&dev->pci->dev, "-- rtsx-control exiting\n"); mutex_unlock(&dev->dev_mutex); break; } /* lock access to the state */ scsi_lock(host); /* has the command aborted ? */ if (rtsx_chk_stat(chip, RTSX_STAT_ABORT)) { chip->srb->result = DID_ABORT << 16; goto skip_for_abort; } scsi_unlock(host); /* reject the command if the direction indicator * is UNKNOWN */ if (chip->srb->sc_data_direction == DMA_BIDIRECTIONAL) { dev_err(&dev->pci->dev, "UNKNOWN data direction\n"); chip->srb->result = DID_ERROR << 16; } /* reject if target != 0 or if LUN is higher than * the maximum known LUN */ else if (chip->srb->device->id) { dev_err(&dev->pci->dev, "Bad target number (%d:%d)\n", chip->srb->device->id, (u8)chip->srb->device->lun); chip->srb->result = DID_BAD_TARGET << 16; } else if (chip->srb->device->lun > chip->max_lun) { dev_err(&dev->pci->dev, "Bad LUN (%d:%d)\n", chip->srb->device->id, (u8)chip->srb->device->lun); chip->srb->result = DID_BAD_TARGET << 16; } /* we've got a command, let's do it! */ else { scsi_show_command(chip); rtsx_invoke_transport(chip->srb, chip); } /* lock access to the state */ scsi_lock(host); /* did the command already complete because of a disconnect? */ if (!chip->srb) ; /* nothing to do */ /* indicate that the command is done */ else if (chip->srb->result != DID_ABORT << 16) { chip->srb->scsi_done(chip->srb); } else { skip_for_abort: dev_err(&dev->pci->dev, "scsi command aborted\n"); } if (rtsx_chk_stat(chip, RTSX_STAT_ABORT)) { complete(&dev->notify); rtsx_set_stat(chip, RTSX_STAT_IDLE); } /* finished working on this command */ chip->srb = NULL; scsi_unlock(host); /* unlock the device pointers */ mutex_unlock(&dev->dev_mutex); } /* for (;;) */ /* notify the exit routine that we're actually exiting now * * complete()/wait_for_completion() is similar to up()/down(), * except that complete() is safe in the case where the structure * is getting deleted in a parallel mode of execution (i.e. just * after the down() -- that's necessary for the thread-shutdown * case. * * complete_and_exit() goes even further than this -- it is safe in * the case that the thread of the caller is going away (not just * the structure) -- this is necessary for the module-remove case. * This is important in preemption kernels, which transfer the flow * of execution immediately upon a complete(). */ complete_and_exit(&dev->control_exit, 0); } static int rtsx_polling_thread(void *__dev) { struct rtsx_dev *dev = __dev; struct rtsx_chip *chip = dev->chip; struct sd_info *sd_card = &chip->sd_card; struct xd_info *xd_card = &chip->xd_card; struct ms_info *ms_card = &chip->ms_card; sd_card->cleanup_counter = 0; xd_card->cleanup_counter = 0; ms_card->cleanup_counter = 0; /* Wait until SCSI scan finished */ wait_timeout((delay_use + 5) * 1000); for (;;) { set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(msecs_to_jiffies(POLLING_INTERVAL)); /* lock the device pointers */ mutex_lock(&dev->dev_mutex); /* if the device has disconnected, we are free to exit */ if (rtsx_chk_stat(chip, RTSX_STAT_DISCONNECT)) { dev_info(&dev->pci->dev, "-- rtsx-polling exiting\n"); mutex_unlock(&dev->dev_mutex); break; } mutex_unlock(&dev->dev_mutex); mspro_polling_format_status(chip); /* lock the device pointers */ mutex_lock(&dev->dev_mutex); rtsx_polling_func(chip); /* unlock the device pointers */ mutex_unlock(&dev->dev_mutex); } complete_and_exit(&dev->polling_exit, 0); } /* * interrupt handler */ static irqreturn_t rtsx_interrupt(int irq, void *dev_id) { struct rtsx_dev *dev = dev_id; struct rtsx_chip *chip; int retval; u32 status; if (dev) chip = dev->chip; else return IRQ_NONE; if (!chip) return IRQ_NONE; spin_lock(&dev->reg_lock); retval = rtsx_pre_handle_interrupt(chip); if (retval == STATUS_FAIL) { spin_unlock(&dev->reg_lock); if (chip->int_reg == 0xFFFFFFFF) return IRQ_HANDLED; return IRQ_NONE; } status = chip->int_reg; if (dev->check_card_cd) { if (!(dev->check_card_cd & status)) { /* card not exist, return TRANS_RESULT_FAIL */ dev->trans_result = TRANS_RESULT_FAIL; if (dev->done) complete(dev->done); goto exit; } } if (status & (NEED_COMPLETE_INT | DELINK_INT)) { if (status & (TRANS_FAIL_INT | DELINK_INT)) { if (status & DELINK_INT) RTSX_SET_DELINK(chip); dev->trans_result = TRANS_RESULT_FAIL; if (dev->done) complete(dev->done); } else if (status & TRANS_OK_INT) { dev->trans_result = TRANS_RESULT_OK; if (dev->done) complete(dev->done); } else if (status & DATA_DONE_INT) { dev->trans_result = TRANS_NOT_READY; if (dev->done && (dev->trans_state == STATE_TRANS_SG)) complete(dev->done); } } exit: spin_unlock(&dev->reg_lock); return IRQ_HANDLED; } /* Release all our dynamic resources */ static void rtsx_release_resources(struct rtsx_dev *dev) { dev_info(&dev->pci->dev, "-- %s\n", __func__); /* Tell the control thread to exit. The SCSI host must * already have been removed so it won't try to queue * any more commands. */ dev_info(&dev->pci->dev, "-- sending exit command to thread\n"); complete(&dev->cmnd_ready); if (dev->ctl_thread) wait_for_completion(&dev->control_exit); if (dev->polling_thread) wait_for_completion(&dev->polling_exit); wait_timeout(200); if (dev->rtsx_resv_buf) { dev->chip->host_cmds_ptr = NULL; dev->chip->host_sg_tbl_ptr = NULL; } if (dev->irq > 0) free_irq(dev->irq, (void *)dev); if (dev->chip->msi_en) pci_disable_msi(dev->pci); if (dev->remap_addr) iounmap(dev->remap_addr); rtsx_release_chip(dev->chip); kfree(dev->chip); } /* * First stage of disconnect processing: stop all commands and remove * the host */ static void quiesce_and_remove_host(struct rtsx_dev *dev) { struct Scsi_Host *host = rtsx_to_host(dev); struct rtsx_chip *chip = dev->chip; /* * Prevent new transfers, stop the current command, and * interrupt a SCSI-scan or device-reset delay */ mutex_lock(&dev->dev_mutex); scsi_lock(host); rtsx_set_stat(chip, RTSX_STAT_DISCONNECT); scsi_unlock(host); mutex_unlock(&dev->dev_mutex); wake_up(&dev->delay_wait); wait_for_completion(&dev->scanning_done); /* Wait some time to let other threads exist */ wait_timeout(100); /* * queuecommand won't accept any new commands and the control * thread won't execute a previously-queued command. If there * is such a command pending, complete it with an error. */ mutex_lock(&dev->dev_mutex); if (chip->srb) { chip->srb->result = DID_NO_CONNECT << 16; scsi_lock(host); chip->srb->scsi_done(dev->chip->srb); chip->srb = NULL; scsi_unlock(host); } mutex_unlock(&dev->dev_mutex); /* Now we own no commands so it's safe to remove the SCSI host */ scsi_remove_host(host); } /* Second stage of disconnect processing: deallocate all resources */ static void release_everything(struct rtsx_dev *dev) { rtsx_release_resources(dev); /* * Drop our reference to the host; the SCSI core will free it * when the refcount becomes 0. */ scsi_host_put(rtsx_to_host(dev)); } /* Thread to carry out delayed SCSI-device scanning */ static int rtsx_scan_thread(void *__dev) { struct rtsx_dev *dev = __dev; struct rtsx_chip *chip = dev->chip; /* Wait for the timeout to expire or for a disconnect */ if (delay_use > 0) { dev_info(&dev->pci->dev, "%s: waiting for device to settle before scanning\n", CR_DRIVER_NAME); wait_event_interruptible_timeout (dev->delay_wait, rtsx_chk_stat(chip, RTSX_STAT_DISCONNECT), delay_use * HZ); } /* If the device is still connected, perform the scanning */ if (!rtsx_chk_stat(chip, RTSX_STAT_DISCONNECT)) { scsi_scan_host(rtsx_to_host(dev)); dev_info(&dev->pci->dev, "%s: device scan complete\n", CR_DRIVER_NAME); /* Should we unbind if no devices were detected? */ } complete_and_exit(&dev->scanning_done, 0); } static void rtsx_init_options(struct rtsx_chip *chip) { chip->vendor_id = chip->rtsx->pci->vendor; chip->product_id = chip->rtsx->pci->device; chip->adma_mode = 1; chip->lun_mc = 0; chip->driver_first_load = 1; #ifdef HW_AUTO_SWITCH_SD_BUS chip->sdio_in_charge = 0; #endif chip->mspro_formatter_enable = 1; chip->ignore_sd = 0; chip->use_hw_setting = 0; chip->lun_mode = DEFAULT_SINGLE; chip->auto_delink_en = auto_delink_en; chip->ss_en = ss_en; chip->ss_idle_period = ss_interval * 1000; chip->remote_wakeup_en = 0; chip->aspm_l0s_l1_en = aspm_l0s_l1_en; chip->dynamic_aspm = 1; chip->fpga_sd_sdr104_clk = CLK_200; chip->fpga_sd_ddr50_clk = CLK_100; chip->fpga_sd_sdr50_clk = CLK_100; chip->fpga_sd_hs_clk = CLK_100; chip->fpga_mmc_52m_clk = CLK_80; chip->fpga_ms_hg_clk = CLK_80; chip->fpga_ms_4bit_clk = CLK_80; chip->fpga_ms_1bit_clk = CLK_40; chip->asic_sd_sdr104_clk = 203; chip->asic_sd_sdr50_clk = 98; chip->asic_sd_ddr50_clk = 98; chip->asic_sd_hs_clk = 98; chip->asic_mmc_52m_clk = 98; chip->asic_ms_hg_clk = 117; chip->asic_ms_4bit_clk = 78; chip->asic_ms_1bit_clk = 39; chip->ssc_depth_sd_sdr104 = SSC_DEPTH_2M; chip->ssc_depth_sd_sdr50 = SSC_DEPTH_2M; chip->ssc_depth_sd_ddr50 = SSC_DEPTH_1M; chip->ssc_depth_sd_hs = SSC_DEPTH_1M; chip->ssc_depth_mmc_52m = SSC_DEPTH_1M; chip->ssc_depth_ms_hg = SSC_DEPTH_1M; chip->ssc_depth_ms_4bit = SSC_DEPTH_512K; chip->ssc_depth_low_speed = SSC_DEPTH_512K; chip->ssc_en = 1; chip->sd_speed_prior = 0x01040203; chip->sd_current_prior = 0x00010203; chip->sd_ctl = SD_PUSH_POINT_AUTO | SD_SAMPLE_POINT_AUTO | SUPPORT_MMC_DDR_MODE; chip->sd_ddr_tx_phase = 0; chip->mmc_ddr_tx_phase = 1; chip->sd_default_tx_phase = 15; chip->sd_default_rx_phase = 15; chip->pmos_pwr_on_interval = 200; chip->sd_voltage_switch_delay = 1000; chip->ms_power_class_en = 3; chip->sd_400mA_ocp_thd = 1; chip->sd_800mA_ocp_thd = 5; chip->ms_ocp_thd = 2; chip->card_drive_sel = 0x55; chip->sd30_drive_sel_1v8 = 0x03; chip->sd30_drive_sel_3v3 = 0x01; chip->do_delink_before_power_down = 1; chip->auto_power_down = 1; chip->polling_config = 0; chip->force_clkreq_0 = 1; chip->ft2_fast_mode = 0; chip->sdio_retry_cnt = 1; chip->xd_timeout = 2000; chip->sd_timeout = 10000; chip->ms_timeout = 2000; chip->mspro_timeout = 15000; chip->power_down_in_ss = 1; chip->sdr104_en = 1; chip->sdr50_en = 1; chip->ddr50_en = 1; chip->delink_stage1_step = 100; chip->delink_stage2_step = 40; chip->delink_stage3_step = 20; chip->auto_delink_in_L1 = 1; chip->blink_led = 1; chip->msi_en = msi_en; chip->hp_watch_bios_hotplug = 0; chip->max_payload = 0; chip->phy_voltage = 0; chip->support_ms_8bit = 1; chip->s3_pwr_off_delay = 1000; } static int rtsx_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { struct Scsi_Host *host; struct rtsx_dev *dev; int err = 0; struct task_struct *th; dev_dbg(&pci->dev, "Realtek PCI-E card reader detected\n"); err = pcim_enable_device(pci); if (err < 0) { dev_err(&pci->dev, "PCI enable device failed!\n"); return err; } err = pci_request_regions(pci, CR_DRIVER_NAME); if (err < 0) { dev_err(&pci->dev, "PCI request regions for %s failed!\n", CR_DRIVER_NAME); return err; } /* * Ask the SCSI layer to allocate a host structure, with extra * space at the end for our private rtsx_dev structure. */ host = scsi_host_alloc(&rtsx_host_template, sizeof(*dev)); if (!host) { dev_err(&pci->dev, "Unable to allocate the scsi host\n"); return -ENOMEM; } dev = host_to_rtsx(host); memset(dev, 0, sizeof(struct rtsx_dev)); dev->chip = kzalloc(sizeof(*dev->chip), GFP_KERNEL); if (!dev->chip) { err = -ENOMEM; goto chip_alloc_fail; } spin_lock_init(&dev->reg_lock); mutex_init(&dev->dev_mutex); init_completion(&dev->cmnd_ready); init_completion(&dev->control_exit); init_completion(&dev->polling_exit); init_completion(&dev->notify); init_completion(&dev->scanning_done); init_waitqueue_head(&dev->delay_wait); dev->pci = pci; dev->irq = -1; dev_info(&pci->dev, "Resource length: 0x%x\n", (unsigned int)pci_resource_len(pci, 0)); dev->addr = pci_resource_start(pci, 0); dev->remap_addr = ioremap_nocache(dev->addr, pci_resource_len(pci, 0)); if (!dev->remap_addr) { dev_err(&pci->dev, "ioremap error\n"); err = -ENXIO; goto ioremap_fail; } /* * Using "unsigned long" cast here to eliminate gcc warning in * 64-bit system */ dev_info(&pci->dev, "Original address: 0x%lx, remapped address: 0x%lx\n", (unsigned long)(dev->addr), (unsigned long)(dev->remap_addr)); dev->rtsx_resv_buf = dmam_alloc_coherent(&pci->dev, RTSX_RESV_BUF_LEN, &dev->rtsx_resv_buf_addr, GFP_KERNEL); if (!dev->rtsx_resv_buf) { dev_err(&pci->dev, "alloc dma buffer fail\n"); err = -ENXIO; goto dma_alloc_fail; } dev->chip->host_cmds_ptr = dev->rtsx_resv_buf; dev->chip->host_cmds_addr = dev->rtsx_resv_buf_addr; dev->chip->host_sg_tbl_ptr = dev->rtsx_resv_buf + HOST_CMDS_BUF_LEN; dev->chip->host_sg_tbl_addr = dev->rtsx_resv_buf_addr + HOST_CMDS_BUF_LEN; dev->chip->rtsx = dev; rtsx_init_options(dev->chip); dev_info(&pci->dev, "pci->irq = %d\n", pci->irq); if (dev->chip->msi_en) { if (pci_enable_msi(pci) < 0) dev->chip->msi_en = 0; } if (rtsx_acquire_irq(dev) < 0) { err = -EBUSY; goto irq_acquire_fail; } pci_set_master(pci); synchronize_irq(dev->irq); rtsx_init_chip(dev->chip); /* * set the supported max_lun and max_id for the scsi host * NOTE: the minimal value of max_id is 1 */ host->max_id = 1; host->max_lun = dev->chip->max_lun; /* Start up our control thread */ th = kthread_run(rtsx_control_thread, dev, CR_DRIVER_NAME); if (IS_ERR(th)) { dev_err(&pci->dev, "Unable to start control thread\n"); err = PTR_ERR(th); goto control_thread_fail; } dev->ctl_thread = th; err = scsi_add_host(host, &pci->dev); if (err) { dev_err(&pci->dev, "Unable to add the scsi host\n"); goto scsi_add_host_fail; } /* Start up the thread for delayed SCSI-device scanning */ th = kthread_run(rtsx_scan_thread, dev, "rtsx-scan"); if (IS_ERR(th)) { dev_err(&pci->dev, "Unable to start the device-scanning thread\n"); complete(&dev->scanning_done); err = PTR_ERR(th); goto scan_thread_fail; } /* Start up the thread for polling thread */ th = kthread_run(rtsx_polling_thread, dev, "rtsx-polling"); if (IS_ERR(th)) { dev_err(&pci->dev, "Unable to start the device-polling thread\n"); err = PTR_ERR(th); goto scan_thread_fail; } dev->polling_thread = th; pci_set_drvdata(pci, dev); return 0; /* We come here if there are any problems */ scan_thread_fail: quiesce_and_remove_host(dev); scsi_add_host_fail: complete(&dev->cmnd_ready); wait_for_completion(&dev->control_exit); control_thread_fail: free_irq(dev->irq, (void *)dev); rtsx_release_chip(dev->chip); irq_acquire_fail: dev->chip->host_cmds_ptr = NULL; dev->chip->host_sg_tbl_ptr = NULL; if (dev->chip->msi_en) pci_disable_msi(dev->pci); dma_alloc_fail: iounmap(dev->remap_addr); ioremap_fail: kfree(dev->chip); chip_alloc_fail: dev_err(&pci->dev, "%s failed\n", __func__); return err; } static void rtsx_remove(struct pci_dev *pci) { struct rtsx_dev *dev = pci_get_drvdata(pci); dev_info(&pci->dev, "%s called\n", __func__); quiesce_and_remove_host(dev); release_everything(dev); } /* PCI IDs */ static const struct pci_device_id rtsx_ids[] = { { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x5208), PCI_CLASS_OTHERS << 16, 0xFF0000 }, { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x5288), PCI_CLASS_OTHERS << 16, 0xFF0000 }, { 0, }, }; MODULE_DEVICE_TABLE(pci, rtsx_ids); /* pci_driver definition */ static struct pci_driver rtsx_driver = { .name = CR_DRIVER_NAME, .id_table = rtsx_ids, .probe = rtsx_probe, .remove = rtsx_remove, #ifdef CONFIG_PM .suspend = rtsx_suspend, .resume = rtsx_resume, #endif .shutdown = rtsx_shutdown, }; module_pci_driver(rtsx_driver);
756942.c
// Auto-generated file. Do not edit! // Template: src/qs8-gemm/MRx4c8-sse.c.in // Generator: tools/xngen // // Copyright 2020 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include <assert.h> #include <smmintrin.h> #include <xnnpack/gemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qu8_gemm_minmax_fp32_ukernel_1x4c8__avx_ld64( size_t mr, size_t nc, size_t kc, const uint8_t* restrict a, size_t a_stride, const void* restrict w, uint8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(uint8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8); const uint8_t* a0 = a; uint8_t* c0 = c; do { __m128i vacc0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); __m128i vacc0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m128i vacc0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); __m128i vacc0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); w = (const int32_t*) w + 4; size_t k = 0; const __m128i vb_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.kernel_zero_point); while (k < kc) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepu8_epi16(va0); a0 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_sub_epi16(_mm_cvtepu8_epi16(vb0), vb_zero_point); vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const uint8_t*) w + 8)); const __m128i vxb1 = _mm_sub_epi16(_mm_cvtepu8_epi16(vb1), vb_zero_point); vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const uint8_t*) w + 16)); const __m128i vxb2 = _mm_sub_epi16(_mm_cvtepu8_epi16(vb2), vb_zero_point); vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const uint8_t*) w + 24)); const __m128i vxb3 = _mm_sub_epi16(_mm_cvtepu8_epi16(vb3), vb_zero_point); vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3)); w = (const void*) ((const uint8_t*) w + 32); k += 8 * sizeof(uint8_t); } const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1); const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3); __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); const __m128 vscale = _mm_load_ps(params->fp32_sse2.scale); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc00x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc0x0123), voutput_zero_point); __m128i vout = _mm_packus_epi16(vacc00x0123, vacc00x0123); vout = _mm_max_epu8(vout, _mm_load_si128((const __m128i*) params->fp32_sse2.output_min)); if (nc >= 4) { unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride); a0 = (const uint8_t*) ((uintptr_t) a0 - kc); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c0 = (uint8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
257297.c
/* * SPDX-License-Identifier: Apache-2.0 * * Copyright (c) 2017-2018 Linaro LTD * Copyright (c) 2017-2019 JUUL Labs * Copyright (c) 2020-2021 Arm Limited * * Original license: * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ #include <string.h> #include "mcuboot_config/mcuboot_config.h" #ifdef MCUBOOT_SIGN_RSA #include "bootutil/sign_key.h" #include "bootutil/crypto/sha256.h" #include "bootutil/crypto/common.h" #include "mbedtls/rsa.h" #include "mbedtls/asn1.h" #include "mbedtls/version.h" #include "bootutil_priv.h" #include "bootutil/fault_injection_hardening.h" /* * Constants for this particular constrained implementation of * RSA-PSS. In particular, we support RSA 2048, with a SHA256 hash, * and a 32-byte salt. A signature with different parameters will be * rejected as invalid. */ /* The size, in octets, of the message. */ #define PSS_EMLEN (MCUBOOT_SIGN_RSA_LEN / 8) /* The size of the hash function. For SHA256, this is 32 bytes. */ #define PSS_HLEN 32 /* Size of the salt, should be fixed. */ #define PSS_SLEN 32 /* The length of the mask: emLen - hLen - 1. */ #define PSS_MASK_LEN (PSS_EMLEN - PSS_HLEN - 1) #define PSS_HASH_OFFSET PSS_MASK_LEN /* For the mask itself, how many bytes should be all zeros. */ #define PSS_MASK_ZERO_COUNT (PSS_MASK_LEN - PSS_SLEN - 1) #define PSS_MASK_ONE_POS PSS_MASK_ZERO_COUNT /* Where the salt starts. */ #define PSS_MASK_SALT_POS (PSS_MASK_ONE_POS + 1) static const uint8_t pss_zeros[8] = {0}; /* * Parse the public key used for signing. Simple RSA format. */ static int bootutil_parse_rsakey(mbedtls_rsa_context *ctx, uint8_t **p, uint8_t *end) { int rc; size_t len; if ((rc = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { return -1; } if (*p + len != end) { return -2; } if ((rc = mbedtls_asn1_get_mpi(p, end, &ctx->MBEDTLS_CONTEXT_MEMBER(N))) != 0 || (rc = mbedtls_asn1_get_mpi(p, end, &ctx->MBEDTLS_CONTEXT_MEMBER(E))) != 0) { return -3; } ctx->MBEDTLS_CONTEXT_MEMBER(len) = mbedtls_mpi_size(&ctx->MBEDTLS_CONTEXT_MEMBER(N)); if (*p != end) { return -4; } /* The mbedtls version is more than 2.6.1 */ #if MBEDTLS_VERSION_NUMBER > 0x02060100 rc = mbedtls_rsa_import(ctx, &ctx->MBEDTLS_CONTEXT_MEMBER(N), NULL, NULL, NULL, &ctx->MBEDTLS_CONTEXT_MEMBER(E)); if (rc != 0) { return -5; } #endif rc = mbedtls_rsa_check_pubkey(ctx); if (rc != 0) { return -6; } ctx->MBEDTLS_CONTEXT_MEMBER(len) = mbedtls_mpi_size(&ctx->MBEDTLS_CONTEXT_MEMBER(N)); return 0; } /* * Compute the RSA-PSS mask-generation function, MGF1. Assumptions * are that the mask length will be less than 256 * PSS_HLEN, and * therefore we never need to increment anything other than the low * byte of the counter. * * This is described in PKCS#1, B.2.1. */ static void pss_mgf1(uint8_t *mask, const uint8_t *hash) { bootutil_sha256_context ctx; uint8_t counter[4] = { 0, 0, 0, 0 }; uint8_t htmp[PSS_HLEN]; int count = PSS_MASK_LEN; int bytes; while (count > 0) { bootutil_sha256_init(&ctx); bootutil_sha256_update(&ctx, hash, PSS_HLEN); bootutil_sha256_update(&ctx, counter, 4); bootutil_sha256_finish(&ctx, htmp); counter[3]++; bytes = PSS_HLEN; if (bytes > count) bytes = count; memcpy(mask, htmp, bytes); mask += bytes; count -= bytes; } bootutil_sha256_drop(&ctx); } /* * Validate an RSA signature, using RSA-PSS, as described in PKCS #1 * v2.2, section 9.1.2, with many parameters required to have fixed * values. */ static fih_int bootutil_cmp_rsasig(mbedtls_rsa_context *ctx, uint8_t *hash, uint32_t hlen, uint8_t *sig) { bootutil_sha256_context shactx; uint8_t em[MBEDTLS_MPI_MAX_SIZE]; uint8_t db_mask[PSS_MASK_LEN]; uint8_t h2[PSS_HLEN]; int i; int rc = 0; fih_int fih_rc = FIH_FAILURE; if (ctx->MBEDTLS_CONTEXT_MEMBER(len) != PSS_EMLEN || PSS_EMLEN > MBEDTLS_MPI_MAX_SIZE) { rc = -1; goto out; } if (hlen != PSS_HLEN) { rc = -1; goto out; } if (mbedtls_rsa_public(ctx, sig, em)) { rc = -1; goto out; } /* * PKCS #1 v2.2, 9.1.2 EMSA-PSS-Verify * * emBits is 2048 * emLen = ceil(emBits/8) = 256 * * The salt length is not known at the beginning. */ /* Step 1. The message is constrained by the address space of a * 32-bit processor, which is far less than the 2^61-1 limit of * SHA-256. */ /* Step 2. mHash is passed in as 'hash', with hLen the hlen * argument. */ /* Step 3. if emLen < hLen + sLen + 2, inconsistent and stop. * The salt length is not known at this point. */ /* Step 4. If the rightmost octet of EM does have the value * 0xbc, output inconsistent and stop. */ if (em[PSS_EMLEN - 1] != 0xbc) { rc = -1; goto out; } /* Step 5. Let maskedDB be the leftmost emLen - hLen - 1 octets * of EM, and H be the next hLen octets. * * maskedDB is then the first 256 - 32 - 1 = 0-222 * H is 32 bytes 223-254 */ /* Step 6. If the leftmost 8emLen - emBits bits of the leftmost * octet in maskedDB are not all equal to zero, output * inconsistent and stop. * * 8emLen - emBits is zero, so there is nothing to test here. */ /* Step 7. let dbMask = MGF(H, emLen - hLen - 1). */ pss_mgf1(db_mask, &em[PSS_HASH_OFFSET]); /* Step 8. let DB = maskedDB xor dbMask. * To avoid needing an additional buffer, store the 'db' in the * same buffer as db_mask. From now, to the end of this function, * db_mask refers to the unmasked 'db'. */ for (i = 0; i < PSS_MASK_LEN; i++) { db_mask[i] ^= em[i]; } /* Step 9. Set the leftmost 8emLen - emBits bits of the leftmost * octet in DB to zero. * pycrypto seems to always make the emBits 2047, so we need to * clear the top bit. */ db_mask[0] &= 0x7F; /* Step 10. If the emLen - hLen - sLen - 2 leftmost octets of DB * are not zero or if the octet at position emLen - hLen - sLen - * 1 (the leftmost position is "position 1") does not have * hexadecimal value 0x01, output "inconsistent" and stop. */ for (i = 0; i < PSS_MASK_ZERO_COUNT; i++) { if (db_mask[i] != 0) { rc = -1; goto out; } } if (db_mask[PSS_MASK_ONE_POS] != 1) { rc = -1; goto out; } /* Step 11. Let salt be the last sLen octets of DB */ /* Step 12. Let M' = 0x00 00 00 00 00 00 00 00 || mHash || salt; */ /* Step 13. Let H' = Hash(M') */ bootutil_sha256_init(&shactx); bootutil_sha256_update(&shactx, pss_zeros, 8); bootutil_sha256_update(&shactx, hash, PSS_HLEN); bootutil_sha256_update(&shactx, &db_mask[PSS_MASK_SALT_POS], PSS_SLEN); bootutil_sha256_finish(&shactx, h2); bootutil_sha256_drop(&shactx); /* Step 14. If H = H', output "consistent". Otherwise, output * "inconsistent". */ FIH_CALL(boot_fih_memequal, fih_rc, h2, &em[PSS_HASH_OFFSET], PSS_HLEN); out: if (rc) { fih_rc = fih_int_encode(rc); } FIH_RET(fih_rc); } fih_int bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig, size_t slen, uint8_t key_id) { mbedtls_rsa_context ctx; int rc; fih_int fih_rc = FIH_FAILURE; uint8_t *cp; uint8_t *end; #if MBEDTLS_VERSION_NUMBER >= 0x03000000 mbedtls_rsa_init(&ctx); #else mbedtls_rsa_init(&ctx, 0, 0); #endif cp = (uint8_t *)bootutil_keys[key_id].key; end = cp + *bootutil_keys[key_id].len; rc = bootutil_parse_rsakey(&ctx, &cp, end); if (rc || slen != ctx.MBEDTLS_CONTEXT_MEMBER(len)) { mbedtls_rsa_free(&ctx); goto out; } FIH_CALL(bootutil_cmp_rsasig, fih_rc, &ctx, hash, hlen, sig); out: mbedtls_rsa_free(&ctx); FIH_RET(fih_rc); } #endif /* MCUBOOT_SIGN_RSA */
1005123.c
#include <stdio.h> int main() { int a; int b; int c; scanf("%d %d", &a, &b); c = a + b; printf("a + b = %d \n", c); c = a - b; printf("a - b = %d \n", c); c = a * b; printf("a * b = %d \n", c); c = a / b; printf("a / b = %d \n", c); c = a % b; printf("a %% b = %d \n", c); return 0; }
902019.c
/* ** 2005 February 15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains C code routines that used to generate VDBE code ** that implements the ALTER TABLE command. */ #include "sqliteInt.h" /* ** The code in this file only exists if we are not omitting the ** ALTER TABLE logic from the build. */ #ifndef SQLITE_OMIT_ALTERTABLE /* ** Parameter zName is the name of a table that is about to be altered ** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN). ** If the table is a system table, this function leaves an error message ** in pParse->zErr (system tables may not be altered) and returns non-zero. ** ** Or, if zName is not a system table, zero is returned. */ static int isAlterableTable(Parse *pParse, Table *pTab){ if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) #ifndef SQLITE_OMIT_VIRTUALTABLE || ( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(pParse->db) ) #endif ){ sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName); return 1; } return 0; } /* ** Generate code to verify that the schemas of database zDb and, if ** bTemp is not true, database "temp", can still be parsed. This is ** called at the end of the generation of an ALTER TABLE ... RENAME ... ** statement to ensure that the operation has not rendered any schema ** objects unusable. */ static void renameTestSchema(Parse *pParse, const char *zDb, int bTemp){ sqlite3NestedParse(pParse, "SELECT 1 " "FROM \"%w\"." DFLT_SCHEMA_TABLE " " "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" " AND sql NOT LIKE 'create virtual%%'" " AND sqlite_rename_test(%Q, sql, type, name, %d)=NULL ", zDb, zDb, bTemp ); if( bTemp==0 ){ sqlite3NestedParse(pParse, "SELECT 1 " "FROM temp." DFLT_SCHEMA_TABLE " " "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" " AND sql NOT LIKE 'create virtual%%'" " AND sqlite_rename_test(%Q, sql, type, name, 1)=NULL ", zDb ); } } /* ** Generate code to reload the schema for database iDb. And, if iDb!=1, for ** the temp database as well. */ static void renameReloadSchema(Parse *pParse, int iDb){ Vdbe *v = pParse->pVdbe; if( v ){ sqlite3ChangeCookie(pParse, iDb); sqlite3VdbeAddParseSchemaOp(pParse->pVdbe, iDb, 0); if( iDb!=1 ) sqlite3VdbeAddParseSchemaOp(pParse->pVdbe, 1, 0); } } /* ** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy" ** command. */ void sqlite3AlterRenameTable( Parse *pParse, /* Parser context. */ SrcList *pSrc, /* The table to rename. */ Token *pName /* The new table name. */ ){ int iDb; /* Database that contains the table */ char *zDb; /* Name of database iDb */ Table *pTab; /* Table being renamed */ char *zName = 0; /* NULL-terminated version of pName */ sqlite3 *db = pParse->db; /* Database connection */ int nTabName; /* Number of UTF-8 characters in zTabName */ const char *zTabName; /* Original name of the table */ Vdbe *v; VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */ u32 savedDbFlags; /* Saved value of db->mDbFlags */ savedDbFlags = db->mDbFlags; if( NEVER(db->mallocFailed) ) goto exit_rename_table; assert( pSrc->nSrc==1 ); assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]); if( !pTab ) goto exit_rename_table; iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); zDb = db->aDb[iDb].zDbSName; db->mDbFlags |= DBFLAG_PreferBuiltin; /* Get a NULL terminated version of the new table name. */ zName = sqlite3NameFromToken(db, pName); if( !zName ) goto exit_rename_table; /* Check that a table or index named 'zName' does not already exist ** in database iDb. If so, this is an error. */ if( sqlite3FindTable(db, zName, zDb) || sqlite3FindIndex(db, zName, zDb) || sqlite3IsShadowTableOf(db, pTab, zName) ){ sqlite3ErrorMsg(pParse, "there is already another table or index with this name: %s", zName); goto exit_rename_table; } /* Make sure it is not a system table being altered, or a reserved name ** that the table is being renamed to. */ if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){ goto exit_rename_table; } if( SQLITE_OK!=sqlite3CheckObjectName(pParse,zName,"table",zName) ){ goto exit_rename_table; } #ifndef SQLITE_OMIT_VIEW if( pTab->pSelect ){ sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName); goto exit_rename_table; } #endif #ifndef SQLITE_OMIT_AUTHORIZATION /* Invoke the authorization callback. */ if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){ goto exit_rename_table; } #endif #ifndef SQLITE_OMIT_VIRTUALTABLE if( sqlite3ViewGetColumnNames(pParse, pTab) ){ goto exit_rename_table; } if( IsVirtual(pTab) ){ pVTab = sqlite3GetVTable(db, pTab); if( pVTab->pVtab->pModule->xRename==0 ){ pVTab = 0; } } #endif /* Begin a transaction for database iDb. Then modify the schema cookie ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(), ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the ** nested SQL may raise an exception. */ v = sqlite3GetVdbe(pParse); if( v==0 ){ goto exit_rename_table; } sqlite3MayAbort(pParse); /* figure out how many UTF-8 characters are in zName */ zTabName = pTab->zName; nTabName = sqlite3Utf8CharLen(zTabName, -1); /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in ** the schema to use the new table name. */ sqlite3NestedParse(pParse, "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) " "WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)" "AND name NOT LIKE 'sqliteX_%%' ESCAPE 'X'" , zDb, zDb, zTabName, zName, (iDb==1), zTabName ); /* Update the tbl_name and name columns of the sqlite_schema table ** as required. */ sqlite3NestedParse(pParse, "UPDATE %Q." DFLT_SCHEMA_TABLE " SET " "tbl_name = %Q, " "name = CASE " "WHEN type='table' THEN %Q " "WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' " " AND type='index' THEN " "'sqlite_autoindex_' || %Q || substr(name,%d+18) " "ELSE name END " "WHERE tbl_name=%Q COLLATE nocase AND " "(type='table' OR type='index' OR type='trigger');", zDb, zName, zName, zName, nTabName, zTabName ); #ifndef SQLITE_OMIT_AUTOINCREMENT /* If the sqlite_sequence table exists in this database, then update ** it with the new table name. */ if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){ sqlite3NestedParse(pParse, "UPDATE \"%w\".sqlite_sequence set name = %Q WHERE name = %Q", zDb, zName, pTab->zName); } #endif /* If the table being renamed is not itself part of the temp database, ** edit view and trigger definitions within the temp database ** as required. */ if( iDb!=1 ){ sqlite3NestedParse(pParse, "UPDATE sqlite_temp_schema SET " "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), " "tbl_name = " "CASE WHEN tbl_name=%Q COLLATE nocase AND " " sqlite_rename_test(%Q, sql, type, name, 1) " "THEN %Q ELSE tbl_name END " "WHERE type IN ('view', 'trigger')" , zDb, zTabName, zName, zTabName, zDb, zName); } /* If this is a virtual table, invoke the xRename() function if ** one is defined. The xRename() callback will modify the names ** of any resources used by the v-table implementation (including other ** SQLite tables) that are identified by the name of the virtual table. */ #ifndef SQLITE_OMIT_VIRTUALTABLE if( pVTab ){ int i = ++pParse->nMem; sqlite3VdbeLoadString(v, i, zName); sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB); } #endif renameReloadSchema(pParse, iDb); renameTestSchema(pParse, zDb, iDb==1); exit_rename_table: sqlite3SrcListDelete(db, pSrc); sqlite3DbFree(db, zName); db->mDbFlags = savedDbFlags; } /* ** Write code that will raise an error if the table described by ** zDb and zTab is not empty. */ static void sqlite3ErrorIfNotEmpty( Parse *pParse, /* Parsing context */ const char *zDb, /* Schema holding the table */ const char *zTab, /* Table to check for empty */ const char *zErr /* Error message text */ ){ sqlite3NestedParse(pParse, "SELECT raise(ABORT,%Q) FROM \"%w\".\"%w\"", zErr, zDb, zTab ); } /* ** This function is called after an "ALTER TABLE ... ADD" statement ** has been parsed. Argument pColDef contains the text of the new ** column definition. ** ** The Table structure pParse->pNewTable was extended to include ** the new column during parsing. */ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){ Table *pNew; /* Copy of pParse->pNewTable */ Table *pTab; /* Table being altered */ int iDb; /* Database number */ const char *zDb; /* Database name */ const char *zTab; /* Table name */ char *zCol; /* Null-terminated column definition */ Column *pCol; /* The new column */ Expr *pDflt; /* Default value for the new column */ sqlite3 *db; /* The database connection; */ Vdbe *v; /* The prepared statement under construction */ int r1; /* Temporary registers */ db = pParse->db; if( pParse->nErr || db->mallocFailed ) return; pNew = pParse->pNewTable; assert( pNew ); assert( sqlite3BtreeHoldsAllMutexes(db) ); iDb = sqlite3SchemaToIndex(db, pNew->pSchema); zDb = db->aDb[iDb].zDbSName; zTab = &pNew->zName[16]; /* Skip the "sqlite_altertab_" prefix on the name */ pCol = &pNew->aCol[pNew->nCol-1]; pDflt = pCol->pDflt; pTab = sqlite3FindTable(db, zTab, zDb); assert( pTab ); #ifndef SQLITE_OMIT_AUTHORIZATION /* Invoke the authorization callback. */ if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){ return; } #endif /* Check that the new column is not specified as PRIMARY KEY or UNIQUE. ** If there is a NOT NULL constraint, then the default value for the ** column must not be NULL. */ if( pCol->colFlags & COLFLAG_PRIMKEY ){ sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column"); return; } if( pNew->pIndex ){ sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column"); return; } if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){ /* If the default value for the new column was specified with a ** literal NULL, then set pDflt to 0. This simplifies checking ** for an SQL NULL default below. */ assert( pDflt==0 || pDflt->op==TK_SPAN ); if( pDflt && pDflt->pLeft->op==TK_NULL ){ pDflt = 0; } if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){ sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "Cannot add a REFERENCES column with non-NULL default value"); } if( pCol->notNull && !pDflt ){ sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "Cannot add a NOT NULL column with default value NULL"); } /* Ensure the default expression is something that sqlite3ValueFromExpr() ** can handle (i.e. not CURRENT_TIME etc.) */ if( pDflt ){ sqlite3_value *pVal = 0; int rc; rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_BLOB, &pVal); assert( rc==SQLITE_OK || rc==SQLITE_NOMEM ); if( rc!=SQLITE_OK ){ assert( db->mallocFailed == 1 ); return; } if( !pVal ){ sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "Cannot add a column with non-constant default"); } sqlite3ValueFree(pVal); } }else if( pCol->colFlags & COLFLAG_STORED ){ sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "cannot add a STORED column"); } /* Modify the CREATE TABLE statement. */ zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n); if( zCol ){ char *zEnd = &zCol[pColDef->n-1]; u32 savedDbFlags = db->mDbFlags; while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){ *zEnd-- = '\0'; } db->mDbFlags |= DBFLAG_PreferBuiltin; /* substr() operations on characters, but addColOffset is in bytes. So we ** have to use printf() to translate between these units: */ sqlite3NestedParse(pParse, "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " "sql = printf('%%.%ds, ',sql) || %Q" " || substr(sql,1+length(printf('%%.%ds',sql))) " "WHERE type = 'table' AND name = %Q", zDb, pNew->addColOffset, zCol, pNew->addColOffset, zTab ); sqlite3DbFree(db, zCol); db->mDbFlags = savedDbFlags; } /* Make sure the schema version is at least 3. But do not upgrade ** from less than 3 to 4, as that will corrupt any preexisting DESC ** index. */ v = sqlite3GetVdbe(pParse); if( v ){ r1 = sqlite3GetTempReg(pParse); sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT); sqlite3VdbeUsesBtree(v, iDb); sqlite3VdbeAddOp2(v, OP_AddImm, r1, -2); sqlite3VdbeAddOp2(v, OP_IfPos, r1, sqlite3VdbeCurrentAddr(v)+2); VdbeCoverage(v); sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3); sqlite3ReleaseTempReg(pParse, r1); } /* Reload the table definition */ renameReloadSchema(pParse, iDb); } /* ** This function is called by the parser after the table-name in ** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument ** pSrc is the full-name of the table being altered. ** ** This routine makes a (partial) copy of the Table structure ** for the table being altered and sets Parse.pNewTable to point ** to it. Routines called by the parser as the column definition ** is parsed (i.e. sqlite3AddColumn()) add the new Column data to ** the copy. The copy of the Table structure is deleted by tokenize.c ** after parsing is finished. ** ** Routine sqlite3AlterFinishAddColumn() will be called to complete ** coding the "ALTER TABLE ... ADD" statement. */ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ Table *pNew; Table *pTab; int iDb; int i; int nAlloc; sqlite3 *db = pParse->db; /* Look up the table being altered. */ assert( pParse->pNewTable==0 ); assert( sqlite3BtreeHoldsAllMutexes(db) ); if( db->mallocFailed ) goto exit_begin_add_column; pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]); if( !pTab ) goto exit_begin_add_column; #ifndef SQLITE_OMIT_VIRTUALTABLE if( IsVirtual(pTab) ){ sqlite3ErrorMsg(pParse, "virtual tables may not be altered"); goto exit_begin_add_column; } #endif /* Make sure this is not an attempt to ALTER a view. */ if( pTab->pSelect ){ sqlite3ErrorMsg(pParse, "Cannot add a column to a view"); goto exit_begin_add_column; } if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){ goto exit_begin_add_column; } sqlite3MayAbort(pParse); assert( pTab->addColOffset>0 ); iDb = sqlite3SchemaToIndex(db, pTab->pSchema); /* Put a copy of the Table struct in Parse.pNewTable for the ** sqlite3AddColumn() function and friends to modify. But modify ** the name by adding an "sqlite_altertab_" prefix. By adding this ** prefix, we insure that the name will not collide with an existing ** table because user table are not allowed to have the "sqlite_" ** prefix on their name. */ pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table)); if( !pNew ) goto exit_begin_add_column; pParse->pNewTable = pNew; pNew->nTabRef = 1; pNew->nCol = pTab->nCol; assert( pNew->nCol>0 ); nAlloc = (((pNew->nCol-1)/8)*8)+8; assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 ); pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc); pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName); if( !pNew->aCol || !pNew->zName ){ assert( db->mallocFailed ); goto exit_begin_add_column; } memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol); for(i=0; i<pNew->nCol; i++){ Column *pCol = &pNew->aCol[i]; pCol->zName = sqlite3DbStrDup(db, pCol->zName); pCol->hName = sqlite3StrIHash(pCol->zName); pCol->zColl = 0; pCol->pDflt = 0; } pNew->pSchema = db->aDb[iDb].pSchema; pNew->addColOffset = pTab->addColOffset; pNew->nTabRef = 1; exit_begin_add_column: sqlite3SrcListDelete(db, pSrc); return; } /* ** Parameter pTab is the subject of an ALTER TABLE ... RENAME COLUMN ** command. This function checks if the table is a view or virtual ** table (columns of views or virtual tables may not be renamed). If so, ** it loads an error message into pParse and returns non-zero. ** ** Or, if pTab is not a view or virtual table, zero is returned. */ #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) static int isRealTable(Parse *pParse, Table *pTab){ const char *zType = 0; #ifndef SQLITE_OMIT_VIEW if( pTab->pSelect ){ zType = "view"; } #endif #ifndef SQLITE_OMIT_VIRTUALTABLE if( IsVirtual(pTab) ){ zType = "virtual table"; } #endif if( zType ){ sqlite3ErrorMsg( pParse, "cannot rename columns of %s \"%s\"", zType, pTab->zName ); return 1; } return 0; } #else /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */ # define isRealTable(x,y) (0) #endif /* ** Handles the following parser reduction: ** ** cmd ::= ALTER TABLE pSrc RENAME COLUMN pOld TO pNew */ void sqlite3AlterRenameColumn( Parse *pParse, /* Parsing context */ SrcList *pSrc, /* Table being altered. pSrc->nSrc==1 */ Token *pOld, /* Name of column being changed */ Token *pNew /* New column name */ ){ sqlite3 *db = pParse->db; /* Database connection */ Table *pTab; /* Table being updated */ int iCol; /* Index of column being renamed */ char *zOld = 0; /* Old column name */ char *zNew = 0; /* New column name */ const char *zDb; /* Name of schema containing the table */ int iSchema; /* Index of the schema */ int bQuote; /* True to quote the new name */ /* Locate the table to be altered */ pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]); if( !pTab ) goto exit_rename_column; /* Cannot alter a system table */ if( SQLITE_OK!=isAlterableTable(pParse, pTab) ) goto exit_rename_column; if( SQLITE_OK!=isRealTable(pParse, pTab) ) goto exit_rename_column; /* Which schema holds the table to be altered */ iSchema = sqlite3SchemaToIndex(db, pTab->pSchema); assert( iSchema>=0 ); zDb = db->aDb[iSchema].zDbSName; #ifndef SQLITE_OMIT_AUTHORIZATION /* Invoke the authorization callback. */ if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, 0) ){ goto exit_rename_column; } #endif /* Make sure the old name really is a column name in the table to be ** altered. Set iCol to be the index of the column being renamed */ zOld = sqlite3NameFromToken(db, pOld); if( !zOld ) goto exit_rename_column; for(iCol=0; iCol<pTab->nCol; iCol++){ if( 0==sqlite3StrICmp(pTab->aCol[iCol].zName, zOld) ) break; } if( iCol==pTab->nCol ){ sqlite3ErrorMsg(pParse, "no such column: \"%s\"", zOld); goto exit_rename_column; } /* Do the rename operation using a recursive UPDATE statement that ** uses the sqlite_rename_column() SQL function to compute the new ** CREATE statement text for the sqlite_schema table. */ sqlite3MayAbort(pParse); zNew = sqlite3NameFromToken(db, pNew); if( !zNew ) goto exit_rename_column; assert( pNew->n>0 ); bQuote = sqlite3Isquote(pNew->z[0]); sqlite3NestedParse(pParse, "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) " "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' " " AND (type != 'index' OR tbl_name = %Q)" " AND sql NOT LIKE 'create virtual%%'", zDb, zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1, pTab->zName ); sqlite3NestedParse(pParse, "UPDATE temp." DFLT_SCHEMA_TABLE " SET " "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) " "WHERE type IN ('trigger', 'view')", zDb, pTab->zName, iCol, zNew, bQuote ); /* Drop and reload the database schema. */ renameReloadSchema(pParse, iSchema); renameTestSchema(pParse, zDb, iSchema==1); exit_rename_column: sqlite3SrcListDelete(db, pSrc); sqlite3DbFree(db, zOld); sqlite3DbFree(db, zNew); return; } /* ** Each RenameToken object maps an element of the parse tree into ** the token that generated that element. The parse tree element ** might be one of: ** ** * A pointer to an Expr that represents an ID ** * The name of a table column in Column.zName ** ** A list of RenameToken objects can be constructed during parsing. ** Each new object is created by sqlite3RenameTokenMap(). ** As the parse tree is transformed, the sqlite3RenameTokenRemap() ** routine is used to keep the mapping current. ** ** After the parse finishes, renameTokenFind() routine can be used ** to look up the actual token value that created some element in ** the parse tree. */ struct RenameToken { void *p; /* Parse tree element created by token t */ Token t; /* The token that created parse tree element p */ RenameToken *pNext; /* Next is a list of all RenameToken objects */ }; /* ** The context of an ALTER TABLE RENAME COLUMN operation that gets passed ** down into the Walker. */ typedef struct RenameCtx RenameCtx; struct RenameCtx { RenameToken *pList; /* List of tokens to overwrite */ int nList; /* Number of tokens in pList */ int iCol; /* Index of column being renamed */ Table *pTab; /* Table being ALTERed */ const char *zOld; /* Old column name */ }; #ifdef SQLITE_DEBUG /* ** This function is only for debugging. It performs two tasks: ** ** 1. Checks that pointer pPtr does not already appear in the ** rename-token list. ** ** 2. Dereferences each pointer in the rename-token list. ** ** The second is most effective when debugging under valgrind or ** address-sanitizer or similar. If any of these pointers no longer ** point to valid objects, an exception is raised by the memory-checking ** tool. ** ** The point of this is to prevent comparisons of invalid pointer values. ** Even though this always seems to work, it is undefined according to the ** C standard. Example of undefined comparison: ** ** sqlite3_free(x); ** if( x==y ) ... ** ** Technically, as x no longer points into a valid object or to the byte ** following a valid object, it may not be used in comparison operations. */ static void renameTokenCheckAll(Parse *pParse, void *pPtr){ if( pParse->nErr==0 && pParse->db->mallocFailed==0 ){ RenameToken *p; u8 i = 0; for(p=pParse->pRename; p; p=p->pNext){ if( p->p ){ assert( p->p!=pPtr ); i += *(u8*)(p->p); } } } } #else # define renameTokenCheckAll(x,y) #endif /* ** Remember that the parser tree element pPtr was created using ** the token pToken. ** ** In other words, construct a new RenameToken object and add it ** to the list of RenameToken objects currently being built up ** in pParse->pRename. ** ** The pPtr argument is returned so that this routine can be used ** with tail recursion in tokenExpr() routine, for a small performance ** improvement. */ void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){ RenameToken *pNew; assert( pPtr || pParse->db->mallocFailed ); renameTokenCheckAll(pParse, pPtr); if( ALWAYS(pParse->eParseMode!=PARSE_MODE_UNMAP) ){ pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken)); if( pNew ){ pNew->p = pPtr; pNew->t = *pToken; pNew->pNext = pParse->pRename; pParse->pRename = pNew; } } return pPtr; } /* ** It is assumed that there is already a RenameToken object associated ** with parse tree element pFrom. This function remaps the associated token ** to parse tree element pTo. */ void sqlite3RenameTokenRemap(Parse *pParse, void *pTo, void *pFrom){ RenameToken *p; renameTokenCheckAll(pParse, pTo); for(p=pParse->pRename; p; p=p->pNext){ if( p->p==pFrom ){ p->p = pTo; break; } } } /* ** Walker callback used by sqlite3RenameExprUnmap(). */ static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){ Parse *pParse = pWalker->pParse; sqlite3RenameTokenRemap(pParse, 0, (void*)pExpr); return WRC_Continue; } /* ** Iterate through the Select objects that are part of WITH clauses attached ** to select statement pSelect. */ static void renameWalkWith(Walker *pWalker, Select *pSelect){ With *pWith = pSelect->pWith; if( pWith ){ int i; for(i=0; i<pWith->nCte; i++){ Select *p = pWith->a[i].pSelect; NameContext sNC; memset(&sNC, 0, sizeof(sNC)); sNC.pParse = pWalker->pParse; sqlite3SelectPrep(sNC.pParse, p, &sNC); sqlite3WalkSelect(pWalker, p); sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols); } } } /* ** Unmap all tokens in the IdList object passed as the second argument. */ static void unmapColumnIdlistNames( Parse *pParse, IdList *pIdList ){ if( pIdList ){ int ii; for(ii=0; ii<pIdList->nId; ii++){ sqlite3RenameTokenRemap(pParse, 0, (void*)pIdList->a[ii].zName); } } } /* ** Walker callback used by sqlite3RenameExprUnmap(). */ static int renameUnmapSelectCb(Walker *pWalker, Select *p){ Parse *pParse = pWalker->pParse; int i; if( pParse->nErr ) return WRC_Abort; if( NEVER(p->selFlags & SF_View) ) return WRC_Prune; if( ALWAYS(p->pEList) ){ ExprList *pList = p->pEList; for(i=0; i<pList->nExpr; i++){ if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){ sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName); } } } if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */ SrcList *pSrc = p->pSrc; for(i=0; i<pSrc->nSrc; i++){ sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName); if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort; unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing); } } renameWalkWith(pWalker, p); return WRC_Continue; } /* ** Remove all nodes that are part of expression pExpr from the rename list. */ void sqlite3RenameExprUnmap(Parse *pParse, Expr *pExpr){ u8 eMode = pParse->eParseMode; Walker sWalker; memset(&sWalker, 0, sizeof(Walker)); sWalker.pParse = pParse; sWalker.xExprCallback = renameUnmapExprCb; sWalker.xSelectCallback = renameUnmapSelectCb; pParse->eParseMode = PARSE_MODE_UNMAP; sqlite3WalkExpr(&sWalker, pExpr); pParse->eParseMode = eMode; } /* ** Remove all nodes that are part of expression-list pEList from the ** rename list. */ void sqlite3RenameExprlistUnmap(Parse *pParse, ExprList *pEList){ if( pEList ){ int i; Walker sWalker; memset(&sWalker, 0, sizeof(Walker)); sWalker.pParse = pParse; sWalker.xExprCallback = renameUnmapExprCb; sqlite3WalkExprList(&sWalker, pEList); for(i=0; i<pEList->nExpr; i++){ if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){ sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName); } } } } /* ** Free the list of RenameToken objects given in the second argument */ static void renameTokenFree(sqlite3 *db, RenameToken *pToken){ RenameToken *pNext; RenameToken *p; for(p=pToken; p; p=pNext){ pNext = p->pNext; sqlite3DbFree(db, p); } } /* ** Search the Parse object passed as the first argument for a RenameToken ** object associated with parse tree element pPtr. If found, remove it ** from the Parse object and add it to the list maintained by the ** RenameCtx object passed as the second argument. */ static void renameTokenFind(Parse *pParse, struct RenameCtx *pCtx, void *pPtr){ RenameToken **pp; assert( pPtr!=0 ); for(pp=&pParse->pRename; (*pp); pp=&(*pp)->pNext){ if( (*pp)->p==pPtr ){ RenameToken *pToken = *pp; *pp = pToken->pNext; pToken->pNext = pCtx->pList; pCtx->pList = pToken; pCtx->nList++; break; } } } /* ** This is a Walker select callback. It does nothing. It is only required ** because without a dummy callback, sqlite3WalkExpr() and similar do not ** descend into sub-select statements. */ static int renameColumnSelectCb(Walker *pWalker, Select *p){ if( p->selFlags & SF_View ) return WRC_Prune; renameWalkWith(pWalker, p); return WRC_Continue; } /* ** This is a Walker expression callback. ** ** For every TK_COLUMN node in the expression tree, search to see ** if the column being references is the column being renamed by an ** ALTER TABLE statement. If it is, then attach its associated ** RenameToken object to the list of RenameToken objects being ** constructed in RenameCtx object at pWalker->u.pRename. */ static int renameColumnExprCb(Walker *pWalker, Expr *pExpr){ RenameCtx *p = pWalker->u.pRename; if( pExpr->op==TK_TRIGGER && pExpr->iColumn==p->iCol && pWalker->pParse->pTriggerTab==p->pTab ){ renameTokenFind(pWalker->pParse, p, (void*)pExpr); }else if( pExpr->op==TK_COLUMN && pExpr->iColumn==p->iCol && p->pTab==pExpr->y.pTab ){ renameTokenFind(pWalker->pParse, p, (void*)pExpr); } return WRC_Continue; } /* ** The RenameCtx contains a list of tokens that reference a column that ** is being renamed by an ALTER TABLE statement. Return the "last" ** RenameToken in the RenameCtx and remove that RenameToken from the ** RenameContext. "Last" means the last RenameToken encountered when ** the input SQL is parsed from left to right. Repeated calls to this routine ** return all column name tokens in the order that they are encountered ** in the SQL statement. */ static RenameToken *renameColumnTokenNext(RenameCtx *pCtx){ RenameToken *pBest = pCtx->pList; RenameToken *pToken; RenameToken **pp; for(pToken=pBest->pNext; pToken; pToken=pToken->pNext){ if( pToken->t.z>pBest->t.z ) pBest = pToken; } for(pp=&pCtx->pList; *pp!=pBest; pp=&(*pp)->pNext); *pp = pBest->pNext; return pBest; } /* ** An error occured while parsing or otherwise processing a database ** object (either pParse->pNewTable, pNewIndex or pNewTrigger) as part of an ** ALTER TABLE RENAME COLUMN program. The error message emitted by the ** sub-routine is currently stored in pParse->zErrMsg. This function ** adds context to the error message and then stores it in pCtx. */ static void renameColumnParseError( sqlite3_context *pCtx, int bPost, sqlite3_value *pType, sqlite3_value *pObject, Parse *pParse ){ const char *zT = (const char*)sqlite3_value_text(pType); const char *zN = (const char*)sqlite3_value_text(pObject); char *zErr; zErr = sqlite3_mprintf("error in %s %s%s: %s", zT, zN, (bPost ? " after rename" : ""), pParse->zErrMsg ); sqlite3_result_error(pCtx, zErr, -1); sqlite3_free(zErr); } /* ** For each name in the the expression-list pEList (i.e. each ** pEList->a[i].zName) that matches the string in zOld, extract the ** corresponding rename-token from Parse object pParse and add it ** to the RenameCtx pCtx. */ static void renameColumnElistNames( Parse *pParse, RenameCtx *pCtx, ExprList *pEList, const char *zOld ){ if( pEList ){ int i; for(i=0; i<pEList->nExpr; i++){ char *zName = pEList->a[i].zEName; if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) && ALWAYS(zName!=0) && 0==sqlite3_stricmp(zName, zOld) ){ renameTokenFind(pParse, pCtx, (void*)zName); } } } } /* ** For each name in the the id-list pIdList (i.e. each pIdList->a[i].zName) ** that matches the string in zOld, extract the corresponding rename-token ** from Parse object pParse and add it to the RenameCtx pCtx. */ static void renameColumnIdlistNames( Parse *pParse, RenameCtx *pCtx, IdList *pIdList, const char *zOld ){ if( pIdList ){ int i; for(i=0; i<pIdList->nId; i++){ char *zName = pIdList->a[i].zName; if( 0==sqlite3_stricmp(zName, zOld) ){ renameTokenFind(pParse, pCtx, (void*)zName); } } } } /* ** Parse the SQL statement zSql using Parse object (*p). The Parse object ** is initialized by this function before it is used. */ static int renameParseSql( Parse *p, /* Memory to use for Parse object */ const char *zDb, /* Name of schema SQL belongs to */ sqlite3 *db, /* Database handle */ const char *zSql, /* SQL to parse */ int bTemp /* True if SQL is from temp schema */ ){ int rc; char *zErr = 0; db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb); /* Parse the SQL statement passed as the first argument. If no error ** occurs and the parse does not result in a new table, index or ** trigger object, the database must be corrupt. */ memset(p, 0, sizeof(Parse)); p->eParseMode = PARSE_MODE_RENAME; p->db = db; p->nQueryLoop = 1; rc = sqlite3RunParser(p, zSql, &zErr); assert( p->zErrMsg==0 ); assert( rc!=SQLITE_OK || zErr==0 ); p->zErrMsg = zErr; if( db->mallocFailed ) rc = SQLITE_NOMEM; if( rc==SQLITE_OK && p->pNewTable==0 && p->pNewIndex==0 && p->pNewTrigger==0 ){ rc = SQLITE_CORRUPT_BKPT; } #ifdef SQLITE_DEBUG /* Ensure that all mappings in the Parse.pRename list really do map to ** a part of the input string. */ if( rc==SQLITE_OK ){ int nSql = sqlite3Strlen30(zSql); RenameToken *pToken; for(pToken=p->pRename; pToken; pToken=pToken->pNext){ assert( pToken->t.z>=zSql && &pToken->t.z[pToken->t.n]<=&zSql[nSql] ); } } #endif db->init.iDb = 0; return rc; } /* ** This function edits SQL statement zSql, replacing each token identified ** by the linked list pRename with the text of zNew. If argument bQuote is ** true, then zNew is always quoted first. If no error occurs, the result ** is loaded into context object pCtx as the result. ** ** Or, if an error occurs (i.e. an OOM condition), an error is left in ** pCtx and an SQLite error code returned. */ static int renameEditSql( sqlite3_context *pCtx, /* Return result here */ RenameCtx *pRename, /* Rename context */ const char *zSql, /* SQL statement to edit */ const char *zNew, /* New token text */ int bQuote /* True to always quote token */ ){ int nNew = sqlite3Strlen30(zNew); int nSql = sqlite3Strlen30(zSql); sqlite3 *db = sqlite3_context_db_handle(pCtx); int rc = SQLITE_OK; char *zQuot; char *zOut; int nQuot; /* Set zQuot to point to a buffer containing a quoted copy of the ** identifier zNew. If the corresponding identifier in the original ** ALTER TABLE statement was quoted (bQuote==1), then set zNew to ** point to zQuot so that all substitutions are made using the ** quoted version of the new column name. */ zQuot = sqlite3MPrintf(db, "\"%w\"", zNew); if( zQuot==0 ){ return SQLITE_NOMEM; }else{ nQuot = sqlite3Strlen30(zQuot); } if( bQuote ){ zNew = zQuot; nNew = nQuot; } /* At this point pRename->pList contains a list of RenameToken objects ** corresponding to all tokens in the input SQL that must be replaced ** with the new column name. All that remains is to construct and ** return the edited SQL string. */ assert( nQuot>=nNew ); zOut = sqlite3DbMallocZero(db, nSql + pRename->nList*nQuot + 1); if( zOut ){ int nOut = nSql; memcpy(zOut, zSql, nSql); while( pRename->pList ){ int iOff; /* Offset of token to replace in zOut */ RenameToken *pBest = renameColumnTokenNext(pRename); u32 nReplace; const char *zReplace; if( sqlite3IsIdChar(*pBest->t.z) ){ nReplace = nNew; zReplace = zNew; }else{ nReplace = nQuot; zReplace = zQuot; } iOff = pBest->t.z - zSql; if( pBest->t.n!=nReplace ){ memmove(&zOut[iOff + nReplace], &zOut[iOff + pBest->t.n], nOut - (iOff + pBest->t.n) ); nOut += nReplace - pBest->t.n; zOut[nOut] = '\0'; } memcpy(&zOut[iOff], zReplace, nReplace); sqlite3DbFree(db, pBest); } sqlite3_result_text(pCtx, zOut, -1, SQLITE_TRANSIENT); sqlite3DbFree(db, zOut); }else{ rc = SQLITE_NOMEM; } sqlite3_free(zQuot); return rc; } /* ** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming ** it was read from the schema of database zDb. Return SQLITE_OK if ** successful. Otherwise, return an SQLite error code and leave an error ** message in the Parse object. */ static int renameResolveTrigger(Parse *pParse){ sqlite3 *db = pParse->db; Trigger *pNew = pParse->pNewTrigger; TriggerStep *pStep; NameContext sNC; int rc = SQLITE_OK; memset(&sNC, 0, sizeof(sNC)); sNC.pParse = pParse; assert( pNew->pTabSchema ); pParse->pTriggerTab = sqlite3FindTable(db, pNew->table, db->aDb[sqlite3SchemaToIndex(db, pNew->pTabSchema)].zDbSName ); pParse->eTriggerOp = pNew->op; /* ALWAYS() because if the table of the trigger does not exist, the ** error would have been hit before this point */ if( ALWAYS(pParse->pTriggerTab) ){ rc = sqlite3ViewGetColumnNames(pParse, pParse->pTriggerTab); } /* Resolve symbols in WHEN clause */ if( rc==SQLITE_OK && pNew->pWhen ){ rc = sqlite3ResolveExprNames(&sNC, pNew->pWhen); } for(pStep=pNew->step_list; rc==SQLITE_OK && pStep; pStep=pStep->pNext){ if( pStep->pSelect ){ sqlite3SelectPrep(pParse, pStep->pSelect, &sNC); if( pParse->nErr ) rc = pParse->rc; } if( rc==SQLITE_OK && pStep->zTarget ){ SrcList *pSrc = sqlite3TriggerStepSrc(pParse, pStep); if( pSrc ){ int i; for(i=0; i<pSrc->nSrc && rc==SQLITE_OK; i++){ struct SrcList_item *p = &pSrc->a[i]; p->iCursor = pParse->nTab++; if( p->pSelect ){ sqlite3SelectPrep(pParse, p->pSelect, 0); sqlite3ExpandSubquery(pParse, p); assert( i>0 ); assert( pStep->pFrom->a[i-1].pSelect ); sqlite3SelectPrep(pParse, pStep->pFrom->a[i-1].pSelect, 0); }else{ p->pTab = sqlite3LocateTableItem(pParse, 0, p); if( p->pTab==0 ){ rc = SQLITE_ERROR; }else{ p->pTab->nTabRef++; rc = sqlite3ViewGetColumnNames(pParse, p->pTab); } } } sNC.pSrcList = pSrc; if( rc==SQLITE_OK && pStep->pWhere ){ rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere); } if( rc==SQLITE_OK ){ rc = sqlite3ResolveExprListNames(&sNC, pStep->pExprList); } assert( !pStep->pUpsert || (!pStep->pWhere && !pStep->pExprList) ); if( pStep->pUpsert ){ Upsert *pUpsert = pStep->pUpsert; assert( rc==SQLITE_OK ); pUpsert->pUpsertSrc = pSrc; sNC.uNC.pUpsert = pUpsert; sNC.ncFlags = NC_UUpsert; rc = sqlite3ResolveExprListNames(&sNC, pUpsert->pUpsertTarget); if( rc==SQLITE_OK ){ ExprList *pUpsertSet = pUpsert->pUpsertSet; rc = sqlite3ResolveExprListNames(&sNC, pUpsertSet); } if( rc==SQLITE_OK ){ rc = sqlite3ResolveExprNames(&sNC, pUpsert->pUpsertWhere); } if( rc==SQLITE_OK ){ rc = sqlite3ResolveExprNames(&sNC, pUpsert->pUpsertTargetWhere); } sNC.ncFlags = 0; } sNC.pSrcList = 0; sqlite3SrcListDelete(db, pSrc); }else{ rc = SQLITE_NOMEM; } } } return rc; } /* ** Invoke sqlite3WalkExpr() or sqlite3WalkSelect() on all Select or Expr ** objects that are part of the trigger passed as the second argument. */ static void renameWalkTrigger(Walker *pWalker, Trigger *pTrigger){ TriggerStep *pStep; /* Find tokens to edit in WHEN clause */ sqlite3WalkExpr(pWalker, pTrigger->pWhen); /* Find tokens to edit in trigger steps */ for(pStep=pTrigger->step_list; pStep; pStep=pStep->pNext){ sqlite3WalkSelect(pWalker, pStep->pSelect); sqlite3WalkExpr(pWalker, pStep->pWhere); sqlite3WalkExprList(pWalker, pStep->pExprList); if( pStep->pUpsert ){ Upsert *pUpsert = pStep->pUpsert; sqlite3WalkExprList(pWalker, pUpsert->pUpsertTarget); sqlite3WalkExprList(pWalker, pUpsert->pUpsertSet); sqlite3WalkExpr(pWalker, pUpsert->pUpsertWhere); sqlite3WalkExpr(pWalker, pUpsert->pUpsertTargetWhere); } if( pStep->pFrom ){ int i; for(i=0; i<pStep->pFrom->nSrc; i++){ sqlite3WalkSelect(pWalker, pStep->pFrom->a[i].pSelect); } } } } /* ** Free the contents of Parse object (*pParse). Do not free the memory ** occupied by the Parse object itself. */ static void renameParseCleanup(Parse *pParse){ sqlite3 *db = pParse->db; Index *pIdx; if( pParse->pVdbe ){ sqlite3VdbeFinalize(pParse->pVdbe); } sqlite3DeleteTable(db, pParse->pNewTable); while( (pIdx = pParse->pNewIndex)!=0 ){ pParse->pNewIndex = pIdx->pNext; sqlite3FreeIndex(db, pIdx); } sqlite3DeleteTrigger(db, pParse->pNewTrigger); sqlite3DbFree(db, pParse->zErrMsg); renameTokenFree(db, pParse->pRename); sqlite3ParserReset(pParse); } /* ** SQL function: ** ** sqlite_rename_column(zSql, iCol, bQuote, zNew, zTable, zOld) ** ** 0. zSql: SQL statement to rewrite ** 1. type: Type of object ("table", "view" etc.) ** 2. object: Name of object ** 3. Database: Database name (e.g. "main") ** 4. Table: Table name ** 5. iCol: Index of column to rename ** 6. zNew: New column name ** 7. bQuote: Non-zero if the new column name should be quoted. ** 8. bTemp: True if zSql comes from temp schema ** ** Do a column rename operation on the CREATE statement given in zSql. ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol ** into zNew. The name should be quoted if bQuote is true. ** ** This function is used internally by the ALTER TABLE RENAME COLUMN command. ** It is only accessible to SQL created using sqlite3NestedParse(). It is ** not reachable from ordinary SQL passed into sqlite3_prepare(). */ static void renameColumnFunc( sqlite3_context *context, int NotUsed, sqlite3_value **argv ){ sqlite3 *db = sqlite3_context_db_handle(context); RenameCtx sCtx; const char *zSql = (const char*)sqlite3_value_text(argv[0]); const char *zDb = (const char*)sqlite3_value_text(argv[3]); const char *zTable = (const char*)sqlite3_value_text(argv[4]); int iCol = sqlite3_value_int(argv[5]); const char *zNew = (const char*)sqlite3_value_text(argv[6]); int bQuote = sqlite3_value_int(argv[7]); int bTemp = sqlite3_value_int(argv[8]); const char *zOld; int rc; Parse sParse; Walker sWalker; Index *pIdx; int i; Table *pTab; #ifndef SQLITE_OMIT_AUTHORIZATION sqlite3_xauth xAuth = db->xAuth; #endif UNUSED_PARAMETER(NotUsed); if( zSql==0 ) return; if( zTable==0 ) return; if( zNew==0 ) return; if( iCol<0 ) return; sqlite3BtreeEnterAll(db); pTab = sqlite3FindTable(db, zTable, zDb); if( pTab==0 || iCol>=pTab->nCol ){ sqlite3BtreeLeaveAll(db); return; } zOld = pTab->aCol[iCol].zName; memset(&sCtx, 0, sizeof(sCtx)); sCtx.iCol = ((iCol==pTab->iPKey) ? -1 : iCol); #ifndef SQLITE_OMIT_AUTHORIZATION db->xAuth = 0; #endif rc = renameParseSql(&sParse, zDb, db, zSql, bTemp); /* Find tokens that need to be replaced. */ memset(&sWalker, 0, sizeof(Walker)); sWalker.pParse = &sParse; sWalker.xExprCallback = renameColumnExprCb; sWalker.xSelectCallback = renameColumnSelectCb; sWalker.u.pRename = &sCtx; sCtx.pTab = pTab; if( rc!=SQLITE_OK ) goto renameColumnFunc_done; if( sParse.pNewTable ){ Select *pSelect = sParse.pNewTable->pSelect; if( pSelect ){ pSelect->selFlags &= ~SF_View; sParse.rc = SQLITE_OK; sqlite3SelectPrep(&sParse, pSelect, 0); rc = (db->mallocFailed ? SQLITE_NOMEM : sParse.rc); if( rc==SQLITE_OK ){ sqlite3WalkSelect(&sWalker, pSelect); } if( rc!=SQLITE_OK ) goto renameColumnFunc_done; }else{ /* A regular table */ int bFKOnly = sqlite3_stricmp(zTable, sParse.pNewTable->zName); FKey *pFKey; assert( sParse.pNewTable->pSelect==0 ); sCtx.pTab = sParse.pNewTable; if( bFKOnly==0 ){ renameTokenFind( &sParse, &sCtx, (void*)sParse.pNewTable->aCol[iCol].zName ); if( sCtx.iCol<0 ){ renameTokenFind(&sParse, &sCtx, (void*)&sParse.pNewTable->iPKey); } sqlite3WalkExprList(&sWalker, sParse.pNewTable->pCheck); for(pIdx=sParse.pNewTable->pIndex; pIdx; pIdx=pIdx->pNext){ sqlite3WalkExprList(&sWalker, pIdx->aColExpr); } for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){ sqlite3WalkExprList(&sWalker, pIdx->aColExpr); } } #ifndef SQLITE_OMIT_GENERATED_COLUMNS for(i=0; i<sParse.pNewTable->nCol; i++){ sqlite3WalkExpr(&sWalker, sParse.pNewTable->aCol[i].pDflt); } #endif for(pFKey=sParse.pNewTable->pFKey; pFKey; pFKey=pFKey->pNextFrom){ for(i=0; i<pFKey->nCol; i++){ if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){ renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]); } if( 0==sqlite3_stricmp(pFKey->zTo, zTable) && 0==sqlite3_stricmp(pFKey->aCol[i].zCol, zOld) ){ renameTokenFind(&sParse, &sCtx, (void*)pFKey->aCol[i].zCol); } } } } }else if( sParse.pNewIndex ){ sqlite3WalkExprList(&sWalker, sParse.pNewIndex->aColExpr); sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere); }else{ /* A trigger */ TriggerStep *pStep; rc = renameResolveTrigger(&sParse); if( rc!=SQLITE_OK ) goto renameColumnFunc_done; for(pStep=sParse.pNewTrigger->step_list; pStep; pStep=pStep->pNext){ if( pStep->zTarget ){ Table *pTarget = sqlite3LocateTable(&sParse, 0, pStep->zTarget, zDb); if( pTarget==pTab ){ if( pStep->pUpsert ){ ExprList *pUpsertSet = pStep->pUpsert->pUpsertSet; renameColumnElistNames(&sParse, &sCtx, pUpsertSet, zOld); } renameColumnIdlistNames(&sParse, &sCtx, pStep->pIdList, zOld); renameColumnElistNames(&sParse, &sCtx, pStep->pExprList, zOld); } } } /* Find tokens to edit in UPDATE OF clause */ if( sParse.pTriggerTab==pTab ){ renameColumnIdlistNames(&sParse, &sCtx,sParse.pNewTrigger->pColumns,zOld); } /* Find tokens to edit in various expressions and selects */ renameWalkTrigger(&sWalker, sParse.pNewTrigger); } assert( rc==SQLITE_OK ); rc = renameEditSql(context, &sCtx, zSql, zNew, bQuote); renameColumnFunc_done: if( rc!=SQLITE_OK ){ if( sParse.zErrMsg ){ renameColumnParseError(context, 0, argv[1], argv[2], &sParse); }else{ sqlite3_result_error_code(context, rc); } } renameParseCleanup(&sParse); renameTokenFree(db, sCtx.pList); #ifndef SQLITE_OMIT_AUTHORIZATION db->xAuth = xAuth; #endif sqlite3BtreeLeaveAll(db); } /* ** Walker expression callback used by "RENAME TABLE". */ static int renameTableExprCb(Walker *pWalker, Expr *pExpr){ RenameCtx *p = pWalker->u.pRename; if( pExpr->op==TK_COLUMN && p->pTab==pExpr->y.pTab ){ renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab); } return WRC_Continue; } /* ** Walker select callback used by "RENAME TABLE". */ static int renameTableSelectCb(Walker *pWalker, Select *pSelect){ int i; RenameCtx *p = pWalker->u.pRename; SrcList *pSrc = pSelect->pSrc; if( pSelect->selFlags & SF_View ) return WRC_Prune; if( pSrc==0 ){ assert( pWalker->pParse->db->mallocFailed ); return WRC_Abort; } for(i=0; i<pSrc->nSrc; i++){ struct SrcList_item *pItem = &pSrc->a[i]; if( pItem->pTab==p->pTab ){ renameTokenFind(pWalker->pParse, p, pItem->zName); } } renameWalkWith(pWalker, pSelect); return WRC_Continue; } /* ** This C function implements an SQL user function that is used by SQL code ** generated by the ALTER TABLE ... RENAME command to modify the definition ** of any foreign key constraints that use the table being renamed as the ** parent table. It is passed three arguments: ** ** 0: The database containing the table being renamed. ** 1. type: Type of object ("table", "view" etc.) ** 2. object: Name of object ** 3: The complete text of the schema statement being modified, ** 4: The old name of the table being renamed, and ** 5: The new name of the table being renamed. ** 6: True if the schema statement comes from the temp db. ** ** It returns the new schema statement. For example: ** ** sqlite_rename_table('main', 'CREATE TABLE t1(a REFERENCES t2)','t2','t3',0) ** -> 'CREATE TABLE t1(a REFERENCES t3)' */ static void renameTableFunc( sqlite3_context *context, int NotUsed, sqlite3_value **argv ){ sqlite3 *db = sqlite3_context_db_handle(context); const char *zDb = (const char*)sqlite3_value_text(argv[0]); const char *zInput = (const char*)sqlite3_value_text(argv[3]); const char *zOld = (const char*)sqlite3_value_text(argv[4]); const char *zNew = (const char*)sqlite3_value_text(argv[5]); int bTemp = sqlite3_value_int(argv[6]); UNUSED_PARAMETER(NotUsed); if( zInput && zOld && zNew ){ Parse sParse; int rc; int bQuote = 1; RenameCtx sCtx; Walker sWalker; #ifndef SQLITE_OMIT_AUTHORIZATION sqlite3_xauth xAuth = db->xAuth; db->xAuth = 0; #endif sqlite3BtreeEnterAll(db); memset(&sCtx, 0, sizeof(RenameCtx)); sCtx.pTab = sqlite3FindTable(db, zOld, zDb); memset(&sWalker, 0, sizeof(Walker)); sWalker.pParse = &sParse; sWalker.xExprCallback = renameTableExprCb; sWalker.xSelectCallback = renameTableSelectCb; sWalker.u.pRename = &sCtx; rc = renameParseSql(&sParse, zDb, db, zInput, bTemp); if( rc==SQLITE_OK ){ int isLegacy = (db->flags & SQLITE_LegacyAlter); if( sParse.pNewTable ){ Table *pTab = sParse.pNewTable; if( pTab->pSelect ){ if( isLegacy==0 ){ Select *pSelect = pTab->pSelect; NameContext sNC; memset(&sNC, 0, sizeof(sNC)); sNC.pParse = &sParse; assert( pSelect->selFlags & SF_View ); pSelect->selFlags &= ~SF_View; sqlite3SelectPrep(&sParse, pTab->pSelect, &sNC); if( sParse.nErr ){ rc = sParse.rc; }else{ sqlite3WalkSelect(&sWalker, pTab->pSelect); } } }else{ /* Modify any FK definitions to point to the new table. */ #ifndef SQLITE_OMIT_FOREIGN_KEY if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){ FKey *pFKey; for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){ if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){ renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo); } } } #endif /* If this is the table being altered, fix any table refs in CHECK ** expressions. Also update the name that appears right after the ** "CREATE [VIRTUAL] TABLE" bit. */ if( sqlite3_stricmp(zOld, pTab->zName)==0 ){ sCtx.pTab = pTab; if( isLegacy==0 ){ sqlite3WalkExprList(&sWalker, pTab->pCheck); } renameTokenFind(&sParse, &sCtx, pTab->zName); } } } else if( sParse.pNewIndex ){ renameTokenFind(&sParse, &sCtx, sParse.pNewIndex->zName); if( isLegacy==0 ){ sqlite3WalkExpr(&sWalker, sParse.pNewIndex->pPartIdxWhere); } } #ifndef SQLITE_OMIT_TRIGGER else{ Trigger *pTrigger = sParse.pNewTrigger; TriggerStep *pStep; if( 0==sqlite3_stricmp(sParse.pNewTrigger->table, zOld) && sCtx.pTab->pSchema==pTrigger->pTabSchema ){ renameTokenFind(&sParse, &sCtx, sParse.pNewTrigger->table); } if( isLegacy==0 ){ rc = renameResolveTrigger(&sParse); if( rc==SQLITE_OK ){ renameWalkTrigger(&sWalker, pTrigger); for(pStep=pTrigger->step_list; pStep; pStep=pStep->pNext){ if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){ renameTokenFind(&sParse, &sCtx, pStep->zTarget); } } } } } #endif } if( rc==SQLITE_OK ){ rc = renameEditSql(context, &sCtx, zInput, zNew, bQuote); } if( rc!=SQLITE_OK ){ if( sParse.zErrMsg ){ renameColumnParseError(context, 0, argv[1], argv[2], &sParse); }else{ sqlite3_result_error_code(context, rc); } } renameParseCleanup(&sParse); renameTokenFree(db, sCtx.pList); sqlite3BtreeLeaveAll(db); #ifndef SQLITE_OMIT_AUTHORIZATION db->xAuth = xAuth; #endif } return; } /* ** An SQL user function that checks that there are no parse or symbol ** resolution problems in a CREATE TRIGGER|TABLE|VIEW|INDEX statement. ** After an ALTER TABLE .. RENAME operation is performed and the schema ** reloaded, this function is called on each SQL statement in the schema ** to ensure that it is still usable. ** ** 0: Database name ("main", "temp" etc.). ** 1: SQL statement. ** 2: Object type ("view", "table", "trigger" or "index"). ** 3: Object name. ** 4: True if object is from temp schema. ** ** Unless it finds an error, this function normally returns NULL. However, it ** returns integer value 1 if: ** ** * the SQL argument creates a trigger, and ** * the table that the trigger is attached to is in database zDb. */ static void renameTableTest( sqlite3_context *context, int NotUsed, sqlite3_value **argv ){ sqlite3 *db = sqlite3_context_db_handle(context); char const *zDb = (const char*)sqlite3_value_text(argv[0]); char const *zInput = (const char*)sqlite3_value_text(argv[1]); int bTemp = sqlite3_value_int(argv[4]); int isLegacy = (db->flags & SQLITE_LegacyAlter); #ifndef SQLITE_OMIT_AUTHORIZATION sqlite3_xauth xAuth = db->xAuth; db->xAuth = 0; #endif UNUSED_PARAMETER(NotUsed); if( zDb && zInput ){ int rc; Parse sParse; rc = renameParseSql(&sParse, zDb, db, zInput, bTemp); if( rc==SQLITE_OK ){ if( isLegacy==0 && sParse.pNewTable && sParse.pNewTable->pSelect ){ NameContext sNC; memset(&sNC, 0, sizeof(sNC)); sNC.pParse = &sParse; sqlite3SelectPrep(&sParse, sParse.pNewTable->pSelect, &sNC); if( sParse.nErr ) rc = sParse.rc; } else if( sParse.pNewTrigger ){ if( isLegacy==0 ){ rc = renameResolveTrigger(&sParse); } if( rc==SQLITE_OK ){ int i1 = sqlite3SchemaToIndex(db, sParse.pNewTrigger->pTabSchema); int i2 = sqlite3FindDbName(db, zDb); if( i1==i2 ) sqlite3_result_int(context, 1); } } } if( rc!=SQLITE_OK ){ renameColumnParseError(context, 1, argv[2], argv[3], &sParse); } renameParseCleanup(&sParse); } #ifndef SQLITE_OMIT_AUTHORIZATION db->xAuth = xAuth; #endif } /* ** Register built-in functions used to help implement ALTER TABLE */ void sqlite3AlterFunctions(void){ static FuncDef aAlterTableFuncs[] = { INTERNAL_FUNCTION(sqlite_rename_column, 9, renameColumnFunc), INTERNAL_FUNCTION(sqlite_rename_table, 7, renameTableFunc), INTERNAL_FUNCTION(sqlite_rename_test, 5, renameTableTest), }; sqlite3InsertBuiltinFuncs(aAlterTableFuncs, ArraySize(aAlterTableFuncs)); } #endif /* SQLITE_ALTER_TABLE */
497461.c
/*************************************************************************/ /* */ /* sampleuse */ /* */ /* Simple examples of library use used in the HowTo.txt document. */ /* */ /* (c) Verisign Inc., 2000-2002, All rights reserved */ /* */ /*************************************************************************/ #include "xcode.h" #include <stdio.h> #include "../utility/utility.h" #ifdef WIN32 #ifdef _DEBUG #pragma comment( lib, "../../../../../lib/win32/xcodelibdbg.lib" ) #else #pragma comment( lib, "../../../../../lib/win32/xcodelib.lib" ) #endif #endif int main(int argc, char* argv[]) { FILE * fpin; char szIn[1024]; char szOut[1024]; UCHAR8 szData[MAX_DOMAIN_SIZE_8]; UTF16CHAR uInput[MAX_DOMAIN_SIZE_16]; int iInputSize = 0; int iOutputSize = 0; int counter = 0; int res; /* Arg check */ if (argc < 1) { printf("usage: [toascii,tounicode] <domains fullcircle file>\n", argv[0] ); return 1; } /* Get file */ fpin = fopen(argv[1], "r"); if (fpin == NULL) { printf("Cannot open %s\n",argv[1]); return 1; } while ( !feof( fpin ) ) { memset( szIn, 0, sizeof(szIn) ); memset( szOut, 0, sizeof(szOut) ); memset( szData, 0, sizeof(szData) ); fgets( szIn, sizeof(szIn), fpin ); counter++; if ( szIn[0] == ' ' || szIn[0] == '#' || strlen( szIn ) < 2 ) continue; fgets( szOut, sizeof(szOut), fpin ); counter++; /* Clip off \n */ szIn[strlen(szIn)-1] = 0; szOut[strlen(szOut)-1] = 0; if ( szIn[0] != 'i' ) { printf("Invalid input file format.\n"); return 1; } if ( szOut[0] != 'o' ) { printf("Invalid input file format.\n"); return 1; } Read16BitLine( &szIn[2], uInput, &iInputSize ); iOutputSize = sizeof(szData); res = Xcode_DomainToASCII( uInput, iInputSize, szData, &iOutputSize ); counter++; if ( res != XCODE_SUCCESS ) { char szMsg[1024]; ConvertErrorCode( res, szMsg ); printf( "Error: line %d Code %s (%s)\n", counter, szMsg, &szIn[2] ); continue; } printf( "%s\n", szData ); } fclose(fpin); #ifdef WIN32 getchar(); #endif return 0; }
271659.c
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Copyright (c) 2011 Synaptics, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ #include "RefCode.h" #include "RefCode_PDTScan.h" #ifdef _F54_TEST_ #ifdef F54_Porting static unsigned char ImageBuffer[CFG_F54_TXCOUNT*CFG_F54_RXCOUNT*2]; static short ImageArray[CFG_F54_RXCOUNT][CFG_F54_RXCOUNT]; static char buf[3000] = {0}; static int ret = 0; #endif unsigned char F54_RxOpenReport(void) { #ifdef F54_Porting #else unsigned char ImageBuffer[CFG_F54_TXCOUNT*CFG_F54_RXCOUNT*2]; short ImageArray[CFG_F54_RXCOUNT][CFG_F54_RXCOUNT]; #endif //char Result[CFG_F54_RXCOUNT][CFG_F54_RXCOUNT]; int Result=0; short OthersLowerLimit = -100; short OthersUpperLimit = 100; int i, j, k; int length; unsigned char command; #ifdef F54_Porting memset(buf, 0, sizeof(buf)); ret = sprintf(buf, "\nBin #: 8 Name: Receiver Open Test\n"); ret += sprintf(buf+ret, "\n\t"); #else printk("\nBin #: 8 Name: Receiver Open Test\n"); printk("\n\t"); #endif for (j = 0; j < numberOfRx; j++) #ifdef F54_Porting ret += sprintf(buf+ret, "R%d\t", j); #else printk("R%d\t", j); #endif #ifdef F54_Porting ret += sprintf(buf+ret, "\n"); #else printk("\n"); #endif length = numberOfRx * numberOfTx*2; // Set report mode command = 0x0E; writeRMI(F54_Data_Base, &command, 1); // Disable CBC command = 0x00; writeRMI(F54_CBCSettings, &command, 1); //NoCDM4 command = 0x01; writeRMI(NoiseMitigation, &command, 1); // Force update command = 0x04; writeRMI(F54_Command_Base, &command, 1); do { delayMS(1); //wait 1ms readRMI(F54_Command_Base, &command, 1); } while (command != 0x00); command = 0x02; writeRMI(F54_Command_Base, &command, 1); do { delayMS(1); //wait 1ms readRMI(F54_Command_Base, &command, 1); } while (command != 0x00); // command = 0x00; // writeRMI(0x0113, &command, 1); command = 0x00; writeRMI(F54_Data_LowIndex, &command, 1); writeRMI(F54_Data_HighIndex, &command, 1); // Set the GetReport bit command = 0x01; writeRMI(F54_Command_Base, &command, 1); // Wait until the command is completed do { delayMS(1); //wait 1ms readRMI(F54_Command_Base, &command, 1); } while (command != 0x00); //readRMI(F54_Data_Buffer, &ImageBuffer[0], length); longReadRMI(F54_Data_Buffer, &ImageBuffer[0], length); k = 0; for (i = 0; i < numberOfTx; i++) { for (j = 0; j < numberOfRx; j++) { ImageArray[i][j] = (ImageBuffer[k] | (ImageBuffer[k+1] << 8)); k = k + 2; } } // Set report mode length = numberOfRx* (numberOfRx-numberOfTx) * 2; command = 0x12; writeRMI(F54_Data_Base, &command, 1); command = 0x00; writeRMI(F54_Data_LowIndex, &command, 1); writeRMI(F54_Data_HighIndex, &command, 1); // Set the GetReport bit to run Tx-to-Tx command = 0x01; writeRMI(F54_Command_Base, &command, 1); // Wait until the command is completed do { delayMS(1); //wait 1ms readRMI(F54_Command_Base, &command, 1); } while (command != 0x00); //readRMI(F54_Data_Buffer, &ImageBuffer[0], length); longReadRMI(F54_Data_Buffer, &ImageBuffer[0], length); k = 0; for (i = 0; i < (numberOfRx-numberOfTx); i++) { for (j = 0; j < numberOfRx; j++) { ImageArray[numberOfTx+i][j] = ImageBuffer[k] | (ImageBuffer[k+1] << 8); k = k + 2; } } /* // Check against test limits printk("\nRxToRx Short Test Result :\n"); for (i = 0; i < numberOfRx; i++) { for (j = 0; j < numberOfRx; j++) { if (i == j) { if((ImageArray[i][j] <= DiagonalUpperLimit) && (ImageArray[i][j] >= DiagonalUpperLimit)) Result[i][j] = 'P'; //Pass else Result[i][j] = 'F'; //Fail //printk("%3d", ImageArray[i][j]); } else { if(ImageArray[i][j] <= OthersUpperLimit) Result[i][j] = 'P'; //Fail else Result[i][j] = 'F'; //Fail } printk("%4d", ImageArray[i][j]); } printk("\n"); } printk("\n"); */ for (i = 0; i < numberOfRx; i++) { #ifdef F54_Porting ret += sprintf(buf+ret, "R%d\t", i); #else printk("R%d\t", i); #endif for (j = 0; j < numberOfRx; j++) { if((ImageArray[i][j] <= OthersUpperLimit) && (ImageArray[i][j] >= OthersLowerLimit)) { Result++; //Pass #ifdef F54_Porting ret += sprintf(buf+ret, "%d\t", ImageArray[i][j]); #else printk("%d\t", ImageArray[i][j]); #endif } else { #ifdef F54_Porting ret += sprintf(buf+ret, "%d(*)\t", ImageArray[i][j]); #else printk("%d(*)\t", ImageArray[i][j]); #endif } } #ifdef F54_Porting ret += sprintf(buf+ret, "\n"); #else printk("\n"); #endif } // Set the Force Cal command = 0x02; writeRMI(F54_Command_Base, &command, 1); do { delayMS(1); //wait 1ms readRMI(F54_Command_Base, &command, 1); } while (command != 0x00); //enable all the interrupts // SetPage(0x00); //Reset command= 0x01; writeRMI(F01_Cmd_Base, &command, 1); delayMS(200); readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high //printk("Result = %d, Rx*Rx= %d\n", Result, numberOfRx * numberOfRx); if(Result == numberOfRx * numberOfRx) { #ifdef F54_Porting ret += sprintf(buf+ret, "Test Result: Pass\n"); //write_log(buf); #else printk("Test Result: Pass\n"); #endif return 1; //Pass } else { #ifdef F54_Porting ret += sprintf(buf+ret, "Test Result: Fail\n"); //write_log(buf); #else printk("Test Result: Fail\n"); #endif return 0; //Fail } } #endif
559614.c
/* * Common function shared by Linux WEXT, cfg80211 and p2p drivers * * Copyright (C) 1999-2014, Broadcom Corporation * * Unless you and Broadcom execute a separate written software license * agreement governing use of this software, this software is licensed to you * under the terms of the GNU General Public License version 2 (the "GPL"), * available at http://www.broadcom.com/licenses/GPLv2.php, with the * following added to such license: * * As a special exception, the copyright holders of this software give you * permission to link this software with independent modules, and to copy and * distribute the resulting executable under terms of your choice, provided that * you also meet, for each linked independent module, the terms and conditions of * the license of that module. An independent module is a module which is not * derived from this software. The special exception does not apply to any * modifications of the software. * * Notwithstanding the above, under no circumstances may you combine this * software in any way with any other Broadcom software provided under a license * other than the GPL, without Broadcom's express prior written consent. * * $Id: wldev_common.c 467328 2014-04-03 01:23:40Z $ */ #include <osl.h> #include <linux/kernel.h> #include <linux/kthread.h> #include <linux/netdevice.h> #include <wldev_common.h> #include <bcmutils.h> #define htod32(i) (i) #define htod16(i) (i) #define dtoh32(i) (i) #define dtoh16(i) (i) #define htodchanspec(i) (i) #define dtohchanspec(i) (i) #define WLDEV_ERROR(args) \ do { \ printk(KERN_ERR "WLDEV-ERROR) %s : ", __func__); \ printk args; \ } while (0) extern int dhd_ioctl_entry_local(struct net_device *net, wl_ioctl_t *ioc, int cmd); s32 wldev_ioctl( struct net_device *dev, u32 cmd, void *arg, u32 len, u32 set) { s32 ret = 0; struct wl_ioctl ioc; memset(&ioc, 0, sizeof(ioc)); ioc.cmd = cmd; ioc.buf = arg; ioc.len = len; ioc.set = set; ret = dhd_ioctl_entry_local(dev, &ioc, cmd); return ret; } /* Format a iovar buffer, not bsscfg indexed. The bsscfg index will be * taken care of in dhd_ioctl_entry. Internal use only, not exposed to * wl_iw, wl_cfg80211 and wl_cfgp2p */ static s32 wldev_mkiovar( s8 *iovar_name, s8 *param, s32 paramlen, s8 *iovar_buf, u32 buflen) { s32 iolen = 0; iolen = bcm_mkiovar(iovar_name, param, paramlen, iovar_buf, buflen); return iolen; } s32 wldev_iovar_getbuf( struct net_device *dev, s8 *iovar_name, void *param, s32 paramlen, void *buf, s32 buflen, struct mutex* buf_sync) { s32 ret = 0; if (buf_sync) { mutex_lock(buf_sync); } wldev_mkiovar(iovar_name, param, paramlen, buf, buflen); ret = wldev_ioctl(dev, WLC_GET_VAR, buf, buflen, FALSE); if (buf_sync) mutex_unlock(buf_sync); return ret; } s32 wldev_iovar_setbuf( struct net_device *dev, s8 *iovar_name, void *param, s32 paramlen, void *buf, s32 buflen, struct mutex* buf_sync) { s32 ret = 0; s32 iovar_len; if (buf_sync) { mutex_lock(buf_sync); } iovar_len = wldev_mkiovar(iovar_name, param, paramlen, buf, buflen); if (iovar_len > 0) ret = wldev_ioctl(dev, WLC_SET_VAR, buf, iovar_len, TRUE); else ret = BCME_BUFTOOSHORT; if (buf_sync) mutex_unlock(buf_sync); return ret; } s32 wldev_iovar_setint( struct net_device *dev, s8 *iovar, s32 val) { s8 iovar_buf[WLC_IOCTL_SMLEN]; val = htod32(val); memset(iovar_buf, 0, sizeof(iovar_buf)); return wldev_iovar_setbuf(dev, iovar, &val, sizeof(val), iovar_buf, sizeof(iovar_buf), NULL); } s32 wldev_iovar_getint( struct net_device *dev, s8 *iovar, s32 *pval) { s8 iovar_buf[WLC_IOCTL_SMLEN]; s32 err; memset(iovar_buf, 0, sizeof(iovar_buf)); err = wldev_iovar_getbuf(dev, iovar, pval, sizeof(*pval), iovar_buf, sizeof(iovar_buf), NULL); if (err == 0) { memcpy(pval, iovar_buf, sizeof(*pval)); *pval = dtoh32(*pval); } return err; } /** Format a bsscfg indexed iovar buffer. The bsscfg index will be * taken care of in dhd_ioctl_entry. Internal use only, not exposed to * wl_iw, wl_cfg80211 and wl_cfgp2p */ s32 wldev_mkiovar_bsscfg( const s8 *iovar_name, s8 *param, s32 paramlen, s8 *iovar_buf, s32 buflen, s32 bssidx) { const s8 *prefix = "bsscfg:"; s8 *p; u32 prefixlen; u32 namelen; u32 iolen; if (bssidx == 0) { return wldev_mkiovar((s8*)iovar_name, (s8 *)param, paramlen, (s8 *) iovar_buf, buflen); } prefixlen = (u32) strlen(prefix); /* lengh of bsscfg prefix */ namelen = (u32) strlen(iovar_name) + 1; /* lengh of iovar name + null */ iolen = prefixlen + namelen + sizeof(u32) + paramlen; if (buflen < 0 || iolen > (u32)buflen) { WLDEV_ERROR(("%s: buffer is too short\n", __FUNCTION__)); return BCME_BUFTOOSHORT; } p = (s8 *)iovar_buf; /* copy prefix, no null */ memcpy(p, prefix, prefixlen); p += prefixlen; /* copy iovar name including null */ memcpy(p, iovar_name, namelen); p += namelen; /* bss config index as first param */ bssidx = htod32(bssidx); memcpy(p, &bssidx, sizeof(u32)); p += sizeof(u32); /* parameter buffer follows */ if (paramlen) memcpy(p, param, paramlen); return iolen; } s32 wldev_iovar_getbuf_bsscfg( struct net_device *dev, s8 *iovar_name, void *param, s32 paramlen, void *buf, s32 buflen, s32 bsscfg_idx, struct mutex* buf_sync) { s32 ret = 0; if (buf_sync) { mutex_lock(buf_sync); } wldev_mkiovar_bsscfg(iovar_name, param, paramlen, buf, buflen, bsscfg_idx); ret = wldev_ioctl(dev, WLC_GET_VAR, buf, buflen, FALSE); if (buf_sync) { mutex_unlock(buf_sync); } return ret; } s32 wldev_iovar_setbuf_bsscfg( struct net_device *dev, s8 *iovar_name, void *param, s32 paramlen, void *buf, s32 buflen, s32 bsscfg_idx, struct mutex* buf_sync) { s32 ret = 0; s32 iovar_len; if (buf_sync) { mutex_lock(buf_sync); } iovar_len = wldev_mkiovar_bsscfg(iovar_name, param, paramlen, buf, buflen, bsscfg_idx); if (iovar_len > 0) ret = wldev_ioctl(dev, WLC_SET_VAR, buf, iovar_len, TRUE); else { ret = BCME_BUFTOOSHORT; } if (buf_sync) { mutex_unlock(buf_sync); } return ret; } s32 wldev_iovar_setint_bsscfg( struct net_device *dev, s8 *iovar, s32 val, s32 bssidx) { s8 iovar_buf[WLC_IOCTL_SMLEN]; val = htod32(val); memset(iovar_buf, 0, sizeof(iovar_buf)); return wldev_iovar_setbuf_bsscfg(dev, iovar, &val, sizeof(val), iovar_buf, sizeof(iovar_buf), bssidx, NULL); } s32 wldev_iovar_getint_bsscfg( struct net_device *dev, s8 *iovar, s32 *pval, s32 bssidx) { s8 iovar_buf[WLC_IOCTL_SMLEN]; s32 err; memset(iovar_buf, 0, sizeof(iovar_buf)); err = wldev_iovar_getbuf_bsscfg(dev, iovar, pval, sizeof(*pval), iovar_buf, sizeof(iovar_buf), bssidx, NULL); if (err == 0) { memcpy(pval, iovar_buf, sizeof(*pval)); *pval = dtoh32(*pval); } return err; } int wldev_get_link_speed( struct net_device *dev, int *plink_speed) { int error; if (!plink_speed) return -ENOMEM; error = wldev_ioctl(dev, WLC_GET_RATE, plink_speed, sizeof(int), 0); if (unlikely(error)) return error; /* Convert internal 500Kbps to Kbps */ *plink_speed *= 500; return error; } int wldev_get_rssi( struct net_device *dev, int *prssi) { scb_val_t scb_val; int error; if (!prssi) return -ENOMEM; bzero(&scb_val, sizeof(scb_val_t)); error = wldev_ioctl(dev, WLC_GET_RSSI, &scb_val, sizeof(scb_val_t), 0); if (unlikely(error)) return error; *prssi = dtoh32(scb_val.val); return error; } int wldev_get_ssid( struct net_device *dev, wlc_ssid_t *pssid) { int error; if (!pssid) return -ENOMEM; error = wldev_ioctl(dev, WLC_GET_SSID, pssid, sizeof(wlc_ssid_t), 0); if (unlikely(error)) return error; pssid->SSID_len = dtoh32(pssid->SSID_len); return error; } int wldev_get_band( struct net_device *dev, uint *pband) { int error; error = wldev_ioctl(dev, WLC_GET_BAND, pband, sizeof(uint), 0); return error; } int wldev_set_band( struct net_device *dev, uint band) { int error = -1; if ((band == WLC_BAND_AUTO) || (band == WLC_BAND_5G) || (band == WLC_BAND_2G)) { error = wldev_ioctl(dev, WLC_SET_BAND, &band, sizeof(band), true); if (!error) dhd_bus_band_set(dev, band); } return error; } int wldev_set_country( struct net_device *dev, char *country_code, bool notify, bool user_enforced) { int error = -1; wl_country_t cspec = {{0}, 0, {0}}; scb_val_t scbval; char smbuf[WLC_IOCTL_SMLEN]; if (!country_code) return error; bzero(&scbval, sizeof(scb_val_t)); error = wldev_iovar_getbuf(dev, "country", NULL, 0, &cspec, sizeof(cspec), NULL); if (error < 0) { WLDEV_ERROR(("%s: get country failed = %d\n", __FUNCTION__, error)); return error; } if ((error < 0) || dhd_force_country_change(dev) || (strncmp(country_code, cspec.country_abbrev, WLC_CNTRY_BUF_SZ) != 0)) { if (user_enforced) { bzero(&scbval, sizeof(scb_val_t)); error = wldev_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t), true); if (error < 0) { WLDEV_ERROR(("%s: set country failed due to Disassoc error %d\n", __FUNCTION__, error)); return error; } } cspec.rev = -1; memcpy(cspec.country_abbrev, country_code, WLC_CNTRY_BUF_SZ); memcpy(cspec.ccode, country_code, WLC_CNTRY_BUF_SZ); dhd_get_customized_country_code(dev, (char *)&cspec.country_abbrev, &cspec); error = wldev_iovar_setbuf(dev, "country", &cspec, sizeof(cspec), smbuf, sizeof(smbuf), NULL); if (error < 0) { WLDEV_ERROR(("%s: set country for %s as %s rev %d failed\n", __FUNCTION__, country_code, cspec.ccode, cspec.rev)); return error; } dhd_bus_country_set(dev, &cspec, notify); WLDEV_ERROR(("%s: set country for %s as %s rev %d\n", __FUNCTION__, country_code, cspec.ccode, cspec.rev)); } return 0; }
517898.c
#include "alphasparse/kernel.h" alphasparse_status_t ONAME(const ALPHA_Number alpha, const ALPHA_SPMAT_DIA *mat, const ALPHA_Number *x, const ALPHA_INT columns, const ALPHA_INT ldx, const ALPHA_Number beta, ALPHA_Number *y, const ALPHA_INT ldy) { #ifdef COMPLEX ALPHA_SPMAT_DIA *conjugated_mat; transpose_conj_dia(mat, &conjugated_mat); alphasparse_status_t status = trmm_dia_n_hi_row(alpha, conjugated_mat, x, columns, ldx, beta, y, ldy); destroy_dia(conjugated_mat); return status; #else return ALPHA_SPARSE_STATUS_INVALID_VALUE; #endif }
719446.c
// Copyright 2014 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif #include "../lpng_v163/fx_pngwrite.c"
290097.c
#region Local Var var uLocal_0 = 0; var uLocal_1 = 0; int iLocal_2 = 0; int iLocal_3 = 0; int iLocal_4 = 0; int iLocal_5 = 0; int iLocal_6 = 0; int iLocal_7 = 0; int iLocal_8 = 0; int iLocal_9 = 0; int iLocal_10 = 0; int iLocal_11 = 0; var uLocal_12 = 0; var uLocal_13 = 0; float fLocal_14 = 0f; var uLocal_15 = 0; var uLocal_16 = 0; int iLocal_17 = 0; var uLocal_18 = 0; var uLocal_19 = 0; int iLocal_20 = 0; int iLocal_21 = 0; int iLocal_22 = 0; int iLocal_23 = 0; char* sLocal_24 = NULL; var uLocal_25 = 0; var uLocal_26 = 0; var uLocal_27 = 0; var uLocal_28 = 0; var uLocal_29 = 0; var uLocal_30 = 0; var uLocal_31 = 0; int iLocal_32 = 0; #endregion void __EntryFunction__() { iLocal_2 = 1; iLocal_3 = 134; iLocal_4 = 134; iLocal_5 = 1; iLocal_6 = 1; iLocal_7 = 1; iLocal_8 = 134; iLocal_9 = 1; iLocal_10 = 12; iLocal_11 = 12; fLocal_14 = 0.001f; iLocal_17 = -1; func_222(); if (PLAYER::HAS_FORCE_CLEANUP_OCCURRED(83)) { func_221(); } while (iLocal_21 != 5) { if (!ENTITY::IS_ENTITY_DEAD(PLAYER::PLAYER_PED_ID(), false)) { switch (iLocal_21) { case 0: if (func_220()) { Global_77101 = 1; iLocal_21 = 1; } func_222(); break; case 1: if (!func_220()) { Global_42180 = 1; func_219(-1613.869f, -1054.958f, 12.0722f, -1082130432, 350, 1114636288, 0); CUTSCENE::REQUEST_CUTSCENE("SOL_5_MCS_2_P5", 8); func_218(0, 1); func_101(PLAYER::PLAYER_PED_ID(), 12, 35, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0); SYSTEM::WAIT(500); iLocal_21 = 2; } func_222(); break; case 2: if ((CUTSCENE::HAS_THIS_CUTSCENE_LOADED("SOL_5_MCS_2_P5") && func_100(0, 1)) && PED::_HAS_STREAMED_PED_ASSETS_LOADED(PLAYER::PLAYER_PED_ID())) { CLOCK::SET_CLOCK_TIME(7, 5, 30); MISC::SET_WEATHER_TYPE_NOW_PERSIST("EXTRASUNNY"); MISC::CLEAR_WEATHER_TYPE_PERSIST(); MISC::CLEAR_AREA(-1590.055f, -1037.067f, 12.0186f, 4f, true, false, false, false); func_57(&iLocal_22, 0, -1590.055f, -1037.067f, 12.0186f, 24.5062f, 1, 1); func_8(iLocal_22, -1590.055f, -1037.067f, 12.0186f, 24.5062f, 24, 0); PED::CLEAR_PED_WETNESS(PLAYER::PLAYER_PED_ID()); PED::RESET_PED_VISIBLE_DAMAGE(PLAYER::PLAYER_PED_ID()); CUTSCENE::START_CUTSCENE(0); iLocal_21 = 3; } break; case 3: if (CUTSCENE::IS_CUTSCENE_PLAYING()) { if (!iLocal_20) { iLocal_23 = ENTITY::GET_PED_INDEX_FROM_ENTITY_INDEX(CUTSCENE::GET_ENTITY_INDEX_OF_CUTSCENE_ENTITY("Michael", joaat("player_zero"))); if (ENTITY::DOES_ENTITY_EXIST(iLocal_23)) { if (!ENTITY::IS_ENTITY_DEAD(iLocal_23, false)) { PED::CLEAR_PED_BLOOD_DAMAGE(iLocal_23); PED::CLEAR_PED_DAMAGE_DECAL_BY_ZONE(iLocal_23, 0, "ALL"); PED::CLEAR_PED_DAMAGE_DECAL_BY_ZONE(iLocal_23, 1, "ALL"); PED::CLEAR_PED_DAMAGE_DECAL_BY_ZONE(iLocal_23, 4, "ALL"); PED::CLEAR_PED_DAMAGE_DECAL_BY_ZONE(iLocal_23, 5, "ALL"); PED::CLEAR_PED_DAMAGE_DECAL_BY_ZONE(iLocal_23, 2, "ALL"); PED::CLEAR_PED_DAMAGE_DECAL_BY_ZONE(iLocal_23, 3, "ALL"); iLocal_20 = 1; } } } if (!CAM::IS_SCREEN_FADED_IN()) { if (!CAM::IS_SCREEN_FADING_IN()) { CAM::DO_SCREEN_FADE_IN(800); Global_77101 = 0; } } else { iLocal_21 = 4; } } break; case 4: if (!CUTSCENE::IS_CUTSCENE_PLAYING()) { func_7(Global_93993[0 /*10*/].f_7, 1, 0); func_6(0, &sLocal_24); iLocal_32 = INTERIOR::GET_INTERIOR_AT_COORDS_WITH_TYPE(Global_93993[0 /*10*/].f_3, &sLocal_24); if (Global_99007.f_349 == iLocal_32) { Global_99007.f_349 = INTERIOR::GET_INTERIOR_FROM_ENTITY(PLAYER::PLAYER_PED_ID()); } if (iLocal_32 != 0) { INTERIOR::UNPIN_INTERIOR(iLocal_32); } Global_98994 = 0; func_4(); Global_42180 = 0; func_3(30000); func_1(0, 0); iLocal_21 = 5; } break; } } SYSTEM::WAIT(0); } func_221(); } void func_1(int iParam0, int iParam1) { if (!func_2(iParam0)) { return; } Global_111858.f_2359.f_539.f_2332[iParam0] = iParam1; } bool func_2(int iParam0) { return iParam0 < 3; } void func_3(int iParam0) { Global_42182 = (MISC::GET_GAME_TIMER() + iParam0); } int func_4() { if (func_5(0)) { return 0; } if (Global_98994.f_8) { if (Global_98994.f_10 > 0) { return 0; } } else if (Global_98994.f_10 > 1) { return 0; } Global_98994.f_10++; return 1; } bool func_5(bool bParam0) { if (!bParam0 && SCRIPT::_GET_NUMBER_OF_REFERENCES_OF_SCRIPT_WITH_NAME_HASH(joaat("benchmark")) > 0) { return 1; } return MISC::IS_BIT_SET(Global_77081, 0); } bool func_6(int iParam0, char* sParam1) { StringCopy(sParam1, "", 32); switch (iParam0) { case 0: StringCopy(sParam1, "v_michael", 32); break; case 5: StringCopy(sParam1, "v_franklins", 32); break; case 6: StringCopy(sParam1, "v_franklinshouse", 32); break; case 2: case 1: if (STREAMING::IS_IPL_ACTIVE("TrevorsTrailer")) { StringCopy(sParam1, "v_trailer", 32); } else if (STREAMING::IS_IPL_ACTIVE("TrevorsTrailerTidy")) { StringCopy(sParam1, "V_TrailerTIDY", 32); } else if (STREAMING::IS_IPL_ACTIVE("TrevorsTrailerTrash")) { StringCopy(sParam1, "V_TrailerTRASH", 32); } break; case 3: StringCopy(sParam1, "v_trevors", 32); break; case 4: StringCopy(sParam1, "v_strip3", 32); break; case 8: case 7: case 9: StringCopy(sParam1, "v_psycheoffice", 32); break; } return !MISC::ARE_STRINGS_EQUAL(sParam1, ""); } void func_7(int iParam0, bool bParam1, bool bParam2) { int iVar0; bool bVar1; iVar0 = iParam0; if ((iVar0 < 0 || iVar0 >= 263) || iParam0 == 263) { return; } if (!bParam2) { bVar1 = MISC::IS_BIT_SET(Global_31346[iVar0 /*23*/].f_11, 15); if (bVar1 == bParam1) { return; } } if (bParam1 != MISC::IS_BIT_SET(Global_31346[iVar0 /*23*/].f_11, 0)) { MISC::SET_BIT(&(Global_31346[iVar0 /*23*/].f_11), 18); if (Global_31343 == 1) { Global_31344 = 1; } Global_31343 = 1; } if (bParam1) { MISC::SET_BIT(&(Global_31346[iVar0 /*23*/].f_11), 0); MISC::SET_BIT(&(Global_31346[iVar0 /*23*/].f_11), 15); MISC::SET_BIT(&(Global_31346[iVar0 /*23*/].f_11), 3); } else { MISC::CLEAR_BIT(&(Global_31346[iVar0 /*23*/].f_11), 0); MISC::CLEAR_BIT(&(Global_31346[iVar0 /*23*/].f_11), 15); } if (!MISC::IS_BIT_SET(Global_31346[iVar0 /*23*/].f_11, 0)) { if (HUD::DOES_BLIP_EXIST(Global_31346[iVar0 /*23*/].f_19)) { MISC::SET_THIS_SCRIPT_CAN_REMOVE_BLIPS_CREATED_BY_ANY_SCRIPT(true); HUD::REMOVE_BLIP(&(Global_31346[iVar0 /*23*/].f_19)); MISC::SET_THIS_SCRIPT_CAN_REMOVE_BLIPS_CREATED_BY_ANY_SCRIPT(false); } } } void func_8(int iParam0, struct<3> Param1, float fParam4, int iParam5, bool bParam6) { struct<60> Var0; if (ENTITY::DOES_ENTITY_EXIST(iParam0) && VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) { if (iParam5 != 24 && iParam5 != 25) { return; } if (iParam5 == 24) { if (ENTITY::DOES_ENTITY_EXIST(Global_75654.f_484[25]) && VEHICLE::IS_VEHICLE_DRIVEABLE(Global_75654.f_484[25], false)) { if (Global_75654.f_484[25] == iParam0) { return; } } } if (!bParam6) { if ((VEHICLE::IS_BIG_VEHICLE(iParam0) || ENTITY::GET_ENTITY_MODEL(iParam0) == joaat("bus")) || ENTITY::GET_ENTITY_MODEL(iParam0) == joaat("tourbus")) { return; } } func_56(iParam5); Var0.f_9 = 49; Var0.f_59 = 2; func_51(iParam0, &Var0); if (func_50(Param1, 0f, 0f, 0f, 0)) { Param1 = { ENTITY::GET_ENTITY_COORDS(iParam0, true) }; fParam4 = ENTITY::GET_ENTITY_HEADING(iParam0); } if (iParam5 == 24) { if (MISC::GET_HASH_KEY(SCRIPT::GET_THIS_SCRIPT_NAME()) != joaat("vehicle_gen_controller")) { Global_76642 = MISC::GET_HASH_KEY(SCRIPT::GET_THIS_SCRIPT_NAME()); } } func_43(iParam5, &Var0, Param1, fParam4, func_49(iParam0)); func_9(iParam5, iParam0, 0); } } void func_9(int iParam0, int iParam1, int iParam2) { int iVar0; if (iParam0 == -1) { return; } if (!func_40(&(Global_75654.f_555[0 /*21*/]), iParam0)) { return; } if (!MISC::IS_BIT_SET(Global_75654.f_555[0 /*21*/].f_9, 12) && !MISC::IS_BIT_SET(Global_75654.f_555[0 /*21*/].f_9, 10)) { if (Global_75654.f_555[0 /*21*/].f_4 != ENTITY::GET_ENTITY_MODEL(iParam1)) { return; } } if (Global_76561 != -1 && Global_76561 != iParam0) { return; } if (ENTITY::DOES_ENTITY_EXIST(iParam1)) { if (VEHICLE::IS_VEHICLE_DRIVEABLE(iParam1, false)) { if (!ENTITY::IS_ENTITY_A_MISSION_ENTITY(iParam1)) { ENTITY::SET_ENTITY_AS_MISSION_ENTITY(iParam1, true, true); } if (iParam0 == 24) { Global_111858.f_32745.f_4801 = func_29(); } if (iParam1 != Global_75654.f_139[iParam0]) { if (iParam0 == 24) { iVar0 = func_28(iParam0); if ((ENTITY::DOES_ENTITY_EXIST(iVar0) && VEHICLE::IS_VEHICLE_DRIVEABLE(iVar0, false)) && iParam1 != iVar0) { func_10(iVar0, 145); } } Global_76560 = iParam1; Global_76561 = iParam0; Global_76562 = iParam2; } } } } void func_10(int iParam0, int iParam1) { int iVar0; int iVar1; int iVar2; if (!func_11(iParam0)) { return; } if ((iParam1 != 0 && iParam1 != 1) && iParam1 != 2) { iVar0 = VEHICLE::GET_PED_IN_VEHICLE_SEAT(iParam0, -1, 0); if (!ENTITY::DOES_ENTITY_EXIST(iVar0)) { iVar0 = VEHICLE::GET_LAST_PED_IN_VEHICLE_SEAT(iParam0, -1); } if (ENTITY::DOES_ENTITY_EXIST(iVar0) && !PED::IS_PED_INJURED(iVar0)) { if (ENTITY::GET_ENTITY_MODEL(iVar0) == joaat("player_zero")) { iParam1 = 0; } else if (ENTITY::GET_ENTITY_MODEL(iVar0) == joaat("player_one")) { iParam1 = 1; } else if (ENTITY::GET_ENTITY_MODEL(iVar0) == joaat("player_two")) { iParam1 = 2; } } if ((iParam1 != 0 && iParam1 != 1) && iParam1 != 2) { iParam1 = Global_111858.f_2359.f_539.f_4321; } } iVar1 = 0; while (iVar1 < 3) { iVar2 = 0; while (iVar2 < 2) { if (ENTITY::GET_ENTITY_MODEL(iParam0) == Global_111858.f_32745.f_5038[iVar1 /*157*/][iVar2 /*78*/].f_66) { if (!MISC::IS_STRING_NULL_OR_EMPTY(&(Global_111858.f_32745.f_5038[iVar1 /*157*/][iVar2 /*78*/].f_1))) { if (MISC::ARE_STRINGS_EQUAL(VEHICLE::GET_VEHICLE_NUMBER_PLATE_TEXT(iParam0), &(Global_111858.f_32745.f_5038[iVar1 /*157*/][iVar2 /*78*/].f_1))) { Global_111858.f_32745.f_5038[iVar1 /*157*/][iVar2 /*78*/].f_66 = 0; Global_111858.f_32745.f_5592[iVar1] = iVar2; } } } iVar2++; } iVar1++; } iVar1 = 0; while (iVar1 < 3) { if (ENTITY::GET_ENTITY_MODEL(iParam0) == Global_111858.f_32745.f_5600[iVar1 /*78*/].f_66) { if (!MISC::IS_STRING_NULL_OR_EMPTY(&(Global_111858.f_32745.f_5600[iVar1 /*78*/].f_1))) { if (MISC::ARE_STRINGS_EQUAL(VEHICLE::GET_VEHICLE_NUMBER_PLATE_TEXT(iParam0), &(Global_111858.f_32745.f_5600[iVar1 /*78*/].f_1))) { Global_111858.f_32745.f_5600[iVar1 /*78*/].f_66 = 0; } } } iVar1++; } Global_111858.f_32745.f_5590 = iParam1; Global_76559 = iParam0; Global_111858.f_32745.f_5588 = 1; func_51(iParam0, &(Global_111858.f_32745.f_5510)); } int func_11(int iParam0) { if ((((((((((!ENTITY::DOES_ENTITY_EXIST(iParam0) || !VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) || func_26(iParam0, 0, 0)) || func_26(iParam0, 1, 0)) || func_26(iParam0, 2, 0)) || func_49(iParam0) != 145) || func_25(iParam0)) || func_24(iParam0)) || func_23(iParam0)) || func_22(iParam0)) || !func_12(ENTITY::GET_ENTITY_MODEL(iParam0))) { if (func_24(iParam0)) { } if (func_24(iParam0)) { } if (func_26(iParam0, 0, 0)) { } if (func_26(iParam0, 1, 0)) { } if (func_26(iParam0, 2, 0)) { } if (func_49(iParam0) != 145) { } return 0; } return 1; } int func_12(int iParam0) { if (iParam0 == 0) { return 0; } if (!func_13(iParam0, 0)) { return 0; } if (((VEHICLE::IS_THIS_MODEL_A_BOAT(iParam0) || VEHICLE::IS_THIS_MODEL_A_PLANE(iParam0)) || VEHICLE::IS_THIS_MODEL_A_HELI(iParam0)) || VEHICLE::IS_THIS_MODEL_A_TRAIN(iParam0)) { return 0; } switch (iParam0) { case joaat("bus"): case joaat("stretch"): case joaat("barracks"): case joaat("armytanker"): case joaat("rhino"): case joaat("armytrailer"): case joaat("barracks2"): case joaat("flatbed"): case joaat("ripley"): case joaat("towtruck"): case joaat("towtruck2"): case joaat("airbus"): case joaat("coach"): case joaat("rentalbus"): case joaat("tourbus"): case joaat("firetruk"): case joaat("pbus"): case joaat("trash"): case joaat("benson"): case joaat("boattrailer"): case joaat("biff"): case joaat("hauler"): case joaat("docktrailer"): case joaat("phantom"): case joaat("pounder"): case joaat("tractor2"): case joaat("bulldozer"): case joaat("handler"): case joaat("tiptruck"): case joaat("cutter"): case joaat("dump"): case joaat("mixer"): case joaat("mixer2"): case joaat("rubble"): case joaat("scrap"): case joaat("tiptruck2"): case joaat("camper"): case joaat("taco"): case joaat("boxville"): case joaat("boxville2"): case joaat("boxville3"): case joaat("journey"): case joaat("mule"): case joaat("mule2"): case joaat("police"): case joaat("police2"): case joaat("police3"): case joaat("police4"): case joaat("policeb"): case joaat("policeold1"): case joaat("policeold2"): case joaat("policet"): case joaat("taxi"): case joaat("submersible"): case joaat("submersible2"): case joaat("monster"): return 0; break; } return 1; } int func_13(int iParam0, bool bParam1) { int iVar0; struct<2> Var1; if (iParam0 == 0) { return 0; } if (!STREAMING::IS_MODEL_A_VEHICLE(iParam0)) { return 0; } if (((((iParam0 == joaat("dominator2") && !NETWORK::NETWORK_IS_GAME_IN_PROGRESS()) || (iParam0 == joaat("buffalo3") && !NETWORK::NETWORK_IS_GAME_IN_PROGRESS())) || (iParam0 == joaat("gauntlet2") && !NETWORK::NETWORK_IS_GAME_IN_PROGRESS())) || iParam0 == joaat("blimp2")) || (iParam0 == joaat("stalion2") && !NETWORK::NETWORK_IS_GAME_IN_PROGRESS())) { if (!func_21()) { return 0; } } else { iVar0 = 0; while (iVar0 < FILES::GET_NUM_DLC_VEHICLES()) { if (FILES::GET_DLC_VEHICLE_DATA(iVar0, &Var1)) { if (iParam0 == Var1.f_1) { if (FILES::IS_CONTENT_ITEM_LOCKED(Var1)) { return 0; } } } iVar0++; } } if (iParam0 == joaat("blimp")) { if ((((!func_20() && !func_19()) && !func_18()) && !func_17()) && !func_21()) { return 0; } } if ((iParam0 == joaat("hotknife") || iParam0 == joaat("carbonrs")) || iParam0 == joaat("khamelion")) { if ((MISC::IS_DURANGO_VERSION() || MISC::IS_PC_VERSION()) || MISC::IS_ORBIS_VERSION()) { } else if (!func_18()) { return 0; } } if (bParam1) { if (!func_16(iParam0)) { return 0; } } if (!func_14(iParam0)) { return 0; } return 1; } int func_14(int iParam0) { int iVar0; var uVar1; char cVar2[64]; if (!func_15()) { return 1; } NETSHOPPING::_NET_GAMESERVER_GET_TRANSACTION_MANAGER_DATA(&iVar0, &uVar1); if (iVar0 == 4) { return 1; } switch (iParam0) { case joaat("dune4"): StringCopy(&cVar2, "VE_DUNE4_t0_v3", 64); break; case joaat("voltic2"): StringCopy(&cVar2, "VE_VOLTIC2_t0_v3", 64); break; case joaat("ruiner2"): StringCopy(&cVar2, "VE_RUINER2_t0_v3", 64); break; case joaat("phantom2"): StringCopy(&cVar2, "VE_PHANTOM2_t0_v3", 64); break; case joaat("technical2"): StringCopy(&cVar2, "VE_TECHNICAL2_t0_v3", 64); break; case joaat("boxville5"): StringCopy(&cVar2, "VE_BOXVILLE5_t0_v3", 64); break; case joaat("wastelander"): StringCopy(&cVar2, "VE_WASTELANDER_t0_v3", 64); break; case joaat("blazer5"): StringCopy(&cVar2, "VE_BLAZER5_t0_v3", 64); break; default: return 1; break; } if (!NETSHOPPING::_NET_GAMESERVER_CATALOG_ITEM_EXISTS(&cVar2)) { return 0; } return 1; } int func_15() { if (MISC::IS_PC_VERSION()) { return NETSHOPPING::_NET_GAMESERVER_USE_SERVER_TRANSACTIONS(); } return 0; } int func_16(int iParam0) { int iVar0; int iVar1; if (Global_2515213) { return 1; } iVar0 = 1; iVar1 = NETWORK::GET_CLOUD_TIME_AS_INT(); if (iParam0 == joaat("btype3")) { if ((!Global_262145.f_6600 && !Global_262145.f_12930) && iVar1 < Global_262145.f_12931) { iVar0 = 0; } } if (iParam0 == joaat("faction3")) { if (!Global_262145.f_14230 && iVar1 < Global_262145.f_14242) { iVar0 = 0; } } else if (iParam0 == joaat("virgo3") || iParam0 == joaat("virgo2")) { if (!Global_262145.f_14226 && iVar1 < Global_262145.f_14238) { iVar0 = 0; } } else if (iParam0 == joaat("sabregt2")) { if (!Global_262145.f_14227 && iVar1 < Global_262145.f_14239) { iVar0 = 0; } } else if (iParam0 == joaat("tornado5")) { if (!Global_262145.f_14228 && iVar1 < Global_262145.f_14240) { iVar0 = 0; } } else if (iParam0 == joaat("minivan2")) { if (!Global_262145.f_14229 && iVar1 < Global_262145.f_14241) { iVar0 = 0; } } else if (iParam0 == joaat("slamvan3")) { if (!Global_262145.f_14231 && iVar1 < Global_262145.f_14243) { iVar0 = 0; } } if (iParam0 == joaat("prototipo")) { if (!Global_262145.f_14232 && iVar1 < Global_262145.f_14235) { iVar0 = 0; } } else if (iParam0 == joaat("seven70")) { if (!Global_262145.f_14233 && iVar1 < Global_262145.f_14236) { iVar0 = 0; } } else if (iParam0 == joaat("pfister811")) { if (!Global_262145.f_14234 && iVar1 < Global_262145.f_14237) { iVar0 = 0; } } if (iParam0 == joaat("bf400")) { if (!Global_262145.f_16861 && iVar1 < Global_262145.f_16826) { iVar0 = 0; } } else if (iParam0 == joaat("brioso")) { if (!Global_262145.f_16856 && iVar1 < Global_262145.f_16821) { iVar0 = 0; } } else if (iParam0 == joaat("cliffhanger")) { if (!Global_262145.f_16860 && iVar1 < Global_262145.f_16825) { iVar0 = 0; } } else if (iParam0 == joaat("contender")) { if (!Global_262145.f_16859 && iVar1 < Global_262145.f_16824) { iVar0 = 0; } } else if (iParam0 == joaat("le7b")) { if (!Global_262145.f_16853 && iVar1 < Global_262145.f_16818) { iVar0 = 0; } } else if (iParam0 == joaat("omnis")) { if (!Global_262145.f_16854 && iVar1 < Global_262145.f_16819) { iVar0 = 0; } } else if (iParam0 == joaat("trophytruck")) { if (!Global_262145.f_16857 && iVar1 < Global_262145.f_16822) { iVar0 = 0; } } else if (iParam0 == joaat("trophytruck2")) { if (!Global_262145.f_16858 && iVar1 < Global_262145.f_16823) { iVar0 = 0; } } else if (iParam0 == joaat("tropos")) { if (!Global_262145.f_16855 && iVar1 < Global_262145.f_16820) { iVar0 = 0; } } else if (iParam0 == joaat("gargoyle")) { if (!Global_262145.f_16863 && iVar1 < Global_262145.f_16828) { iVar0 = 0; } } else if (iParam0 == joaat("rallytruck")) { if (!Global_262145.f_16864 && iVar1 < Global_262145.f_16829) { iVar0 = 0; } } else if (iParam0 == joaat("tampa2")) { if (!Global_262145.f_16852 && iVar1 < Global_262145.f_16817) { iVar0 = 0; } } else if (iParam0 == joaat("tyrus")) { if (!Global_262145.f_16851 && iVar1 < Global_262145.f_16816) { iVar0 = 0; } } else if (iParam0 == joaat("sheava")) { if (!Global_262145.f_16850 && iVar1 < Global_262145.f_16815) { iVar0 = 0; } } else if (iParam0 == joaat("lynx")) { if (!Global_262145.f_16862 && iVar1 < Global_262145.f_16827) { iVar0 = 0; } } else if (iParam0 == joaat("stalion2")) { if (!Global_262145.f_16865 && iVar1 < Global_262145.f_16830) { iVar0 = 0; } } else if (iParam0 == joaat("gauntlet2")) { if (!Global_262145.f_16866 && iVar1 < Global_262145.f_16831) { iVar0 = 0; } } else if (iParam0 == joaat("dominator2")) { if (!Global_262145.f_16867 && iVar1 < Global_262145.f_16832) { iVar0 = 0; } } else if (iParam0 == joaat("buffalo3")) { if (!Global_262145.f_16868 && iVar1 < Global_262145.f_16833) { iVar0 = 0; } } if (iParam0 == joaat("defiler")) { if (!Global_262145.f_17015 && iVar1 < Global_262145.f_17037) { iVar0 = 0; } } else if (iParam0 == joaat("nightblade")) { if (!Global_262145.f_17016 && iVar1 < Global_262145.f_17038) { iVar0 = 0; } } else if (iParam0 == joaat("zombiea")) { if (!Global_262145.f_17017 && iVar1 < Global_262145.f_17039) { iVar0 = 0; } } else if (iParam0 == joaat("esskey")) { if (!Global_262145.f_17018 && iVar1 < Global_262145.f_17040) { iVar0 = 0; } } else if (iParam0 == joaat("avarus")) { if (!Global_262145.f_17019 && iVar1 < Global_262145.f_17041) { iVar0 = 0; } } else if (iParam0 == joaat("zombieb")) { if (!Global_262145.f_17020 && iVar1 < Global_262145.f_17042) { iVar0 = 0; } } else if (iParam0 == joaat("hakuchou2")) { if (!Global_262145.f_17022 && iVar1 < Global_262145.f_17043) { iVar0 = 0; } } else if (iParam0 == joaat("vortex")) { if (!Global_262145.f_17023 && iVar1 < Global_262145.f_17044) { iVar0 = 0; } } else if (iParam0 == joaat("shotaro")) { if (!Global_262145.f_17024 && iVar1 < Global_262145.f_17045) { iVar0 = 0; } } else if (iParam0 == joaat("chimera")) { if (!Global_262145.f_17025 && iVar1 < Global_262145.f_17046) { iVar0 = 0; } } else if (iParam0 == joaat("raptor")) { if (!Global_262145.f_17026 && iVar1 < Global_262145.f_17047) { iVar0 = 0; } } else if (iParam0 == joaat("daemon2")) { if (!Global_262145.f_17027 && iVar1 < Global_262145.f_17048) { iVar0 = 0; } } else if (iParam0 == joaat("blazer4")) { if (!Global_262145.f_17028 && iVar1 < Global_262145.f_17049) { iVar0 = 0; } } else if (iParam0 == joaat("tornado6")) { if (!Global_262145.f_17034 && iVar1 < Global_262145.f_17056) { iVar0 = 0; } } else if (iParam0 == joaat("youga2")) { if (!Global_262145.f_17031 && iVar1 < Global_262145.f_17052) { iVar0 = 0; } } else if (iParam0 == joaat("wolfsbane")) { if (!Global_262145.f_17032 && iVar1 < Global_262145.f_17053) { iVar0 = 0; } } else if (iParam0 == joaat("faggio3")) { if (!Global_262145.f_17033 && iVar1 < Global_262145.f_17054) { iVar0 = 0; } } else if (iParam0 == joaat("faggio")) { if (!Global_262145.f_17021 && iVar1 < Global_262145.f_17055) { iVar0 = 0; } } else if (iParam0 == joaat("bagger")) { if (!Global_262145.f_17035 && iVar1 < Global_262145.f_17057) { iVar0 = 0; } } else if (iParam0 == joaat("sanctus")) { if (!Global_262145.f_17029 && iVar1 < Global_262145.f_17050) { iVar0 = 0; } } else if (iParam0 == joaat("manchez")) { if (!Global_262145.f_17030 && iVar1 < Global_262145.f_17051) { iVar0 = 0; } } else if (iParam0 == joaat("ratbike")) { if (!Global_262145.f_17036 && iVar1 < Global_262145.f_17058) { iVar0 = 0; } } if (iParam0 == joaat("voltic2")) { if (!Global_262145.f_18667 && iVar1 < Global_262145.f_18764) { iVar0 = 0; } } else if (iParam0 == joaat("ruiner2")) { if (!Global_262145.f_18668 && iVar1 < Global_262145.f_18765) { iVar0 = 0; } } else if (iParam0 == joaat("dune4")) { if (!Global_262145.f_18669 && iVar1 < Global_262145.f_18766) { iVar0 = 0; } } else if (iParam0 == joaat("dune5")) { if (!Global_262145.f_18670 && iVar1 < Global_262145.f_18767) { iVar0 = 0; } } else if (iParam0 == joaat("phantom2")) { if (!Global_262145.f_18671 && iVar1 < Global_262145.f_18768) { iVar0 = 0; } } else if (iParam0 == joaat("technical2")) { if (!Global_262145.f_18672 && iVar1 < Global_262145.f_18769) { iVar0 = 0; } } else if (iParam0 == joaat("boxville5")) { if (!Global_262145.f_18673 && iVar1 < Global_262145.f_18770) { iVar0 = 0; } } else if (iParam0 == joaat("wastelander")) { if (!Global_262145.f_18674 && iVar1 < Global_262145.f_18771) { iVar0 = 0; } } else if (iParam0 == joaat("blazer5")) { if (!Global_262145.f_18675 && iVar1 < Global_262145.f_18772) { iVar0 = 0; } } else if (iParam0 == joaat("comet2")) { if (!Global_262145.f_18676 && iVar1 < Global_262145.f_18773) { iVar0 = 0; } } else if (iParam0 == joaat("comet3")) { if (!Global_262145.f_18677 && iVar1 < Global_262145.f_18774) { iVar0 = 0; } } else if (iParam0 == joaat("diablous")) { if (!Global_262145.f_18678 && iVar1 < Global_262145.f_18775) { iVar0 = 0; } } else if (iParam0 == joaat("diablous2")) { if (!Global_262145.f_18679 && iVar1 < Global_262145.f_18776) { iVar0 = 0; } } else if (iParam0 == joaat("elegy")) { if (!Global_262145.f_18680 && iVar1 < Global_262145.f_18777) { iVar0 = 0; } } else if (iParam0 == joaat("elegy2")) { if (!Global_262145.f_18681 && iVar1 < Global_262145.f_18778) { iVar0 = 0; } } else if (iParam0 == joaat("fcr")) { if (!Global_262145.f_18682 && iVar1 < Global_262145.f_18779) { iVar0 = 0; } } else if (iParam0 == joaat("fcr2")) { if (!Global_262145.f_18683 && iVar1 < Global_262145.f_18780) { iVar0 = 0; } } else if (iParam0 == joaat("italigtb")) { if (!Global_262145.f_18684 && iVar1 < Global_262145.f_18781) { iVar0 = 0; } } else if (iParam0 == joaat("italigtb2")) { if (!Global_262145.f_18685 && iVar1 < Global_262145.f_18782) { iVar0 = 0; } } else if (iParam0 == joaat("nero")) { if (!Global_262145.f_18686 && iVar1 < Global_262145.f_18783) { iVar0 = 0; } } else if (iParam0 == joaat("nero2")) { if (!Global_262145.f_18687 && iVar1 < Global_262145.f_18784) { iVar0 = 0; } } else if (iParam0 == joaat("penetrator")) { if (!Global_262145.f_18688 && iVar1 < Global_262145.f_18785) { iVar0 = 0; } } else if (iParam0 == joaat("specter")) { if (!Global_262145.f_18689 && iVar1 < Global_262145.f_18786) { iVar0 = 0; } } else if (iParam0 == joaat("specter2")) { if (!Global_262145.f_18690 && iVar1 < Global_262145.f_18787) { iVar0 = 0; } } else if (iParam0 == joaat("tempesta")) { if (!Global_262145.f_18691 && iVar1 < Global_262145.f_18788) { iVar0 = 0; } } if (iParam0 == joaat("gp1")) { if (!Global_262145.f_19748 && iVar1 < Global_262145.f_19744) { iVar0 = 0; } } else if (iParam0 == joaat("infernus2")) { if (!Global_262145.f_19749 && iVar1 < Global_262145.f_19745) { iVar0 = 0; } } else if (iParam0 == joaat("ruston")) { if (!Global_262145.f_19750 && iVar1 < Global_262145.f_19746) { iVar0 = 0; } } else if (iParam0 == joaat("turismo2")) { if (!Global_262145.f_19751 && iVar1 < Global_262145.f_19747) { iVar0 = 0; } } if (iParam0 == joaat("xa21")) { if (!Global_262145.f_20629 && iVar1 < Global_262145.f_20637) { iVar0 = 0; } } else if (iParam0 == joaat("cheetah2")) { if (!Global_262145.f_20630 && iVar1 < Global_262145.f_20638) { iVar0 = 0; } } else if (iParam0 == joaat("torero")) { if (!Global_262145.f_20631 && iVar1 < Global_262145.f_20639) { iVar0 = 0; } } else if (iParam0 == joaat("vagner")) { if (!Global_262145.f_20632 && iVar1 < Global_262145.f_20640) { iVar0 = 0; } } else if (iParam0 == joaat("ardent")) { if (!Global_262145.f_20633 && iVar1 < Global_262145.f_20641) { iVar0 = 0; } } else if (iParam0 == joaat("nightshark")) { if (!Global_262145.f_20634 && iVar1 < Global_262145.f_20642) { iVar0 = 0; } } if (iParam0 == joaat("microlight")) { if (!Global_262145.f_21409 && iVar1 < Global_262145.f_21429) { iVar0 = 0; } } else if (iParam0 == joaat("mogul")) { if (!Global_262145.f_21421 && iVar1 < Global_262145.f_21441) { iVar0 = 0; } } else if (iParam0 == joaat("rogue")) { if (!Global_262145.f_21412 && iVar1 < Global_262145.f_21432) { iVar0 = 0; } } else if (iParam0 == joaat("starling")) { if (!Global_262145.f_21422 && iVar1 < Global_262145.f_21442) { iVar0 = 0; } } else if (iParam0 == joaat("seabreeze")) { if (!Global_262145.f_21410 && iVar1 < Global_262145.f_21430) { iVar0 = 0; } } else if (iParam0 == joaat("tula")) { if (!Global_262145.f_21426 && iVar1 < Global_262145.f_21446) { iVar0 = 0; } } else if (iParam0 == joaat("pyro")) { if (!Global_262145.f_21424 && iVar1 < Global_262145.f_21444) { iVar0 = 0; } } else if (iParam0 == joaat("molotok")) { if (!Global_262145.f_21425 && iVar1 < Global_262145.f_21445) { iVar0 = 0; } } else if (iParam0 == joaat("nokota")) { if (!Global_262145.f_21420 && iVar1 < Global_262145.f_21440) { iVar0 = 0; } } else if (iParam0 == joaat("bombushka")) { if (!Global_262145.f_21427 && iVar1 < Global_262145.f_21447) { iVar0 = 0; } } else if (iParam0 == joaat("hunter")) { if (!Global_262145.f_21423 && iVar1 < Global_262145.f_21443) { iVar0 = 0; } } else if (iParam0 == joaat("havok")) { if (!Global_262145.f_21419 && iVar1 < Global_262145.f_21439) { iVar0 = 0; } } else if (iParam0 == joaat("howard")) { if (!Global_262145.f_21411 && iVar1 < Global_262145.f_21431) { iVar0 = 0; } } else if (iParam0 == joaat("alphaz1")) { if (!Global_262145.f_21413 && iVar1 < Global_262145.f_21433) { iVar0 = 0; } } else if (iParam0 == joaat("cyclone")) { if (!Global_262145.f_21414 && iVar1 < Global_262145.f_21434) { iVar0 = 0; } } else if (iParam0 == joaat("visione")) { if (!Global_262145.f_21415 && iVar1 < Global_262145.f_21435) { iVar0 = 0; } } else if (iParam0 == joaat("vigilante")) { if (!Global_262145.f_21416 && iVar1 < Global_262145.f_21436) { iVar0 = 0; } } else if (iParam0 == joaat("retinue")) { if (!Global_262145.f_21417 && iVar1 < Global_262145.f_21437) { iVar0 = 0; } } else if (iParam0 == joaat("rapidgt3")) { if (!Global_262145.f_21418 && iVar1 < Global_262145.f_21438) { iVar0 = 0; } } if (iParam0 == joaat("deluxo")) { if (!Global_262145.f_22370 && iVar1 < Global_262145.f_22398) { iVar0 = 0; } } else if (iParam0 == joaat("stromberg")) { if (!Global_262145.f_22371 && iVar1 < Global_262145.f_22399) { iVar0 = 0; } } else if (iParam0 == joaat("riot2")) { if (!Global_262145.f_22372 && iVar1 < Global_262145.f_22400) { iVar0 = 0; } } else if (iParam0 == joaat("chernobog")) { if (!Global_262145.f_22373 && iVar1 < Global_262145.f_22401) { iVar0 = 0; } } else if (iParam0 == joaat("khanjali")) { if (!Global_262145.f_22374 && iVar1 < Global_262145.f_22402) { iVar0 = 0; } } else if (iParam0 == joaat("akula")) { if (!Global_262145.f_22375 && iVar1 < Global_262145.f_22403) { iVar0 = 0; } } else if (iParam0 == joaat("thruster")) { if (!Global_262145.f_22376 && iVar1 < Global_262145.f_22404) { iVar0 = 0; } } else if (iParam0 == joaat("barrage")) { if (!Global_262145.f_22377 && iVar1 < Global_262145.f_22405) { iVar0 = 0; } } else if (iParam0 == joaat("volatol")) { if (!Global_262145.f_22378 && iVar1 < Global_262145.f_22406) { iVar0 = 0; } } else if (iParam0 == joaat("comet4")) { if (!Global_262145.f_22379 && iVar1 < Global_262145.f_22407) { iVar0 = 0; } } else if (iParam0 == joaat("neon")) { if (!Global_262145.f_22380 && iVar1 < Global_262145.f_22408) { iVar0 = 0; } } else if (iParam0 == joaat("streiter")) { if (!Global_262145.f_22381 && iVar1 < Global_262145.f_22409) { iVar0 = 0; } } else if (iParam0 == joaat("sentinel3")) { if (!Global_262145.f_22382 && iVar1 < Global_262145.f_22410) { iVar0 = 0; } } else if (iParam0 == joaat("yosemite")) { if (!Global_262145.f_22383 && iVar1 < Global_262145.f_22411) { iVar0 = 0; } } else if (iParam0 == joaat("sc1")) { if (!Global_262145.f_22384 && iVar1 < Global_262145.f_22412) { iVar0 = 0; } } else if (iParam0 == joaat("autarch")) { if (!Global_262145.f_22385 && iVar1 < Global_262145.f_22413) { iVar0 = 0; } } else if (iParam0 == joaat("gt500")) { if (!Global_262145.f_22386 && iVar1 < Global_262145.f_22414) { iVar0 = 0; } } else if (iParam0 == joaat("hustler")) { if (!Global_262145.f_22387 && iVar1 < Global_262145.f_22415) { iVar0 = 0; } } else if (iParam0 == joaat("revolter")) { if (!Global_262145.f_22388 && iVar1 < Global_262145.f_22416) { iVar0 = 0; } } else if (iParam0 == joaat("pariah")) { if (!Global_262145.f_22389 && iVar1 < Global_262145.f_22417) { iVar0 = 0; } } else if (iParam0 == joaat("raiden")) { if (!Global_262145.f_22390 && iVar1 < Global_262145.f_22418) { iVar0 = 0; } } else if (iParam0 == joaat("savestra")) { if (!Global_262145.f_22391 && iVar1 < Global_262145.f_22419) { iVar0 = 0; } } else if (iParam0 == joaat("riata")) { if (!Global_262145.f_22392 && iVar1 < Global_262145.f_22420) { iVar0 = 0; } } else if (iParam0 == joaat("hermes")) { if (!Global_262145.f_22393 && iVar1 < Global_262145.f_22421) { iVar0 = 0; } } else if (iParam0 == joaat("comet5")) { if (!Global_262145.f_22394 && iVar1 < Global_262145.f_22422) { iVar0 = 0; } } else if (iParam0 == joaat("z190")) { if (!Global_262145.f_22395 && iVar1 < Global_262145.f_22423) { iVar0 = 0; } } else if (iParam0 == joaat("viseris")) { if (!Global_262145.f_22396 && iVar1 < Global_262145.f_22424) { iVar0 = 0; } } else if (iParam0 == joaat("kamacho")) { if (!Global_262145.f_22397 && iVar1 < Global_262145.f_22425) { iVar0 = 0; } } if (iParam0 == joaat("gb200")) { if (!Global_262145.f_23586 && iVar1 < Global_262145.f_23602) { iVar0 = 0; } } else if (iParam0 == joaat("fagaloa")) { if (!Global_262145.f_23587 && iVar1 < Global_262145.f_23603) { iVar0 = 0; } } else if (iParam0 == joaat("ellie")) { if (!Global_262145.f_23591 && iVar1 < Global_262145.f_23607) { iVar0 = 0; } } else if (iParam0 == joaat("issi3")) { if (!Global_262145.f_23594 && iVar1 < Global_262145.f_23610) { iVar0 = 0; } } else if (iParam0 == joaat("michelli")) { if (!Global_262145.f_23599 && iVar1 < Global_262145.f_23615) { iVar0 = 0; } } else if (iParam0 == joaat("flashgt")) { if (!Global_262145.f_23593 && iVar1 < Global_262145.f_23609) { iVar0 = 0; } } else if (iParam0 == joaat("hotring")) { if (!Global_262145.f_23585 && iVar1 < Global_262145.f_23601) { iVar0 = 0; } } else if (iParam0 == joaat("tezeract")) { if (!Global_262145.f_23592 && iVar1 < Global_262145.f_23608) { iVar0 = 0; } } else if (iParam0 == joaat("tyrant")) { if (!Global_262145.f_23598 && iVar1 < Global_262145.f_23614) { iVar0 = 0; } } else if (iParam0 == joaat("dominator3")) { if (!Global_262145.f_23597 && iVar1 < Global_262145.f_23613) { iVar0 = 0; } } else if (iParam0 == joaat("taipan")) { if (!Global_262145.f_23588 && iVar1 < Global_262145.f_23604) { iVar0 = 0; } } else if (iParam0 == joaat("entity2")) { if (!Global_262145.f_23590 && iVar1 < Global_262145.f_23606) { iVar0 = 0; } } else if (iParam0 == joaat("jester3")) { if (!Global_262145.f_23600 && iVar1 < Global_262145.f_23616) { iVar0 = 0; } } else if (iParam0 == joaat("cheburek")) { if (!Global_262145.f_23596 && iVar1 < Global_262145.f_23612) { iVar0 = 0; } } else if (iParam0 == joaat("caracara")) { if (!Global_262145.f_23589 && iVar1 < Global_262145.f_23605) { iVar0 = 0; } } else if (iParam0 == joaat("seasparrow")) { if (!Global_262145.f_23595 && iVar1 < Global_262145.f_23611) { iVar0 = 0; } } if (iParam0 == joaat("terbyte")) { if (!Global_262145.f_23676 && iVar1 < Global_262145.f_23663) { iVar0 = 0; } } else if (iParam0 == joaat("pbus2")) { if (!Global_262145.f_23677 && iVar1 < Global_262145.f_23664) { iVar0 = 0; } } else if (iParam0 == joaat("mule4")) { if (!Global_262145.f_23682 && iVar1 < Global_262145.f_23669) { iVar0 = 0; } } else if (iParam0 == joaat("pounder2")) { if (!Global_262145.f_23681 && iVar1 < Global_262145.f_23668) { iVar0 = 0; } } else if (iParam0 == joaat("swinger")) { if (!Global_262145.f_23679 && iVar1 < Global_262145.f_23666) { iVar0 = 0; } } else if (iParam0 == joaat("menacer")) { if (!Global_262145.f_23685 && iVar1 < Global_262145.f_23672) { iVar0 = 0; } } else if (iParam0 == joaat("scramjet")) { if (!Global_262145.f_23687 && iVar1 < Global_262145.f_23674) { iVar0 = 0; } } else if (iParam0 == joaat("strikeforce")) { if (!Global_262145.f_23688 && iVar1 < Global_262145.f_23675) { iVar0 = 0; } } else if (iParam0 == joaat("oppressor2")) { if (!Global_262145.f_23686 && iVar1 < Global_262145.f_23673) { iVar0 = 0; } } else if (iParam0 == joaat("patriot2")) { if (!Global_262145.f_23678 && iVar1 < Global_262145.f_23665) { iVar0 = 0; } } else if (iParam0 == joaat("stafford")) { if (!Global_262145.f_23680 && iVar1 < Global_262145.f_23667) { iVar0 = 0; } } else if (iParam0 == joaat("freecrawler")) { if (!Global_262145.f_23684 && iVar1 < Global_262145.f_23671) { iVar0 = 0; } } else if (iParam0 == joaat("blimp3")) { if (!Global_262145.f_23683 && iVar1 < Global_262145.f_23670) { iVar0 = 0; } } if (iParam0 == joaat("monster3")) { } else if (iParam0 == joaat("cerberus")) { } else if (iParam0 == joaat("cerberus2")) { } else if (iParam0 == joaat("cerberus3")) { } else if (iParam0 == joaat("brutus")) { } else if (iParam0 == joaat("brutus2")) { } else if (iParam0 == joaat("brutus3")) { } else if (iParam0 == joaat("scarab")) { } else if (iParam0 == joaat("scarab2")) { } else if (iParam0 == joaat("scarab3")) { } else if (iParam0 == joaat("imperator")) { } else if (iParam0 == joaat("imperator2")) { } else if (iParam0 == joaat("imperator3")) { } else if (iParam0 == joaat("zr380")) { } else if (iParam0 == joaat("zr3802")) { } else if (iParam0 == joaat("zr3803")) { } else if (iParam0 == joaat("impaler")) { } else if (iParam0 == joaat("deveste")) { if (!Global_262145.f_26051 && iVar1 < Global_262145.f_26053) { iVar0 = 0; } } else if (iParam0 == joaat("toros")) { if (!Global_262145.f_25064 && iVar1 < Global_262145.f_25057) { iVar0 = 0; } } else if (iParam0 == joaat("clique")) { if (!Global_262145.f_25065 && iVar1 < Global_262145.f_25058) { iVar0 = 0; } } else if (iParam0 == joaat("italigto")) { if (!Global_262145.f_25066 && iVar1 < Global_262145.f_25059) { iVar0 = 0; } } else if (iParam0 == joaat("deviant")) { if (!Global_262145.f_25067 && iVar1 < Global_262145.f_25060) { iVar0 = 0; } } else if (iParam0 == joaat("vamos")) { if (!Global_262145.f_26052 && iVar1 < Global_262145.f_26054) { iVar0 = 0; } } else if (iParam0 == joaat("tulip")) { if (!Global_262145.f_25068 && iVar1 < Global_262145.f_25061) { iVar0 = 0; } } else if (iParam0 == joaat("schlagen")) { if (!Global_262145.f_25069 && iVar1 < Global_262145.f_25062) { iVar0 = 0; } } else if (iParam0 == joaat("rcbandito")) { if (!Global_262145.f_25070 && iVar1 < Global_262145.f_25063) { iVar0 = 0; } } else if (iParam0 == joaat("thrax")) { if (!Global_262145.f_25075 && iVar1 < Global_262145.f_25096) { iVar0 = 0; } } else if (iParam0 == joaat("drafter")) { if (!Global_262145.f_25076 && iVar1 < Global_262145.f_25097) { iVar0 = 0; } } else if (iParam0 == joaat("locust")) { if (!Global_262145.f_25077 && iVar1 < Global_262145.f_25098) { iVar0 = 0; } } else if (iParam0 == joaat("novak")) { if (!Global_262145.f_25078 && iVar1 < Global_262145.f_25099) { iVar0 = 0; } } else if (iParam0 == joaat("zorrusso")) { if (!Global_262145.f_25079 && iVar1 < Global_262145.f_25100) { iVar0 = 0; } } else if (iParam0 == joaat("gauntlet3")) { if (!Global_262145.f_25080 && iVar1 < Global_262145.f_25101) { iVar0 = 0; } } else if (iParam0 == joaat("issi7")) { if (!Global_262145.f_25081 && iVar1 < Global_262145.f_25102) { iVar0 = 0; } } else if (iParam0 == joaat("zion3")) { if (!Global_262145.f_25082 && iVar1 < Global_262145.f_25103) { iVar0 = 0; } } else if (iParam0 == joaat("nebula")) { if (!Global_262145.f_25083 && iVar1 < Global_262145.f_25104) { iVar0 = 0; } } else if (iParam0 == joaat("hellion")) { if (!Global_262145.f_25084 && iVar1 < Global_262145.f_25105) { iVar0 = 0; } } else if (iParam0 == joaat("dynasty")) { if (!Global_262145.f_25085 && iVar1 < Global_262145.f_25106) { iVar0 = 0; } } else if (iParam0 == joaat("rrocket")) { if (!Global_262145.f_25086 && iVar1 < Global_262145.f_25107) { iVar0 = 0; } } else if (iParam0 == joaat("peyote2")) { if (!Global_262145.f_25087 && iVar1 < Global_262145.f_25108) { iVar0 = 0; } } else if (iParam0 == joaat("gauntlet4")) { if (!Global_262145.f_25088 && iVar1 < Global_262145.f_25109) { iVar0 = 0; } } else if (iParam0 == joaat("caracara2")) { if (!Global_262145.f_25089 && iVar1 < Global_262145.f_25110) { iVar0 = 0; } } else if (iParam0 == joaat("jugular")) { if (!Global_262145.f_25090 && iVar1 < Global_262145.f_25111) { iVar0 = 0; } } else if (iParam0 == joaat("s80")) { if (!Global_262145.f_25091 && iVar1 < Global_262145.f_25112) { iVar0 = 0; } } else if (iParam0 == joaat("krieger")) { if (!Global_262145.f_25092 && iVar1 < Global_262145.f_25113) { iVar0 = 0; } } else if (iParam0 == joaat("emerus")) { if (!Global_262145.f_25093 && iVar1 < Global_262145.f_25114) { iVar0 = 0; } } else if (iParam0 == joaat("neo")) { if (!Global_262145.f_25094 && iVar1 < Global_262145.f_25115) { iVar0 = 0; } } else if (iParam0 == joaat("paragon")) { if (!Global_262145.f_25095 && iVar1 < Global_262145.f_25116) { iVar0 = 0; } } else if (iParam0 == joaat("asbo")) { if (!Global_262145.f_27895 && iVar1 < Global_262145.f_27916) { iVar0 = 0; } } else if (iParam0 == joaat("kanjo")) { if (!Global_262145.f_27896 && iVar1 < Global_262145.f_27917) { iVar0 = 0; } } else if (iParam0 == joaat("everon")) { if (!Global_262145.f_27897 && iVar1 < Global_262145.f_27918) { iVar0 = 0; } } else if (iParam0 == joaat("retinue2")) { if (!Global_262145.f_27898 && iVar1 < Global_262145.f_27919) { iVar0 = 0; } } else if (iParam0 == joaat("yosemite2")) { if (!Global_262145.f_27899 && iVar1 < Global_262145.f_27920) { iVar0 = 0; } } else if (iParam0 == joaat("sugoi")) { if (!Global_262145.f_27900 && iVar1 < Global_262145.f_27921) { iVar0 = 0; } } else if (iParam0 == joaat("sultan2")) { if (!Global_262145.f_27901 && iVar1 < Global_262145.f_27922) { iVar0 = 0; } } else if (iParam0 == joaat("outlaw")) { if (!Global_262145.f_27902 && iVar1 < Global_262145.f_27923) { iVar0 = 0; } } else if (iParam0 == joaat("vagrant")) { if (!Global_262145.f_27903 && iVar1 < Global_262145.f_27924) { iVar0 = 0; } } else if (iParam0 == joaat("komoda")) { if (!Global_262145.f_27904 && iVar1 < Global_262145.f_27925) { iVar0 = 0; } } else if (iParam0 == joaat("stryder")) { if (!Global_262145.f_27905 && iVar1 < Global_262145.f_27926) { iVar0 = 0; } } else if (iParam0 == joaat("furia")) { if (!Global_262145.f_27906 && iVar1 < Global_262145.f_27927) { iVar0 = 0; } } else if (iParam0 == joaat("zhaba")) { if (!Global_262145.f_27907 && iVar1 < Global_262145.f_27928) { iVar0 = 0; } } else if (iParam0 == joaat("jb7002")) { if (!Global_262145.f_27908 && iVar1 < Global_262145.f_27929) { iVar0 = 0; } } else if (iParam0 == joaat("firetruk")) { if (!Global_262145.f_27909 && iVar1 < Global_262145.f_27930) { iVar0 = 0; } } else if (iParam0 == joaat("burrito2")) { if (!Global_262145.f_27910 && iVar1 < Global_262145.f_27931) { iVar0 = 0; } } else if (iParam0 == joaat("boxville")) { if (!Global_262145.f_27911 && iVar1 < Global_262145.f_27932) { iVar0 = 0; } } else if (iParam0 == joaat("stockade")) { if (!Global_262145.f_27912 && iVar1 < Global_262145.f_27933) { iVar0 = 0; } } else if (iParam0 == joaat("minitank")) { if (!Global_262145.f_27913 && iVar1 < Global_262145.f_27934) { iVar0 = 0; } } else if (iParam0 == joaat("lguard")) { if (!Global_262145.f_27914 && iVar1 < Global_262145.f_27935) { iVar0 = 0; } } else if (iParam0 == joaat("blazer2")) { if (!Global_262145.f_27915 && iVar1 < Global_262145.f_27936) { iVar0 = 0; } } else if (iParam0 == joaat("formula")) { if ((!Global_262145.f_27938 && iVar1 < Global_262145.f_27939) && !Global_262145.f_27893) { iVar0 = 0; } } else if (iParam0 == joaat("formula2")) { if ((!Global_262145.f_27941 && iVar1 < Global_262145.f_27942) && !Global_262145.f_27894) { iVar0 = 0; } } else if (iParam0 == joaat("imorgon")) { if (!Global_262145.f_27946 && iVar1 < Global_262145.f_27949) { iVar0 = 0; } } else if (iParam0 == joaat("rebla")) { if (!Global_262145.f_27947 && iVar1 < Global_262145.f_27950) { iVar0 = 0; } } else if (iParam0 == joaat("vstr")) { if (!Global_262145.f_27948 && iVar1 < Global_262145.f_27951) { iVar0 = 0; } } else if (iParam0 == joaat("gauntlet5")) { if (!Global_262145.f_28950 && iVar1 < Global_262145.f_28615) { iVar0 = 0; } } else if (iParam0 == joaat("club")) { if (!Global_262145.f_28601 && iVar1 < Global_262145.f_28622) { iVar0 = 0; } } else if (iParam0 == joaat("dukes3")) { if (!Global_262145.f_28602 && iVar1 < Global_262145.f_28608) { iVar0 = 0; } } else if (iParam0 == joaat("yosemite3")) { if (!Global_262145.f_28948 && iVar1 < Global_262145.f_28616) { iVar0 = 0; } } else if (iParam0 == joaat("peyote3")) { if (!Global_262145.f_28949 && iVar1 < Global_262145.f_28617) { iVar0 = 0; } } else if (iParam0 == joaat("glendale2")) { if (!Global_262145.f_28595 && iVar1 < Global_262145.f_28614) { iVar0 = 0; } } else if (iParam0 == joaat("penumbra2")) { if (!Global_262145.f_28596 && iVar1 < Global_262145.f_28623) { iVar0 = 0; } } else if (iParam0 == joaat("landstalker2")) { if (!Global_262145.f_28597 && iVar1 < Global_262145.f_28613) { iVar0 = 0; } } else if (iParam0 == joaat("seminole2")) { if (!Global_262145.f_28598 && iVar1 < Global_262145.f_28611) { iVar0 = 0; } } else if (iParam0 == joaat("tigon")) { if (!Global_262145.f_28944 && iVar1 < Global_262145.f_28618) { iVar0 = 0; } } else if (iParam0 == joaat("openwheel1")) { if (!Global_262145.f_28945 && iVar1 < Global_262145.f_28619) { iVar0 = 0; } } else if (iParam0 == joaat("openwheel2")) { if (!Global_262145.f_28946 && iVar1 < Global_262145.f_28620) { iVar0 = 0; } } else if (iParam0 == joaat("coquette4")) { if (!Global_262145.f_28947 && iVar1 < Global_262145.f_28621) { iVar0 = 0; } } else if (iParam0 == joaat("manana2")) { if (!Global_262145.f_28599 && iVar1 < Global_262145.f_28610) { iVar0 = 0; } } else if (iParam0 == joaat("youga3")) { if (!Global_262145.f_28600 && iVar1 < Global_262145.f_28612) { iVar0 = 0; } } else if (iParam0 == joaat("toreador")) { if (!Global_262145.f_29392 && iVar1 < Global_262145.f_29375) { iVar0 = 0; } } else if (iParam0 == joaat("annihilator2")) { if (!Global_262145.f_29393 && iVar1 < Global_262145.f_29376) { iVar0 = 0; } } else if (iParam0 == joaat("alkonost")) { if (!Global_262145.f_29394 && iVar1 < Global_262145.f_29377) { iVar0 = 0; } } else if (iParam0 == joaat("patrolboat")) { if (!Global_262145.f_29395 && iVar1 < Global_262145.f_29378) { iVar0 = 0; } } else if (iParam0 == joaat("longfin")) { if (!Global_262145.f_29396 && iVar1 < Global_262145.f_29379) { iVar0 = 0; } } else if (iParam0 == joaat("winky")) { if (!Global_262145.f_29397 && iVar1 < Global_262145.f_29380) { iVar0 = 0; } } else if (iParam0 == joaat("veto")) { if (!Global_262145.f_29398 && iVar1 < Global_262145.f_29381) { iVar0 = 0; } } else if (iParam0 == joaat("veto2")) { if (!Global_262145.f_29399 && iVar1 < Global_262145.f_29382) { iVar0 = 0; } } else if (iParam0 == joaat("italirsx")) { if (!Global_262145.f_29400 && iVar1 < Global_262145.f_29383) { iVar0 = 0; } } else if (iParam0 == joaat("weevil")) { if (Global_262145.f_29409) { } else if (!Global_262145.f_29401 && iVar1 < Global_262145.f_29384) { iVar0 = 0; } } else if (iParam0 == joaat("manchez2")) { if (!Global_262145.f_29402 && iVar1 < Global_262145.f_29385) { iVar0 = 0; } } else if (iParam0 == joaat("slamtruck")) { if (!Global_262145.f_29403 && iVar1 < Global_262145.f_29386) { iVar0 = 0; } } else if (iParam0 == joaat("vetir")) { if (!Global_262145.f_29404 && iVar1 < Global_262145.f_29387) { iVar0 = 0; } } else if (iParam0 == joaat("squaddie")) { if (!Global_262145.f_29405 && iVar1 < Global_262145.f_29388) { iVar0 = 0; } } else if (iParam0 == joaat("brioso2")) { if (Global_262145.f_29410) { } else if (!Global_262145.f_29406 && iVar1 < Global_262145.f_29389) { iVar0 = 0; } } else if (iParam0 == joaat("dinghy5")) { if (!Global_262145.f_29407 && iVar1 < Global_262145.f_29390) { iVar0 = 0; } } else if (iParam0 == joaat("verus")) { if (!Global_262145.f_29408 && iVar1 < Global_262145.f_29391) { iVar0 = 0; } } return iVar0; } int func_17() { return 0; } int func_18() { return 1; } int func_19() { return 1; } int func_20() { if (DLC::IS_DLC_PRESENT(-1226939934)) { return 1; } return 0; } int func_21() { int iVar0; if (NETWORK::NETWORK_IS_SIGNED_IN()) { if (NETWORK::NETWORK_HAS_VALID_ROS_CREDENTIALS()) { if (NETWORK::_NETWORK_GET_ROS_PRIVILEGE_24()) { STATS::STAT_GET_INT(joaat("SP_UNLOCK_EXCLUS_CONTENT"), &iVar0, -1); MISC::SET_BIT(&iVar0, 2); MISC::SET_BIT(&iVar0, 4); MISC::SET_BIT(&iVar0, 6); MISC::SET_BIT(&Global_25, 2); MISC::SET_BIT(&Global_25, 4); MISC::SET_BIT(&Global_25, 6); STATS::STAT_SET_INT(joaat("SP_UNLOCK_EXCLUS_CONTENT"), iVar0, true); if (MISC::ARE_PROFILE_SETTINGS_VALID()) { iVar0 = MISC::GET_PROFILE_SETTING(866); MISC::SET_BIT(&iVar0, 0); STATS::_SET_HAS_CONTENT_UNLOCKS_FLAGS(iVar0); } return 1; } } } if (Global_150693 == 2) { return 1; } else if (Global_150693 == 3) { return 0; } if (MISC::ARE_PROFILE_SETTINGS_VALID()) { if (MISC::IS_BIT_SET(MISC::GET_PROFILE_SETTING(866), 0)) { return 1; } } return 0; } int func_22(int iParam0) { int iVar0; char* sVar1; iVar0 = ENTITY::GET_ENTITY_MODEL(iParam0); sVar1 = VEHICLE::GET_VEHICLE_NUMBER_PLATE_TEXT(iParam0); if (iVar0 == joaat("speedo") && MISC::ARE_STRINGS_EQUAL(sVar1, "LAMAR G ")) { return 1; } if (!func_13(iVar0, 0)) { return 1; } return 0; } int func_23(int iParam0) { int iVar0; iVar0 = 0; while (iVar0 < 3) { if (ENTITY::DOES_ENTITY_EXIST(Global_96316[iVar0])) { if (Global_96316[iVar0] == iParam0) { return 1; } } iVar0++; } return 0; } int func_24(int iParam0) { int iVar0; if (ENTITY::DOES_ENTITY_EXIST(iParam0) && VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) { iVar0 = 0; while (iVar0 < 9) { if (ENTITY::DOES_ENTITY_EXIST(Global_96286[iVar0]) && VEHICLE::IS_VEHICLE_DRIVEABLE(Global_96286[iVar0], false)) { if (Global_96286[iVar0] == iParam0 && ENTITY::GET_ENTITY_MODEL(Global_96286[iVar0]) == ENTITY::GET_ENTITY_MODEL(iParam0)) { return 1; } } iVar0++; } } return 0; } int func_25(int iParam0) { int iVar0; if (ENTITY::DOES_ENTITY_EXIST(Global_75654.f_484[24])) { if (iParam0 == Global_75654.f_484[24]) { return 0; } } iVar0 = 0; while (iVar0 < 68) { if (ENTITY::DOES_ENTITY_EXIST(Global_75654.f_484[iVar0])) { if ((((((((((((iVar0 != 24 && iVar0 != 21) && iVar0 != 22) && iVar0 != 23) && iVar0 != 27) && iVar0 != 30) && iVar0 != 33) && iVar0 != 28) && iVar0 != 31) && iVar0 != 34) && iVar0 != 26) && iVar0 != 29) && iVar0 != 32) { if (iParam0 == Global_75654.f_484[iVar0]) { return 1; } } } iVar0++; } return 0; } int func_26(int iParam0, int iParam1, bool bParam2) { int iVar0; char* sVar1; int iVar9; if (!ENTITY::DOES_ENTITY_EXIST(iParam0) || !VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) { return 0; } iVar0 = 0; while (func_27(iParam1, iVar0, &sVar1, &iVar9)) { if (!bParam2 || MISC::IS_BIT_SET(Global_111858.f_7225[iVar9], 0)) { if (VEHICLE::IS_VEHICLE_IN_GARAGE_AREA(&sVar1, iParam0)) { return 1; } } iVar0++; } return 0; } int func_27(int iParam0, int iParam1, char* sParam2, var uParam3) { StringCopy(sParam2, "", 32); switch (iParam0) { case 0: if (iParam1 == 0) { StringCopy(sParam2, "Michael - Beverly Hills", 32); *uParam3 = 0; return 1; } else if (iParam1 == 1) { StringCopy(sParam2, "Trevor - Countryside", 32); *uParam3 = 1; return 1; } break; case 1: if (iParam1 == 0) { StringCopy(sParam2, "Franklin - Aunt", 32); *uParam3 = 5; return 1; } else if (iParam1 == 1) { StringCopy(sParam2, "Franklin - Hills", 32); *uParam3 = 6; return 1; } break; case 2: if (iParam1 == 0) { StringCopy(sParam2, "Trevor - Countryside", 32); *uParam3 = 2; return 1; } else if (iParam1 == 1) { StringCopy(sParam2, "Trevor - City", 32); *uParam3 = 3; return 1; } else if (iParam1 == 2) { StringCopy(sParam2, "Trevor - Stripclub", 32); *uParam3 = 4; return 1; } break; } return 0; } int func_28(int iParam0) { if (iParam0 == -1) { return 0; } return Global_75654.f_139[iParam0]; } var func_29() { var uVar0; func_39(&uVar0, CLOCK::GET_CLOCK_SECONDS()); func_38(&uVar0, CLOCK::GET_CLOCK_MINUTES()); func_37(&uVar0, CLOCK::GET_CLOCK_HOURS()); func_32(&uVar0, CLOCK::GET_CLOCK_DAY_OF_MONTH()); func_31(&uVar0, CLOCK::GET_CLOCK_MONTH()); func_30(&uVar0, CLOCK::GET_CLOCK_YEAR()); return uVar0; } void func_30(var uParam0, int iParam1) { if (iParam1 <= 0) { return; } if (iParam1 > 2043 || iParam1 < 1979) { return; } *uParam0 = (*uParam0 - *uParam0 & 2080374784); if (iParam1 < 2011) { *uParam0 = (*uParam0 || SYSTEM::SHIFT_LEFT((2011 - iParam1), 26)); *uParam0 |= -2147483648; } else { *uParam0 = (*uParam0 || SYSTEM::SHIFT_LEFT((iParam1 - 2011), 26)); *uParam0 = (*uParam0 - *uParam0 & -2147483648); } } void func_31(var uParam0, int iParam1) { if (iParam1 < 0 || iParam1 > 11) { return; } *uParam0 = (*uParam0 - *uParam0 & 15); *uParam0 = (*uParam0 || iParam1); } void func_32(var uParam0, int iParam1) { int iVar0; int iVar1; iVar0 = func_36(*uParam0); iVar1 = func_34(*uParam0); if (iParam1 < 1 || iParam1 > func_33(iVar0, iVar1)) { return; } *uParam0 = (*uParam0 - *uParam0 & 496); *uParam0 = (*uParam0 || SYSTEM::SHIFT_LEFT(iParam1, 4)); } int func_33(int iParam0, int iParam1) { if (iParam1 < 0) { iParam1 = 0; } switch (iParam0) { case 0: case 2: case 4: case 6: case 7: case 9: case 11: return 31; break; case 3: case 5: case 8: case 10: return 30; break; case 1: if ((iParam1 % 4) == 0) { if ((iParam1 % 100) != 0) { return 29; } else if ((iParam1 % 400) == 0) { return 29; } } return 28; break; } return 30; } var func_34(int iParam0) { return (SYSTEM::SHIFT_RIGHT(iParam0, 26) & 31 * func_35(MISC::IS_BIT_SET(iParam0, 31), -1, 1)) + 2011; } int func_35(bool bParam0, int iParam1, int iParam2) { if (bParam0) { return iParam1; } return iParam2; } int func_36(var uParam0) { return uParam0 & 15; } void func_37(var uParam0, int iParam1) { if (iParam1 < 0 || iParam1 > 24) { return; } *uParam0 = (*uParam0 - *uParam0 & 15872); *uParam0 = (*uParam0 || SYSTEM::SHIFT_LEFT(iParam1, 9)); } void func_38(var uParam0, int iParam1) { if (iParam1 < 0 || iParam1 >= 60) { return; } *uParam0 = (*uParam0 - *uParam0 & 1032192); *uParam0 = (*uParam0 || SYSTEM::SHIFT_LEFT(iParam1, 14)); } void func_39(var uParam0, int iParam1) { if (iParam1 < 0 || iParam1 >= 60) { return; } *uParam0 = (*uParam0 - *uParam0 & 66060288); *uParam0 = (*uParam0 || SYSTEM::SHIFT_LEFT(iParam1, 20)); } int func_40(var uParam0, int iParam1) { int iVar0; int iVar1; *uParam0 = { 0f, 0f, 0f }; uParam0->f_3 = 0f; uParam0->f_4 = 0; StringCopy(&(uParam0->f_5), "", 16); uParam0->f_9 = 0; uParam0->f_10 = 0; uParam0->f_11 = 0; uParam0->f_12 = 145; uParam0->f_13 = -1; uParam0->f_14 = 0; uParam0->f_15 = { 0f, 0f, 0f }; uParam0->f_18 = { 0f, 0f, 0f }; switch (iParam1) { case 0: *uParam0 = { -831.8538f, 172.1154f, 69.9058f }; uParam0->f_3 = 157.5705f; uParam0->f_4 = func_41(0, 1); uParam0->f_12 = 0; MISC::SET_BIT(&(uParam0->f_9), 20); MISC::SET_BIT(&(uParam0->f_9), 7); iVar0 = 1; break; case 1: *uParam0 = { 1970.943f, 3801.684f, 31.1396f }; uParam0->f_3 = 301.3964f; uParam0->f_4 = func_41(0, 1); uParam0->f_12 = 0; MISC::SET_BIT(&(uParam0->f_9), 20); MISC::SET_BIT(&(uParam0->f_9), 7); iVar0 = 1; break; case 2: *uParam0 = { -22.6297f, -1439.137f, 29.6549f }; uParam0->f_3 = 180.0808f; uParam0->f_4 = func_41(1, 1); uParam0->f_12 = 1; MISC::SET_BIT(&(uParam0->f_9), 20); MISC::SET_BIT(&(uParam0->f_9), 7); iVar0 = 1; break; case 3: *uParam0 = { -22.5229f, -1434.699f, 29.6552f }; uParam0->f_3 = 141.6114f; uParam0->f_4 = func_41(1, 2); uParam0->f_12 = 1; MISC::SET_BIT(&(uParam0->f_9), 19); MISC::SET_BIT(&(uParam0->f_9), 7); iVar0 = 1; break; case 4: *uParam0 = { 10.9281f, 545.669f, 174.7951f }; uParam0->f_3 = 61.392f; uParam0->f_4 = func_41(1, 1); uParam0->f_12 = 1; MISC::SET_BIT(&(uParam0->f_9), 20); MISC::SET_BIT(&(uParam0->f_9), 7); iVar0 = 1; break; case 5: *uParam0 = { 6.1093f, 544.9742f, 174.2835f }; uParam0->f_3 = 92.1548f; uParam0->f_4 = func_41(1, 2); uParam0->f_12 = 1; MISC::SET_BIT(&(uParam0->f_9), 19); MISC::SET_BIT(&(uParam0->f_9), 7); iVar0 = 1; break; case 6: *uParam0 = { 1981.416f, 3808.131f, 31.1384f }; uParam0->f_3 = 117.2557f; uParam0->f_4 = func_41(2, 1); uParam0->f_12 = 2; MISC::SET_BIT(&(uParam0->f_9), 20); MISC::SET_BIT(&(uParam0->f_9), 7); iVar0 = 1; break; case 7: *uParam0 = { -1158.488f, -1529.367f, 3.8995f }; uParam0->f_3 = 35.7505f; uParam0->f_4 = func_41(2, 1); uParam0->f_12 = 2; MISC::SET_BIT(&(uParam0->f_9), 20); MISC::SET_BIT(&(uParam0->f_9), 7); iVar0 = 1; break; case 8: *uParam0 = { 148.2868f, -1270.569f, 28.2252f }; uParam0->f_3 = 208.4685f; uParam0->f_4 = func_41(2, 1); uParam0->f_12 = 2; MISC::SET_BIT(&(uParam0->f_9), 20); MISC::SET_BIT(&(uParam0->f_9), 7); iVar0 = 1; break; case 9: *uParam0 = { 1459.509f, -1380.45f, 78.3259f }; uParam0->f_3 = 99.6211f; uParam0->f_4 = joaat("scorcher"); MISC::SET_BIT(&(uParam0->f_9), 6); iVar0 = 1; break; case 10: *uParam0 = { -1518.947f, -1387.865f, -0.5134f }; uParam0->f_3 = 98.3867f; uParam0->f_4 = joaat("seashark"); iVar0 = 1; MISC::SET_BIT(&(uParam0->f_9), 6); break; case 11: *uParam0 = { 353.0926f, 3577.593f, 32.351f }; uParam0->f_3 = 16.6205f; uParam0->f_4 = joaat("duster"); iVar0 = 1; MISC::SET_BIT(&(uParam0->f_9), 6); break; case 12: uParam0->f_14 = 0; *uParam0 = { -1652.004f, -3142.348f, 12.9921f }; uParam0->f_3 = 329.1082f; uParam0->f_12 = 0; uParam0->f_13 = 359; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 28); iVar0 = 1; break; case 13: uParam0->f_14 = 1; *uParam0 = { -1271.649f, -3380.685f, 12.9451f }; uParam0->f_3 = 329.5137f; uParam0->f_12 = 1; uParam0->f_13 = 359; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 28); iVar0 = 1; break; case 14: uParam0->f_14 = 2; *uParam0 = { 1735.586f, 3294.531f, 40.1651f }; uParam0->f_3 = 194.9525f; uParam0->f_12 = 2; uParam0->f_13 = 359; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 28); iVar0 = 1; break; case 15: uParam0->f_14 = 3; *uParam0 = { -846.27f, -1363.19f, 0.22f }; uParam0->f_3 = 108.78f; uParam0->f_12 = 0; uParam0->f_13 = 356; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 22); MISC::SET_BIT(&(uParam0->f_9), 28); iVar0 = 1; break; case 16: uParam0->f_14 = 4; *uParam0 = { -849.47f, -1354.99f, 0.24f }; uParam0->f_3 = 109.84f; uParam0->f_12 = 1; uParam0->f_13 = 356; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 22); MISC::SET_BIT(&(uParam0->f_9), 28); iVar0 = 1; break; case 17: uParam0->f_14 = 5; *uParam0 = { -852.47f, -1346.2f, 0.21f }; uParam0->f_3 = 108.76f; uParam0->f_12 = 2; uParam0->f_13 = 356; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 22); MISC::SET_BIT(&(uParam0->f_9), 28); iVar0 = 1; break; case 18: uParam0->f_14 = 6; *uParam0 = { -745.857f, -1433.904f, 4.0005f }; uParam0->f_12 = 0; uParam0->f_13 = 360; uParam0->f_15 = { -756.2952f, -1441.609f, 2.9184f }; uParam0->f_18 = { -738.0606f, -1423.068f, 8.2835f }; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 28); iVar0 = 1; break; case 19: uParam0->f_14 = 7; *uParam0 = { -761.8486f, -1453.829f, 4.0005f }; uParam0->f_12 = 1; uParam0->f_13 = 360; uParam0->f_15 = { -772.8158f, -1459.957f, 3.2894f }; uParam0->f_18 = { -754.3353f, -1440.836f, 8.3334f }; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 28); iVar0 = 1; break; case 20: uParam0->f_14 = 8; *uParam0 = { 1769.3f, 3244f, 41.1f }; uParam0->f_12 = 2; uParam0->f_13 = 360; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 23); MISC::SET_BIT(&(uParam0->f_9), 28); iVar0 = 1; break; case 21: uParam0->f_14 = 9; *uParam0 = { 192.7897f, -1020.539f, -99.98f }; uParam0->f_3 = 180f; uParam0->f_4 = 0; uParam0->f_12 = 0; uParam0->f_13 = 357; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 24); MISC::SET_BIT(&(uParam0->f_9), 28); MISC::SET_BIT(&(uParam0->f_9), 29); iVar0 = 1; break; case 22: uParam0->f_14 = 10; *uParam0 = { 192.7897f, -1020.539f, -99.98f }; uParam0->f_3 = 180f; uParam0->f_4 = 0; uParam0->f_12 = 1; uParam0->f_13 = 357; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 24); MISC::SET_BIT(&(uParam0->f_9), 28); MISC::SET_BIT(&(uParam0->f_9), 29); iVar0 = 1; break; case 23: uParam0->f_14 = 11; *uParam0 = { 192.7897f, -1020.539f, -99.98f }; uParam0->f_3 = 180f; uParam0->f_4 = 0; uParam0->f_12 = 2; uParam0->f_13 = 357; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 14); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 24); MISC::SET_BIT(&(uParam0->f_9), 28); MISC::SET_BIT(&(uParam0->f_9), 29); iVar0 = 1; break; case 26: case 27: case 28: iVar1 = (iParam1 - 26); uParam0->f_14 = (12 + iVar1); *uParam0 = { 196.2794f, -1020.479f, -99.98f }; uParam0->f_3 = 180f; uParam0->f_4 = 0; uParam0->f_12 = (0 + iVar1); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 27); MISC::SET_BIT(&(uParam0->f_9), 24); MISC::SET_BIT(&(uParam0->f_9), 29); iVar0 = 1; break; case 29: case 30: case 31: iVar1 = (iParam1 - 29); uParam0->f_14 = (15 + iVar1); *uParam0 = { 199.8872f, -1020.048f, -99.98f }; uParam0->f_3 = 180f; uParam0->f_4 = 0; uParam0->f_12 = (0 + iVar1); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 27); MISC::SET_BIT(&(uParam0->f_9), 24); MISC::SET_BIT(&(uParam0->f_9), 29); iVar0 = 1; break; case 32: case 33: case 34: iVar1 = (iParam1 - 32); uParam0->f_14 = (18 + iVar1); *uParam0 = { 203.6006f, -1019.776f, -99.98f }; uParam0->f_3 = 180f; uParam0->f_4 = 0; uParam0->f_12 = (0 + iVar1); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 12); MISC::SET_BIT(&(uParam0->f_9), 7); MISC::SET_BIT(&(uParam0->f_9), 27); MISC::SET_BIT(&(uParam0->f_9), 24); MISC::SET_BIT(&(uParam0->f_9), 29); iVar0 = 1; break; case 24: uParam0->f_14 = 21; *uParam0 = { 0f, 0f, 0f }; uParam0->f_3 = 0f; uParam0->f_4 = 0; MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 11); MISC::SET_BIT(&(uParam0->f_9), 13); MISC::SET_BIT(&(uParam0->f_9), 12); iVar0 = 1; break; case 25: uParam0->f_14 = 22; *uParam0 = { 723.2515f, -632.0496f, 27.1484f }; uParam0->f_3 = 12.9316f; uParam0->f_4 = joaat("tailgater"); MISC::SET_BIT(&(uParam0->f_9), 10); MISC::SET_BIT(&(uParam0->f_9), 11); MISC::SET_BIT(&(uParam0->f_9), 13); MISC::SET_BIT(&(uParam0->f_9), 12); iVar0 = 1; break; case 35: *uParam0 = { -51.23f, 3111.9f, 24.95f }; uParam0->f_3 = 46.78f; uParam0->f_4 = joaat("proptrailer"); MISC::SET_BIT(&(uParam0->f_9), 8); iVar0 = 1; break; case 36: *uParam0 = { -55.7984f, -1096.586f, 25.4223f }; uParam0->f_3 = 308.0596f; uParam0->f_4 = joaat("bjxl"); uParam0->f_10 = 126; uParam0->f_11 = 126; MISC::SET_BIT(&(uParam0->f_9), 9); MISC::SET_BIT(&(uParam0->f_9), 13); iVar0 = 1; break; case 37: *uParam0 = { -2892.93f, 3192.37f, 11.66f }; uParam0->f_3 = -132.35f; uParam0->f_4 = joaat("velum"); uParam0->f_10 = 157; uParam0->f_11 = 157; MISC::SET_BIT(&(uParam0->f_9), 9); MISC::SET_BIT(&(uParam0->f_9), 23); MISC::SET_BIT(&(uParam0->f_9), 13); iVar0 = 1; break; case 38: *uParam0 = { 1744.308f, 3270.673f, 40.2076f }; uParam0->f_3 = 125f; uParam0->f_4 = joaat("cargobob3"); MISC::SET_BIT(&(uParam0->f_9), 23); MISC::SET_BIT(&(uParam0->f_9), 8); iVar0 = 1; break; case 39: *uParam0 = { 1751.44f, 3322.643f, 42.1855f }; uParam0->f_3 = 268.134f; uParam0->f_4 = joaat("submersible"); MISC::SET_BIT(&(uParam0->f_9), 23); iVar0 = 1; break; case 41: *uParam0 = { 1377.104f, -2076.2f, 52f }; uParam0->f_3 = 37.5f; uParam0->f_4 = joaat("towtruck"); MISC::SET_BIT(&(uParam0->f_9), 8); iVar0 = 1; break; case 40: *uParam0 = { 1380.42f, -2072.77f, 51.7607f }; uParam0->f_3 = 37.5f; uParam0->f_4 = joaat("trash"); MISC::SET_BIT(&(uParam0->f_9), 8); iVar0 = 1; break; case 42: *uParam0 = { 1359.389f, 3618.441f, 33.8907f }; uParam0->f_3 = 108.2337f; uParam0->f_4 = joaat("barracks"); MISC::SET_BIT(&(uParam0->f_9), 8); iVar0 = 1; break; case 43: *uParam0 = { 693.1154f, -1018.155f, 21.6387f }; uParam0->f_3 = 177.6454f; uParam0->f_4 = joaat("firetruk"); MISC::SET_BIT(&(uParam0->f_9), 23); MISC::SET_BIT(&(uParam0->f_9), 8); iVar0 = 1; break; case 44: *uParam0 = { -73.6963f, 495.124f, 143.5226f }; uParam0->f_3 = 155.5994f; uParam0->f_4 = joaat("vacca"); iVar0 = 1; break; case 45: *uParam0 = { -67.6314f, 891.8266f, 234.5348f }; uParam0->f_3 = 294.993f; uParam0->f_4 = joaat("surano"); iVar0 = 1; break; case 46: *uParam0 = { 533.9048f, -169.2469f, 53.7005f }; uParam0->f_3 = 1.2998f; uParam0->f_4 = joaat("tornado2"); iVar0 = 1; break; case 47: *uParam0 = { -726.8914f, -408.6952f, 34.0416f }; uParam0->f_3 = 267.7392f; uParam0->f_4 = joaat("superd"); iVar0 = 1; break; case 48: *uParam0 = { -1321.519f, 261.3993f, 61.5709f }; uParam0->f_3 = 350.7697f; uParam0->f_4 = joaat("double"); iVar0 = 1; break; case 49: *uParam0 = { -1267.999f, 451.6463f, 93.7071f }; uParam0->f_3 = 48.9311f; uParam0->f_4 = joaat("double"); iVar0 = 1; break; case 50: *uParam0 = { -1062.076f, -226.7637f, 37.157f }; uParam0->f_3 = 234.2767f; uParam0->f_4 = joaat("double"); iVar0 = 1; break; case 51: *uParam0 = { 68.16914f, -1558.958f, 29.46904f }; uParam0->f_3 = 49.90575f; uParam0->f_4 = joaat("rumpo2"); uParam0->f_12 = 2; MISC::SET_BIT(&(uParam0->f_9), 26); iVar0 = 1; break; case 52: *uParam0 = { 589.4399f, 2736.708f, 42.03316f }; uParam0->f_3 = -175.7105f; uParam0->f_4 = joaat("rumpo2"); uParam0->f_12 = 2; MISC::SET_BIT(&(uParam0->f_9), 26); iVar0 = 1; break; case 53: *uParam0 = { -488.774f, -344.5721f, 34.36356f }; uParam0->f_3 = 82.4042f; uParam0->f_4 = joaat("rumpo2"); uParam0->f_12 = 2; MISC::SET_BIT(&(uParam0->f_9), 26); iVar0 = 1; break; case 54: *uParam0 = { 288.8808f, -585.4728f, 43.15428f }; uParam0->f_3 = -20.80707f; uParam0->f_4 = joaat("rumpo2"); uParam0->f_12 = 2; MISC::SET_BIT(&(uParam0->f_9), 26); iVar0 = 1; break; case 55: *uParam0 = { 304.8294f, -1383.674f, 31.67744f }; uParam0->f_3 = -41.11603f; uParam0->f_4 = joaat("rumpo2"); uParam0->f_12 = 2; MISC::SET_BIT(&(uParam0->f_9), 26); iVar0 = 1; break; case 56: *uParam0 = { 1126.194f, -1481.486f, 34.7016f }; uParam0->f_3 = -91.43369f; uParam0->f_4 = joaat("rumpo2"); uParam0->f_12 = 2; MISC::SET_BIT(&(uParam0->f_9), 26); iVar0 = 1; break; case 57: *uParam0 = { -1598.36f, 5252.84f, 0f }; uParam0->f_3 = 28.14f; uParam0->f_4 = joaat("submersible"); uParam0->f_13 = 308; MISC::SET_BIT(&(uParam0->f_9), 2); MISC::SET_BIT(&(uParam0->f_9), 30); MISC::SET_BIT(&(uParam0->f_9), 6); iVar0 = 1; break; case 58: *uParam0 = { -1602.62f, 5260.37f, 0.86f }; uParam0->f_3 = 25.32f; uParam0->f_4 = joaat("dinghy"); uParam0->f_13 = 404; MISC::SET_BIT(&(uParam0->f_9), 2); MISC::SET_BIT(&(uParam0->f_9), 22); MISC::SET_BIT(&(uParam0->f_9), 6); iVar0 = 1; break; case 59: *uParam0 = { 2116.571f, 4763.279f, 40.1596f }; uParam0->f_3 = 198.723f; uParam0->f_4 = joaat("bfinjection"); iVar0 = 1; break; case 60: *uParam0 = { 1133.21f, 120.2f, 80.9f }; uParam0->f_3 = 134.4f; if (func_21()) { uParam0->f_4 = joaat("blimp2"); } else { uParam0->f_4 = joaat("blimp"); } uParam0->f_13 = 401; MISC::SET_BIT(&(uParam0->f_9), 13); MISC::SET_BIT(&(uParam0->f_9), 2); MISC::SET_BIT(&(uParam0->f_9), 1); MISC::SET_BIT(&(uParam0->f_9), 23); MISC::SET_BIT(&(uParam0->f_9), 21); iVar0 = 1; break; case 61: *uParam0 = { -806.31f, -2679.65f, 13.9f }; uParam0->f_3 = 150.54f; if (func_21()) { uParam0->f_4 = joaat("blimp2"); } else { uParam0->f_4 = joaat("blimp"); } uParam0->f_13 = 401; MISC::SET_BIT(&(uParam0->f_9), 13); MISC::SET_BIT(&(uParam0->f_9), 2); MISC::SET_BIT(&(uParam0->f_9), 1); MISC::SET_BIT(&(uParam0->f_9), 23); MISC::SET_BIT(&(uParam0->f_9), 21); iVar0 = 1; break; case 62: *uParam0 = { 1985.85f, 3828.96f, 31.98f }; uParam0->f_3 = -16.58f; uParam0->f_4 = joaat("blazer3"); MISC::SET_BIT(&(uParam0->f_9), 6); iVar0 = 1; break; case 63: *uParam0 = { 3870.75f, 4464.67f, 0f }; uParam0->f_3 = 0f; uParam0->f_4 = joaat("submersible2"); uParam0->f_13 = 308; MISC::SET_BIT(&(uParam0->f_9), 0); MISC::SET_BIT(&(uParam0->f_9), 21); MISC::SET_BIT(&(uParam0->f_9), 23); MISC::SET_BIT(&(uParam0->f_9), 6); MISC::SET_BIT(&(uParam0->f_9), 30); iVar0 = 1; break; case 64: *uParam0 = { 1257.729f, -2564.474f, 41.717f }; uParam0->f_3 = 284.5561f; uParam0->f_4 = joaat("dukes2"); MISC::SET_BIT(&(uParam0->f_9), 6); iVar0 = 1; break; case 65: *uParam0 = { 643.2823f, 3014.152f, 42.2733f }; uParam0->f_3 = 128.0554f; uParam0->f_4 = joaat("dukes2"); MISC::SET_BIT(&(uParam0->f_9), 6); iVar0 = 1; break; case 66: *uParam0 = { 38.9368f, 850.8677f, 196.3f }; uParam0->f_3 = 311.6813f; uParam0->f_4 = joaat("dodo"); MISC::SET_BIT(&(uParam0->f_9), 30); MISC::SET_BIT(&(uParam0->f_9), 23); MISC::SET_BIT(&(uParam0->f_9), 6); iVar0 = 1; break; case 67: *uParam0 = { 1333.875f, 4262.226f, 30.78f }; uParam0->f_3 = 262.5293f; uParam0->f_4 = joaat("dodo"); MISC::SET_BIT(&(uParam0->f_9), 30); MISC::SET_BIT(&(uParam0->f_9), 23); MISC::SET_BIT(&(uParam0->f_9), 6); iVar0 = 1; break; } if (MISC::IS_BIT_SET(uParam0->f_9, 10)) { uParam0->f_4 = Global_111858.f_32745.f_69[uParam0->f_14 /*78*/].f_66; if (iParam1 == 14) { if (((((uParam0->f_4 == joaat("miljet") || uParam0->f_4 == joaat("besra")) || uParam0->f_4 == joaat("luxor")) || uParam0->f_4 == joaat("shamal")) || uParam0->f_4 == joaat("titan")) || uParam0->f_4 == joaat("luxor2")) { *uParam0 = { 1678.8f, 3229.6f, 41.8f }; uParam0->f_3 = 106.0906f; } } if (!func_50(Global_111858.f_32745.f_1864[uParam0->f_14 /*3*/], 0f, 0f, 0f, 0)) { *uParam0 = { Global_111858.f_32745.f_1864[uParam0->f_14 /*3*/] }; } if (Global_111858.f_32745.f_1934[uParam0->f_14] != -1f) { uParam0->f_3 = Global_111858.f_32745.f_1934[uParam0->f_14]; } } if (MISC::IS_BIT_SET(uParam0->f_9, 19)) { if (!func_50(Global_111858.f_2359.f_539.f_3588[1 /*10*/][uParam0->f_12 /*3*/], 0f, 0f, 0f, 0)) { *uParam0 = { Global_111858.f_2359.f_539.f_3588[1 /*10*/][uParam0->f_12 /*3*/] }; uParam0->f_3 = Global_111858.f_2359.f_539.f_3609[1 /*4*/][uParam0->f_12]; } } else if (MISC::IS_BIT_SET(uParam0->f_9, 20)) { if (!func_50(Global_111858.f_2359.f_539.f_3588[0 /*10*/][uParam0->f_12 /*3*/], 0f, 0f, 0f, 0)) { *uParam0 = { Global_111858.f_2359.f_539.f_3588[0 /*10*/][uParam0->f_12 /*3*/] }; uParam0->f_3 = Global_111858.f_2359.f_539.f_3609[0 /*4*/][uParam0->f_12]; } } return iVar0; } int func_41(int iParam0, int iParam1) { struct<82> Var0; if (func_2(iParam0)) { Var0.f_11 = 12; Var0.f_31 = 49; Var0.f_81 = 2; func_42(iParam0, &Var0, iParam1); return Var0; } else if (iParam0 != 145) { } return 0; } void func_42(int iParam0, var uParam1, int iParam2) { int iVar0; uParam1->f_88 = 1; uParam1->f_84 = 255; uParam1->f_85 = 255; uParam1->f_86 = 255; uParam1->f_97 = 1; uParam1->f_3 = 1000; uParam1->f_1 = 0; switch (iParam0) { case 0: iVar0 = joaat("tailgater"); if (Global_111858.f_9081.f_99.f_58[128] && !Global_111858.f_9081.f_99.f_58[131]) { iVar0 = joaat("premier"); } switch (iVar0) { case joaat("tailgater"): *uParam1 = iVar0; uParam1->f_2 = 3f; uParam1->f_4 = 0; uParam1->f_9 = 1; uParam1->f_11[0] = 1; StringCopy(&(uParam1->f_27), "5MDS003", 16); break; case joaat("premier"): *uParam1 = iVar0; uParam1->f_2 = 14.9f; uParam1->f_5 = 43; uParam1->f_6 = 43; uParam1->f_7 = 0; uParam1->f_8 = 156; uParam1->f_9 = 0; StringCopy(&(uParam1->f_27), "880HS955", 16); break; } break; case 2: iVar0 = joaat("bodhi2"); switch (iVar0) { case joaat("bodhi2"): *uParam1 = iVar0; uParam1->f_2 = 14f; uParam1->f_5 = 32; uParam1->f_6 = 0; uParam1->f_7 = 0; uParam1->f_8 = 156; StringCopy(&(uParam1->f_27), "BETTY 32", 16); if (Global_111858.f_9081.f_99.f_58[119]) { uParam1->f_11[1] = 1; } break; } break; case 1: if (iParam2 == 1) { iVar0 = joaat("buffalo2"); } else if (iParam2 == 2) { iVar0 = joaat("bagger"); } else if (Global_111858.f_9081.f_99.f_58[118]) { iVar0 = joaat("bagger"); } else { iVar0 = joaat("buffalo2"); } switch (iVar0) { case joaat("bagger"): *uParam1 = iVar0; uParam1->f_2 = 6f; uParam1->f_5 = 53; uParam1->f_6 = 0; uParam1->f_7 = 59; uParam1->f_8 = 156; StringCopy(&(uParam1->f_27), "FC88", 16); break; case joaat("buffalo2"): *uParam1 = iVar0; uParam1->f_2 = 0f; uParam1->f_5 = 111; uParam1->f_6 = 111; uParam1->f_7 = 0; uParam1->f_8 = 156; uParam1->f_10 = 1; StringCopy(&(uParam1->f_27), "FC1988", 16); uParam1->f_11[0] = 1; uParam1->f_11[1] = 1; uParam1->f_11[2] = 1; uParam1->f_11[3] = 1; uParam1->f_11[4] = 1; uParam1->f_11[5] = 1; uParam1->f_11[6] = 1; uParam1->f_11[7] = 1; uParam1->f_11[8] = 1; break; } break; default: break; } } void func_43(int iParam0, var uParam1, struct<3> Param2, float fParam5, int iParam6) { if (func_40(&(Global_75654.f_555[0 /*21*/]), iParam0)) { if (MISC::IS_BIT_SET(Global_75654.f_555[0 /*21*/].f_9, 10)) { func_48(iParam0); func_47(uParam1, &(Global_111858.f_32745.f_69[Global_75654.f_555[0 /*21*/].f_14 /*78*/])); if (MISC::IS_BIT_SET(Global_75654.f_555[0 /*21*/].f_9, 11)) { Global_111858.f_32745.f_1864[Global_75654.f_555[0 /*21*/].f_14 /*3*/] = { Param2 }; Global_111858.f_32745.f_1934[Global_75654.f_555[0 /*21*/].f_14] = fParam5; } else { Global_111858.f_32745.f_1864[Global_75654.f_555[0 /*21*/].f_14 /*3*/] = { 0f, 0f, 0f }; Global_111858.f_32745.f_1934[Global_75654.f_555[0 /*21*/].f_14] = -1f; } Global_111858.f_32745.f_1958[Global_75654.f_555[0 /*21*/].f_14] = iParam6 + 1; func_44(iParam0, 1); } } } void func_44(int iParam0, bool bParam1) { if (iParam0 == -1) { return; } if (bParam1) { if (!func_46(iParam0, 0)) { func_45(iParam0, 1, 0); func_45(iParam0, 2, 0); func_45(iParam0, 3, 0); func_45(iParam0, 4, 0); func_45(iParam0, 0, 1); Global_75654[iParam0] = 1; } } else { func_45(iParam0, 0, 0); } } void func_45(int iParam0, int iParam1, bool bParam2) { if (iParam0 == -1) { return; } if (bParam2) { MISC::SET_BIT(&(Global_111858.f_32745[iParam0]), iParam1); } else { MISC::CLEAR_BIT(&(Global_111858.f_32745[iParam0]), iParam1); } } bool func_46(int iParam0, int iParam1) { if (iParam0 == -1) { return 0; } return MISC::IS_BIT_SET(Global_111858.f_32745[iParam0], iParam1); } void func_47(var uParam0, var uParam1) { uParam1->f_66 = uParam0->f_66; *uParam1 = *uParam0; uParam1->f_1 = { uParam0->f_1 }; uParam1->f_5 = uParam0->f_5; uParam1->f_6 = uParam0->f_6; uParam1->f_7 = uParam0->f_7; uParam1->f_8 = uParam0->f_8; uParam1->f_9 = { uParam0->f_9 }; uParam1->f_59 = { uParam0->f_59 }; uParam1->f_62 = uParam0->f_62; uParam1->f_63 = uParam0->f_63; uParam1->f_64 = uParam0->f_64; uParam1->f_65 = uParam0->f_65; uParam1->f_77 = uParam0->f_77; uParam1->f_67 = uParam0->f_67; uParam1->f_69 = uParam0->f_69; uParam1->f_68 = uParam0->f_68; uParam1->f_71 = uParam0->f_71; uParam1->f_72 = uParam0->f_72; uParam1->f_73 = uParam0->f_73; uParam1->f_74 = uParam0->f_74; uParam1->f_75 = uParam0->f_75; uParam1->f_76 = uParam0->f_76; } void func_48(int iParam0) { if (iParam0 == -1) { return; } if (func_40(&(Global_75654.f_555[0 /*21*/]), iParam0)) { if (ENTITY::DOES_ENTITY_EXIST(Global_75654.f_139[iParam0])) { ENTITY::SET_ENTITY_AS_MISSION_ENTITY(Global_75654.f_139[iParam0], true, true); ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&(Global_75654.f_139[iParam0])); Global_75654.f_139[iParam0] = 0; } if (MISC::IS_BIT_SET(Global_75654.f_555[0 /*21*/].f_9, 13)) { func_44(iParam0, 0); } } } int func_49(int iParam0) { int iVar0; if (!ENTITY::DOES_ENTITY_EXIST(iParam0)) { return 145; } if (!VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) { return 145; } iVar0 = 0; while (iVar0 < 9) { if (ENTITY::DOES_ENTITY_EXIST(Global_96286[iVar0])) { if (Global_96286[iVar0] == iParam0) { return Global_96296[iVar0]; } } iVar0++; } return 145; } bool func_50(struct<3> Param0, struct<3> Param3, bool bParam6) { if (bParam6) { return (Param0.x == Param3.x && Param0.f_1 == Param3.f_1); } return ((Param0.x == Param3.x && Param0.f_1 == Param3.f_1) && Param0.f_2 == Param3.f_2); } void func_51(int iParam0, var uParam1) { int iVar0; if (VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) { func_55(uParam1); uParam1->f_66 = ENTITY::GET_ENTITY_MODEL(iParam0); StringCopy(&(uParam1->f_1), VEHICLE::GET_VEHICLE_NUMBER_PLATE_TEXT(iParam0), 16); *uParam1 = VEHICLE::GET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(iParam0); VEHICLE::GET_VEHICLE_COLOURS(iParam0, &(uParam1->f_5), &(uParam1->f_6)); VEHICLE::GET_VEHICLE_EXTRA_COLOURS(iParam0, &(uParam1->f_7), &(uParam1->f_8)); VEHICLE::GET_VEHICLE_TYRE_SMOKE_COLOR(iParam0, &(uParam1->f_62), &(uParam1->f_63), &(uParam1->f_64)); uParam1->f_65 = VEHICLE::GET_VEHICLE_WINDOW_TINT(iParam0); uParam1->f_67 = VEHICLE::GET_VEHICLE_LIVERY(iParam0); uParam1->f_69 = VEHICLE::GET_VEHICLE_WHEEL_TYPE(iParam0); uParam1->f_70 = VEHICLE::GET_VEHICLE_DOOR_LOCK_STATUS(iParam0); VEHICLE::GET_VEHICLE_CUSTOM_SECONDARY_COLOUR(iParam0, &(uParam1->f_71), &(uParam1->f_72), &(uParam1->f_73)); VEHICLE::_GET_VEHICLE_NEON_LIGHTS_COLOUR(iParam0, &(uParam1->f_74), &(uParam1->f_75), &(uParam1->f_76)); if (VEHICLE::_IS_VEHICLE_NEON_LIGHT_ENABLED(iParam0, 2)) { MISC::SET_BIT(&(uParam1->f_77), 28); } if (VEHICLE::_IS_VEHICLE_NEON_LIGHT_ENABLED(iParam0, 3)) { MISC::SET_BIT(&(uParam1->f_77), 29); } if (VEHICLE::_IS_VEHICLE_NEON_LIGHT_ENABLED(iParam0, 0)) { MISC::SET_BIT(&(uParam1->f_77), 30); } if (VEHICLE::_IS_VEHICLE_NEON_LIGHT_ENABLED(iParam0, 1)) { MISC::SET_BIT(&(uParam1->f_77), 31); } if (uParam1->f_65 == -1 && !func_54(uParam1->f_66)) { uParam1->f_65 = 0; } if (VEHICLE::IS_VEHICLE_A_CONVERTIBLE(iParam0, false)) { uParam1->f_68 = VEHICLE::GET_CONVERTIBLE_ROOF_STATE(iParam0); } if (VEHICLE::IS_THIS_MODEL_A_PLANE(uParam1->f_66)) { if (VEHICLE::IS_PLANE_LANDING_GEAR_INTACT(iParam0)) { switch (VEHICLE::GET_LANDING_GEAR_STATE(iParam0)) { case 3: case 0: MISC::CLEAR_BIT(&(uParam1->f_77), 23); MISC::SET_BIT(&(uParam1->f_77), 22); break; case 4: case 1: MISC::CLEAR_BIT(&(uParam1->f_77), 23); MISC::CLEAR_BIT(&(uParam1->f_77), 22); break; case 5: MISC::SET_BIT(&(uParam1->f_77), 23); break; } } else { MISC::SET_BIT(&(uParam1->f_77), 23); } } if (!VEHICLE::GET_VEHICLE_TYRES_CAN_BURST(iParam0)) { MISC::SET_BIT(&(uParam1->f_77), 9); } if (VEHICLE::IS_VEHICLE_STOLEN(iParam0)) { MISC::SET_BIT(&(uParam1->f_77), 10); } if (VEHICLE::GET_IS_VEHICLE_PRIMARY_COLOUR_CUSTOM(iParam0)) { MISC::SET_BIT(&(uParam1->f_77), 13); VEHICLE::GET_VEHICLE_CUSTOM_PRIMARY_COLOUR(iParam0, &(uParam1->f_71), &(uParam1->f_72), &(uParam1->f_73)); } if (VEHICLE::GET_IS_VEHICLE_SECONDARY_COLOUR_CUSTOM(iParam0)) { MISC::SET_BIT(&(uParam1->f_77), 12); } func_53(&iParam0, &(uParam1->f_9), &(uParam1->f_59)); iVar0 = 0; while (iVar0 <= 11) { if (VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(iParam0, iVar0 + 1)) { MISC::SET_BIT(&(uParam1->f_77), func_52(iVar0 + 1)); } iVar0++; } if (GRAPHICS::DOES_VEHICLE_HAVE_CREW_EMBLEM(iParam0, 0)) { MISC::SET_BIT(&(uParam1->f_77), 11); } else { MISC::CLEAR_BIT(&(uParam1->f_77), 11); } if (DECORATOR::DECOR_EXIST_ON(iParam0, "IgnoredByQuickSave") && DECORATOR::DECOR_GET_BOOL(iParam0, "IgnoredByQuickSave")) { MISC::SET_BIT(&(uParam1->f_77), 27); } else { MISC::CLEAR_BIT(&(uParam1->f_77), 27); } } } int func_52(int iParam0) { switch (iParam0) { case 1: return 0; break; case 2: return 1; break; case 3: return 2; break; case 4: return 3; break; case 5: return 4; break; case 6: return 5; break; case 7: return 6; break; case 8: return 7; break; case 9: return 8; break; case 10: return 24; break; case 11: return 25; break; case 12: return 26; break; } return 0; } int func_53(int iParam0, var uParam1, var uParam2) { int iVar0; int iVar1; if (!VEHICLE::IS_VEHICLE_DRIVEABLE(*iParam0, false)) { return 0; } if (VEHICLE::GET_NUM_MOD_KITS(*iParam0) == 0) { return 0; } iVar0 = 0; while (iVar0 < *uParam1) { iVar1 = iVar0; if ((((iVar1 == 17 || iVar1 == 18) || iVar1 == 19) || iVar1 == 20) || iVar1 == 21) { (*uParam1)[iVar0] = 0; if (VEHICLE::IS_TOGGLE_MOD_ON(*iParam0, iVar1)) { (*uParam1)[iVar0] = 1; } } else if (iVar1 == 22) { if (VEHICLE::IS_TOGGLE_MOD_ON(*iParam0, iVar1)) { switch (VEHICLE::_GET_VEHICLE_XENON_LIGHTS_COLOR(*iParam0)) { case 255: (*uParam1)[iVar0] = 1; break; case 0: (*uParam1)[iVar0] = 2; break; case 1: (*uParam1)[iVar0] = 3; break; case 2: (*uParam1)[iVar0] = 4; break; case 3: (*uParam1)[iVar0] = 5; break; case 4: (*uParam1)[iVar0] = 6; break; case 5: (*uParam1)[iVar0] = 7; break; case 6: (*uParam1)[iVar0] = 8; break; case 7: (*uParam1)[iVar0] = 9; break; case 8: (*uParam1)[iVar0] = 10; break; case 9: (*uParam1)[iVar0] = 11; break; case 10: (*uParam1)[iVar0] = 12; break; case 11: (*uParam1)[iVar0] = 13; break; case 12: (*uParam1)[iVar0] = 14; break; case 13: (*uParam1)[iVar0] = 15; break; } } else { (*uParam1)[iVar0] = 0; } } else { (*uParam1)[iVar0] = VEHICLE::GET_VEHICLE_MOD(*iParam0, iVar0) + 1; if (iVar0 == 23) { (*uParam2)[0] = VEHICLE::GET_VEHICLE_MOD_VARIATION(*iParam0, iVar0); } else if (iVar0 == 24) { (*uParam2)[1] = VEHICLE::GET_VEHICLE_MOD_VARIATION(*iParam0, iVar0); } } iVar0++; } return 1; } int func_54(int iParam0) { switch (iParam0) { case joaat("granger"): case joaat("visione"): return 1; default: } return 0; } void func_55(var uParam0) { int iVar0; uParam0->f_66 = 0; uParam0->f_77 = 0; uParam0->f_65 = 0; uParam0->f_62 = 0; uParam0->f_63 = 0; uParam0->f_64 = 0; uParam0->f_74 = 0; uParam0->f_75 = 0; uParam0->f_76 = 0; *uParam0 = 0; StringCopy(&(uParam0->f_1), "", 16); uParam0->f_5 = 0; uParam0->f_6 = 0; uParam0->f_7 = 0; uParam0->f_8 = 0; iVar0 = 0; while (iVar0 < 49) { uParam0->f_9[iVar0] = 0; iVar0++; } iVar0 = 0; while (iVar0 < 2) { uParam0->f_59[iVar0] = 0; iVar0++; } uParam0->f_67 = 0; uParam0->f_68 = 0; uParam0->f_69 = 0; uParam0->f_70 = 1; uParam0->f_71 = 0; uParam0->f_72 = 0; uParam0->f_73 = 0; } void func_56(int iParam0) { if (iParam0 != 24 && iParam0 != 25) { } func_48(iParam0); func_44(iParam0, 0); } int func_57(int iParam0, int iParam1, struct<3> Param2, float fParam5, bool bParam6, int iParam7) { int iVar0; var uVar1; struct<97> Var5; int iVar103; int iVar104; bool bVar105; char cVar106[16]; int iVar110; if (func_2(iParam1)) { Var5.f_11 = 12; Var5.f_31 = 49; Var5.f_81 = 2; func_42(iParam1, &Var5, iParam7); if (Var5 == 0) { return 1; } if (ENTITY::DOES_ENTITY_EXIST(*iParam0)) { if (ENTITY::GET_ENTITY_MODEL(*iParam0) != Var5) { } return 1; } if ((iParam1 == 0 && !Global_111858.f_2359.f_539.f_4316) && Global_111858.f_9081.f_99.f_58[131]) { Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/] = 0; } if (Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/] == Var5) { STREAMING::REQUEST_MODEL(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/]); if (STREAMING::HAS_MODEL_LOADED(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/])) { *iParam0 = VEHICLE::CREATE_VEHICLE(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/], Param2, fParam5, false, false, false); VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(*iParam0, 5f); VEHICLE::_0xAB04325045427AAE(*iParam0, false); VEHICLE::SET_VEHICLE_CAN_SAVE_IN_GARAGE(*iParam0, false); VEHICLE::SET_VEHICLE_HAS_STRONG_AXLES(*iParam0, true); ENTITY::SET_ENTITY_HEALTH(*iParam0, 1250, 0); VEHICLE::SET_VEHICLE_ENGINE_HEALTH(*iParam0, 1250f); VEHICLE::SET_VEHICLE_PETROL_TANK_HEALTH(*iParam0, 1250f); Var5.f_3 = 1250; VEHICLE::SET_VEHICLE_COLOURS(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_5, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_6); VEHICLE::SET_VEHICLE_EXTRA_COLOURS(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_7, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_8); VEHICLE::SET_VEHICLE_DIRT_LEVEL(*iParam0, Var5.f_2); iVar103 = 0; while (iVar103 < 12) { VEHICLE::SET_VEHICLE_EXTRA(*iParam0, iVar103 + 1, !Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_11[iVar103]); iVar103++; } if (Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_24) { VEHICLE::SET_CONVERTIBLE_ROOF(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_24); } if (func_99(&uVar1, &iVar0)) { VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT(*iParam0, &uVar1); VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(*iParam0, iVar0); } else { VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT(*iParam0, &(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_27)); if (Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_26 >= 0 && Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_26 < VEHICLE::GET_NUMBER_OF_VEHICLE_NUMBER_PLATES()) { VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_26); } } VEHICLE::SET_VEHICLE_TYRE_SMOKE_COLOR(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_84, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_85, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_86); VEHICLE::SET_VEHICLE_TYRES_CAN_BURST(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_88); VEHICLE::SET_VEHICLE_WINDOW_TINT(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_87); VEHICLE::_SET_VEHICLE_NEON_LIGHTS_COLOUR(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_93, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_94, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_95); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 2, MISC::IS_BIT_SET(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_92, 28)); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 3, MISC::IS_BIT_SET(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_92, 29)); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 0, MISC::IS_BIT_SET(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_92, 30)); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 1, MISC::IS_BIT_SET(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_92, 31)); if (VEHICLE::GET_VEHICLE_LIVERY_COUNT(*iParam0) > 1 && Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_89 >= 0) { VEHICLE::SET_VEHICLE_LIVERY(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_89); } if (Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_90 > -1) { if (!VEHICLE::IS_THIS_MODEL_A_BICYCLE(ENTITY::GET_ENTITY_MODEL(*iParam0))) { if (VEHICLE::IS_THIS_MODEL_A_BIKE(ENTITY::GET_ENTITY_MODEL(*iParam0))) { if (Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_90 == 6) { VEHICLE::SET_VEHICLE_WHEEL_TYPE(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_90); } } else { VEHICLE::SET_VEHICLE_WHEEL_TYPE(*iParam0, Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_90); } } } func_95(iParam0, &(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_31), &(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/].f_81)); VEHICLE::SET_VEHICLE_ENVEFF_SCALE(*iParam0, Var5.f_96); if (iParam1 == 2) { if (ENTITY::GET_ENTITY_MODEL(*iParam0) == joaat("bodhi2")) { func_93(iParam0); } } if (bParam6) { STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(Global_111858.f_2359.f_539.f_2407[0 /*295*/][iParam1 /*98*/]); } func_92(*iParam0, iParam1); return 1; } } else if (Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/] == Var5) { STREAMING::REQUEST_MODEL(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/]); if (STREAMING::HAS_MODEL_LOADED(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/])) { *iParam0 = VEHICLE::CREATE_VEHICLE(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/], Param2, fParam5, false, false, false); VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(*iParam0, 5f); VEHICLE::_0xAB04325045427AAE(*iParam0, false); VEHICLE::SET_VEHICLE_CAN_SAVE_IN_GARAGE(*iParam0, false); VEHICLE::SET_VEHICLE_HAS_STRONG_AXLES(*iParam0, true); ENTITY::SET_ENTITY_HEALTH(*iParam0, 1250, 0); VEHICLE::SET_VEHICLE_ENGINE_HEALTH(*iParam0, 1250f); VEHICLE::SET_VEHICLE_PETROL_TANK_HEALTH(*iParam0, 1250f); Var5.f_3 = 1250; VEHICLE::SET_VEHICLE_COLOURS(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_5, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_6); VEHICLE::SET_VEHICLE_EXTRA_COLOURS(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_7, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_8); VEHICLE::SET_VEHICLE_DIRT_LEVEL(*iParam0, Var5.f_2); iVar104 = 0; while (iVar104 < 12) { VEHICLE::SET_VEHICLE_EXTRA(*iParam0, iVar104 + 1, !Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_11[iVar104]); iVar104++; } if (Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_24) { VEHICLE::SET_CONVERTIBLE_ROOF(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_24); } if (func_99(&uVar1, &iVar0)) { VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT(*iParam0, &uVar1); VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(*iParam0, iVar0); } else { VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT(*iParam0, &(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_27)); if (Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_26 >= 0 && Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_26 < VEHICLE::GET_NUMBER_OF_VEHICLE_NUMBER_PLATES()) { VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_26); } } VEHICLE::SET_VEHICLE_TYRE_SMOKE_COLOR(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_84, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_85, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_86); VEHICLE::SET_VEHICLE_TYRES_CAN_BURST(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_88); VEHICLE::SET_VEHICLE_WINDOW_TINT(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_87); VEHICLE::_SET_VEHICLE_NEON_LIGHTS_COLOUR(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_93, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_94, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_95); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 2, MISC::IS_BIT_SET(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_92, 28)); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 3, MISC::IS_BIT_SET(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_92, 29)); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 0, MISC::IS_BIT_SET(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_92, 30)); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 1, MISC::IS_BIT_SET(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_92, 31)); if (VEHICLE::GET_VEHICLE_LIVERY_COUNT(*iParam0) > 1 && Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_89 >= 0) { VEHICLE::SET_VEHICLE_LIVERY(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_89); } if (Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_90 > -1) { if (!VEHICLE::IS_THIS_MODEL_A_BICYCLE(ENTITY::GET_ENTITY_MODEL(*iParam0))) { if (VEHICLE::IS_THIS_MODEL_A_BIKE(ENTITY::GET_ENTITY_MODEL(*iParam0))) { if (Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_90 == 6) { VEHICLE::SET_VEHICLE_WHEEL_TYPE(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_90); } } else { VEHICLE::SET_VEHICLE_WHEEL_TYPE(*iParam0, Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_90); } } } func_95(iParam0, &(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_31), &(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/].f_81)); VEHICLE::SET_VEHICLE_ENVEFF_SCALE(*iParam0, Var5.f_96); if (iParam1 == 2) { if (ENTITY::GET_ENTITY_MODEL(*iParam0) == joaat("bodhi2")) { func_93(iParam0); } } if (bParam6) { STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(Global_111858.f_2359.f_539.f_2407[1 /*295*/][iParam1 /*98*/]); } func_92(*iParam0, iParam1); return 1; } } else { STREAMING::REQUEST_MODEL(Var5); if (STREAMING::HAS_MODEL_LOADED(Var5)) { bVar105 = true; *iParam0 = VEHICLE::CREATE_VEHICLE(Var5, Param2, fParam5, true, true, false); VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(*iParam0, 5f); VEHICLE::_0xAB04325045427AAE(*iParam0, false); VEHICLE::SET_VEHICLE_CAN_SAVE_IN_GARAGE(*iParam0, false); VEHICLE::SET_VEHICLE_HAS_STRONG_AXLES(*iParam0, true); StringCopy(&cVar106, VEHICLE::GET_VEHICLE_NUMBER_PLATE_TEXT(*iParam0), 16); ENTITY::SET_ENTITY_HEALTH(*iParam0, 1250, 0); VEHICLE::SET_VEHICLE_ENGINE_HEALTH(*iParam0, 1250f); VEHICLE::SET_VEHICLE_PETROL_TANK_HEALTH(*iParam0, 1250f); Var5.f_3 = 1250; VEHICLE::SET_VEHICLE_COLOURS(*iParam0, Var5.f_5, Var5.f_6); VEHICLE::SET_VEHICLE_EXTRA_COLOURS(*iParam0, Var5.f_7, Var5.f_8); VEHICLE::SET_VEHICLE_DIRT_LEVEL(*iParam0, Var5.f_2); iVar110 = 0; while (iVar110 < 12) { VEHICLE::SET_VEHICLE_EXTRA(*iParam0, iVar110 + 1, !Var5.f_11[iVar110]); iVar110++; } if (Var5.f_24) { VEHICLE::SET_CONVERTIBLE_ROOF(*iParam0, Var5.f_24); } if (func_99(&uVar1, &iVar0)) { VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT(*iParam0, &uVar1); VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(*iParam0, iVar0); } else { VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT(*iParam0, &(Var5.f_27)); if (Var5.f_26 >= 0 && Var5.f_26 < VEHICLE::GET_NUMBER_OF_VEHICLE_NUMBER_PLATES()) { VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(*iParam0, Var5.f_26); } } VEHICLE::SET_VEHICLE_TYRE_SMOKE_COLOR(*iParam0, Var5.f_84, Var5.f_85, Var5.f_86); VEHICLE::SET_VEHICLE_TYRES_CAN_BURST(*iParam0, Var5.f_88); VEHICLE::SET_VEHICLE_WINDOW_TINT(*iParam0, Var5.f_87); VEHICLE::_SET_VEHICLE_NEON_LIGHTS_COLOUR(*iParam0, Var5.f_93, Var5.f_94, Var5.f_95); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 2, MISC::IS_BIT_SET(Var5.f_92, 28)); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 3, MISC::IS_BIT_SET(Var5.f_92, 29)); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 0, MISC::IS_BIT_SET(Var5.f_92, 30)); VEHICLE::_SET_VEHICLE_NEON_LIGHT_ENABLED(*iParam0, 1, MISC::IS_BIT_SET(Var5.f_92, 31)); if (VEHICLE::GET_VEHICLE_LIVERY_COUNT(*iParam0) > 1 && Var5.f_89 >= 0) { VEHICLE::SET_VEHICLE_LIVERY(*iParam0, Var5.f_89); } if (Var5.f_90 > -1) { if (!VEHICLE::IS_THIS_MODEL_A_BICYCLE(ENTITY::GET_ENTITY_MODEL(*iParam0))) { if (VEHICLE::IS_THIS_MODEL_A_BIKE(ENTITY::GET_ENTITY_MODEL(*iParam0))) { if (Var5.f_90 == 6) { VEHICLE::SET_VEHICLE_WHEEL_TYPE(*iParam0, Var5.f_90); } } else { VEHICLE::SET_VEHICLE_WHEEL_TYPE(*iParam0, Var5.f_90); } } } func_95(iParam0, &(Var5.f_31), &(Var5.f_81)); VEHICLE::SET_VEHICLE_ENVEFF_SCALE(*iParam0, Var5.f_96); if (iParam1 == 1) { if (ENTITY::GET_ENTITY_MODEL(*iParam0) == joaat("bagger") && !Global_111858.f_9081.f_99.f_58[118]) { VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT(*iParam0, &cVar106); bVar105 = false; } } else if (iParam1 == 2) { if (ENTITY::GET_ENTITY_MODEL(*iParam0) == joaat("bodhi2")) { func_93(iParam0); } } else if (((iParam1 == 0 && !Global_111858.f_2359.f_539.f_4316) && Global_111858.f_9081.f_99.f_58[131]) && ENTITY::GET_ENTITY_MODEL(*iParam0) == joaat("tailgater")) { VEHICLE::SET_VEHICLE_MOD(*iParam0, 6, 1, false); VEHICLE::SET_VEHICLE_MOD(*iParam0, 14, 7, false); VEHICLE::SET_VEHICLE_MOD(*iParam0, 11, 2, false); VEHICLE::SET_VEHICLE_MOD(*iParam0, 2, 3, false); VEHICLE::SET_VEHICLE_MOD(*iParam0, 7, 5, false); VEHICLE::SET_VEHICLE_MOD(*iParam0, 0, 0, false); VEHICLE::SET_VEHICLE_MOD(*iParam0, 3, 3, false); VEHICLE::SET_VEHICLE_MOD(*iParam0, 13, 1, false); VEHICLE::SET_VEHICLE_MOD(*iParam0, 4, 3, false); VEHICLE::SET_VEHICLE_MOD(*iParam0, 12, 2, false); VEHICLE::TOGGLE_VEHICLE_MOD(*iParam0, 22, true); VEHICLE::SET_VEHICLE_WHEEL_TYPE(*iParam0, 2); VEHICLE::SET_VEHICLE_MOD(*iParam0, 23, 11, false); VEHICLE::SET_VEHICLE_WINDOW_TINT(*iParam0, 2); Global_111858.f_2359.f_539.f_4316 = 1; func_58(iParam1, iParam0, 0, 1); } if (bParam6) { STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(Var5); } if (bVar105) { func_92(*iParam0, iParam1); } return 1; } } } return 0; } void func_58(int iParam0, int iParam1, int iParam2, bool bParam3) { var uVar0; int iVar1; int iVar2; int iVar3; int iVar4; var uVar5; var uVar6; if ((func_2(iParam0) && ENTITY::DOES_ENTITY_EXIST(*iParam1)) && VEHICLE::IS_VEHICLE_DRIVEABLE(*iParam1, false)) { if (iParam2 > Global_111858.f_2359.f_539.f_2407) { return; } if (iParam2 == 0) { } else if (iParam2 == 1) { } else if (iParam2 == 2) { } else if (iParam2 == 3) { func_10(*iParam1, iParam0); } if (VEHICLE::GET_NUM_MOD_KITS(*iParam1) != 0) { VEHICLE::SET_VEHICLE_MOD_KIT(*iParam1, 0); } Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/] = ENTITY::GET_ENTITY_MODEL(*iParam1); if (VEHICLE::GET_VEHICLE_TRAILER_VEHICLE(*iParam1, &iVar1)) { Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_1 = ENTITY::GET_ENTITY_MODEL(iVar1); } Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_2 = VEHICLE::GET_VEHICLE_DIRT_LEVEL(*iParam1); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_3 = ENTITY::GET_ENTITY_HEALTH(*iParam1); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[0] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 1); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[1] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 2); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[2] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 3); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[3] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 4); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[4] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 5); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[5] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 6); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[6] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 7); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[7] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 8); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[8] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 9); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[9] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 10); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[10] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 11); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_11[11] = VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(*iParam1, 12); if (VEHICLE::IS_VEHICLE_A_CONVERTIBLE(*iParam1, false)) { iVar2 = VEHICLE::GET_CONVERTIBLE_ROOF_STATE(*iParam1); if (iVar2 == 0 || iVar2 == 5) { Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_24 = 1; } else { Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_24 = 0; } } else { Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_24 = 0; } Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_25 = AUDIO::GET_PLAYER_RADIO_STATION_INDEX(); StringCopy(&(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_27), VEHICLE::GET_VEHICLE_NUMBER_PLATE_TEXT(*iParam1), 16); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_26 = VEHICLE::GET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(*iParam1); VEHICLE::GET_VEHICLE_COLOURS(*iParam1, &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_5), &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_6)); VEHICLE::GET_VEHICLE_EXTRA_COLOURS(*iParam1, &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_7), &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_8)); VEHICLE::GET_VEHICLE_TYRE_SMOKE_COLOR(*iParam1, &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_84), &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_85), &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_86)); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_88 = VEHICLE::GET_VEHICLE_TYRES_CAN_BURST(*iParam1); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_87 = VEHICLE::GET_VEHICLE_WINDOW_TINT(*iParam1); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_89 = VEHICLE::GET_VEHICLE_LIVERY(*iParam1); Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_90 = VEHICLE::GET_VEHICLE_WHEEL_TYPE(*iParam1); VEHICLE::_GET_VEHICLE_NEON_LIGHTS_COLOUR(*iParam1, &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_93), &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_94), &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_95)); if (VEHICLE::_IS_VEHICLE_NEON_LIGHT_ENABLED(*iParam1, 2)) { MISC::SET_BIT(&(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_92), 28); } else { MISC::CLEAR_BIT(&(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_92), 28); } if (VEHICLE::_IS_VEHICLE_NEON_LIGHT_ENABLED(*iParam1, 3)) { MISC::SET_BIT(&(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_92), 29); } else { MISC::CLEAR_BIT(&(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_92), 29); } if (VEHICLE::_IS_VEHICLE_NEON_LIGHT_ENABLED(*iParam1, 0)) { MISC::SET_BIT(&(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_92), 30); } else { MISC::CLEAR_BIT(&(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_92), 30); } if (VEHICLE::_IS_VEHICLE_NEON_LIGHT_ENABLED(*iParam1, 1)) { MISC::SET_BIT(&(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_92), 31); } else { MISC::CLEAR_BIT(&(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_92), 31); } Global_111858.f_2359.f_539.f_4317[iParam0] = 10; if (VEHICLE::GET_VEHICLE_MOD_KIT(*iParam1) >= 0 && func_62(*iParam1, 0, &uVar0)) { func_53(iParam1, &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31), &(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_81)); if (bParam3) { Global_111858.f_20114[iParam0 /*43*/].f_40 = 1; Global_111858.f_20114[iParam0 /*43*/] = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/]; Global_111858.f_20114[iParam0 /*43*/].f_3 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_87; Global_111858.f_20114[iParam0 /*43*/].f_4 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_84; Global_111858.f_20114[iParam0 /*43*/].f_5 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_85; Global_111858.f_20114[iParam0 /*43*/].f_6 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_86; Global_111858.f_20114[iParam0 /*43*/].f_10 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_90; Global_111858.f_20114[iParam0 /*43*/].f_16 = !Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_88; Global_111858.f_20114[iParam0 /*43*/].f_19 = { Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_27 }; Global_111858.f_20114[iParam0 /*43*/].f_23 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_26; Global_111858.f_20114[iParam0 /*43*/].f_7 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31[11]; Global_111858.f_20114[iParam0 /*43*/].f_8 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31[12]; Global_111858.f_20114[iParam0 /*43*/].f_9 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31[23]; Global_111858.f_20114[iParam0 /*43*/].f_11 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31[4]; Global_111858.f_20114[iParam0 /*43*/].f_12 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31[15]; Global_111858.f_20114[iParam0 /*43*/].f_13 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31[16]; Global_111858.f_20114[iParam0 /*43*/].f_14 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31[14]; Global_111858.f_20114[iParam0 /*43*/].f_15 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31[22]; Global_111858.f_20114[iParam0 /*43*/].f_18 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31[20]; Global_111858.f_20114[iParam0 /*43*/].f_17 = Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_31[18]; Global_111858.f_20114[iParam0 /*43*/].f_24 = VEHICLE::GET_NUM_VEHICLE_MODS(*iParam1, 11) + 1; Global_111858.f_20114[iParam0 /*43*/].f_25 = VEHICLE::GET_NUM_VEHICLE_MODS(*iParam1, 12) + 1; Global_111858.f_20114[iParam0 /*43*/].f_26 = VEHICLE::GET_NUM_VEHICLE_MODS(*iParam1, 4) + 1; Global_111858.f_20114[iParam0 /*43*/].f_27 = VEHICLE::GET_NUM_VEHICLE_MODS(*iParam1, 23) + 1; Global_111858.f_20114[iParam0 /*43*/].f_28 = VEHICLE::GET_NUM_VEHICLE_MODS(*iParam1, 14) + 1; Global_111858.f_20114[iParam0 /*43*/].f_29 = VEHICLE::GET_NUM_VEHICLE_MODS(*iParam1, 16) + 1; Global_111858.f_20114[iParam0 /*43*/].f_30 = VEHICLE::GET_NUM_VEHICLE_MODS(*iParam1, 15) + 1; Global_111858.f_20114[iParam0 /*43*/].f_32 = VEHICLE::_0xEEBFC7A7EFDC35B4(*iParam1); Global_111858.f_20114[iParam0 /*43*/].f_33[0] = AUDIO::GET_VEHICLE_DEFAULT_HORN(*iParam1); Global_111858.f_20114[iParam0 /*43*/].f_33[1] = VEHICLE::GET_VEHICLE_MOD_MODIFIER_VALUE(*iParam1, 14, 0); Global_111858.f_20114[iParam0 /*43*/].f_33[2] = VEHICLE::GET_VEHICLE_MOD_MODIFIER_VALUE(*iParam1, 14, 1); Global_111858.f_20114[iParam0 /*43*/].f_33[3] = VEHICLE::GET_VEHICLE_MOD_MODIFIER_VALUE(*iParam1, 14, 2); Global_111858.f_20114[iParam0 /*43*/].f_33[4] = VEHICLE::GET_VEHICLE_MOD_MODIFIER_VALUE(*iParam1, 14, 3); Global_111858.f_20114[iParam0 /*43*/].f_39 = VEHICLE::GET_VEHICLE_MOD_KIT_TYPE(*iParam1); Global_111858.f_20114[iParam0 /*43*/].f_31 = func_61(*iParam1); Global_111858.f_20114[iParam0 /*43*/].f_33[0] = AUDIO::GET_VEHICLE_DEFAULT_HORN_IGNORE_MODS(*iParam1); VEHICLE::GET_VEHICLE_MOD_COLOR_1(*iParam1, &iVar4, &uVar5, &uVar6); if (iVar4 == 0) { iVar3 = 0; } else if (iVar4 == 1) { iVar3 = 1; } else if (iVar4 == 3) { iVar3 = 2; } else if (iVar4 == 4) { iVar3 = 3; } else if (iVar4 == 5) { iVar3 = 4; } else { iVar3 = -1; } func_59(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_5, Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_7, iVar3, 1, &(Global_111858.f_20114[iParam0 /*43*/].f_1)); VEHICLE::GET_VEHICLE_MOD_COLOR_2(*iParam1, &iVar4, &uVar5); if (iVar4 == 0) { iVar3 = 0; } else if (iVar4 == 1) { iVar3 = 1; } else if (iVar4 == 3) { iVar3 = 2; } else if (iVar4 == 4) { iVar3 = 3; } else if (iVar4 == 5) { iVar3 = 4; } else { iVar3 = -1; } func_59(Global_111858.f_2359.f_539.f_2407[iParam2 /*295*/][iParam0 /*98*/].f_6, -1, iVar3, 0, &(Global_111858.f_20114[iParam0 /*43*/].f_2)); } } } } int func_59(int iParam0, int iParam1, int iParam2, bool bParam3, var uParam4) { int iVar0; int iVar1; char* sVar2; int iVar6; int iVar7; iVar0 = 0; while (func_60(iVar0, &sVar2, &iVar1, &iVar6, &iVar7)) { if ((iParam0 == iVar6 && (!bParam3 || iParam1 == iVar7)) && ((iParam2 == iVar1 || iParam2 == -1) || iParam2 == 255)) { *uParam4 = iVar0; return 1; } iVar0++; } iParam0 = -1; iParam1 = -1; *uParam4 = -1; return 0; } bool func_60(int iParam0, char* sParam1, var uParam2, var uParam3, var uParam4) { *uParam2 = -1; *uParam3 = -1; *uParam4 = -1; switch (iParam0) { case 0: StringCopy(sParam1, "BR BLACK_STEEL", 16); *uParam2 = 3; *uParam3 = 118; *uParam4 = 3; break; case 1: StringCopy(sParam1, "BLACK_GRAPHITE", 16); *uParam2 = 0; *uParam3 = 147; *uParam4 = 4; break; case 2: StringCopy(sParam1, "CHOCOLATE_BROWN", 16); *uParam2 = 1; *uParam3 = 96; *uParam4 = 0; break; case 3: StringCopy(sParam1, "PURPLE", 16); *uParam2 = 0; *uParam3 = 71; *uParam4 = 145; break; case 4: StringCopy(sParam1, "HOT PINK", 16); *uParam2 = 0; *uParam3 = 135; *uParam4 = 135; break; case 5: StringCopy(sParam1, "FORMULA_RED", 16); *uParam2 = 0; *uParam3 = 29; *uParam4 = 28; break; case 6: StringCopy(sParam1, "BLUE", 16); *uParam2 = 0; *uParam3 = 64; *uParam4 = 68; break; case 7: StringCopy(sParam1, "ULTRA_BLUE", 16); *uParam2 = 1; *uParam3 = 70; *uParam4 = 0; break; case 8: StringCopy(sParam1, "RACING_GREEN", 16); *uParam2 = 1; *uParam3 = 50; *uParam4 = 0; break; case 9: StringCopy(sParam1, "LIME_GREEN", 16); *uParam2 = 2; *uParam3 = 55; *uParam4 = 0; break; case 10: StringCopy(sParam1, "RACE_YELLOW", 16); *uParam2 = 1; *uParam3 = 89; *uParam4 = 0; break; case 11: StringCopy(sParam1, "ORANGE", 16); *uParam2 = 1; *uParam3 = 38; *uParam4 = 0; break; case 12: StringCopy(sParam1, "GOLD", 16); *uParam2 = 0; *uParam3 = 37; *uParam4 = 106; break; case 13: StringCopy(sParam1, "SILVER", 16); *uParam2 = 0; *uParam3 = 4; *uParam4 = 111; break; case 14: StringCopy(sParam1, "CHROME", 16); *uParam2 = 4; *uParam3 = 120; *uParam4 = 0; break; case 15: StringCopy(sParam1, "WHITE", 16); *uParam2 = 1; *uParam3 = 111; *uParam4 = 0; break; case 16: StringCopy(sParam1, "BLACK", 16); *uParam2 = 0; *uParam3 = 0; *uParam4 = 10; break; case 17: StringCopy(sParam1, "GRAPHITE", 16); *uParam2 = 0; *uParam3 = 1; *uParam4 = 5; break; case 18: StringCopy(sParam1, "ANTHR_BLACK", 16); *uParam2 = 0; *uParam3 = 11; *uParam4 = 2; break; case 19: StringCopy(sParam1, "BLACK_STEEL", 16); *uParam2 = 0; *uParam3 = 2; *uParam4 = 5; break; case 20: StringCopy(sParam1, "DARK_SILVER", 16); *uParam2 = 0; *uParam3 = 3; *uParam4 = 6; break; case 21: StringCopy(sParam1, "BLUE_SILVER", 16); *uParam2 = 0; *uParam3 = 5; *uParam4 = 111; break; case 22: StringCopy(sParam1, "ROLLED_STEEL", 16); *uParam2 = 0; *uParam3 = 6; *uParam4 = 4; break; case 23: StringCopy(sParam1, "SHADOW_SILVER", 16); *uParam2 = 0; *uParam3 = 7; *uParam4 = 5; break; case 24: StringCopy(sParam1, "STONE_SILVER", 16); *uParam2 = 0; *uParam3 = 8; *uParam4 = 5; break; case 25: StringCopy(sParam1, "MIDNIGHT_SILVER", 16); *uParam2 = 0; *uParam3 = 9; *uParam4 = 7; break; case 26: StringCopy(sParam1, "CAST_IRON_SIL", 16); *uParam2 = 0; *uParam3 = 10; *uParam4 = 7; break; case 27: StringCopy(sParam1, "RED", 16); *uParam2 = 0; *uParam3 = 27; *uParam4 = 36; break; case 28: StringCopy(sParam1, "TORINO_RED", 16); *uParam2 = 0; *uParam3 = 28; *uParam4 = 28; break; case 29: StringCopy(sParam1, "LAVA_RED", 16); *uParam2 = 0; *uParam3 = 150; *uParam4 = 42; break; case 30: StringCopy(sParam1, "BLAZE_RED", 16); *uParam2 = 0; *uParam3 = 30; *uParam4 = 36; break; case 31: StringCopy(sParam1, "GRACE_RED", 16); *uParam2 = 0; *uParam3 = 31; *uParam4 = 27; break; case 32: StringCopy(sParam1, "GARNET_RED", 16); *uParam2 = 0; *uParam3 = 32; *uParam4 = 25; break; case 33: StringCopy(sParam1, "SUNSET_RED", 16); *uParam2 = 0; *uParam3 = 33; *uParam4 = 47; break; case 34: StringCopy(sParam1, "CABERNET_RED", 16); *uParam2 = 0; *uParam3 = 34; *uParam4 = 47; break; case 35: StringCopy(sParam1, "WINE_RED", 16); *uParam2 = 0; *uParam3 = 143; *uParam4 = 31; break; case 36: StringCopy(sParam1, "CANDY_RED", 16); *uParam2 = 0; *uParam3 = 35; *uParam4 = 25; break; case 37: StringCopy(sParam1, "PINK", 16); *uParam2 = 0; *uParam3 = 137; *uParam4 = 3; break; case 38: StringCopy(sParam1, "SALMON_PINK", 16); *uParam2 = 0; *uParam3 = 136; *uParam4 = 5; break; case 39: StringCopy(sParam1, "SUNRISE_ORANGE", 16); *uParam2 = 0; *uParam3 = 36; *uParam4 = 26; break; case 40: StringCopy(sParam1, "ORANGE", 16); *uParam2 = 0; *uParam3 = 38; *uParam4 = 37; break; case 41: StringCopy(sParam1, "BRIGHT_ORANGE", 16); *uParam2 = 0; *uParam3 = 138; *uParam4 = 89; break; case 42: StringCopy(sParam1, "BRONZE", 16); *uParam2 = 0; *uParam3 = 90; *uParam4 = 102; break; case 43: StringCopy(sParam1, "YELLOW", 16); *uParam2 = 0; *uParam3 = 88; *uParam4 = 88; break; case 44: StringCopy(sParam1, "RACE_YELLOW", 16); *uParam2 = 0; *uParam3 = 89; *uParam4 = 88; break; case 45: StringCopy(sParam1, "FLUR_YELLOW", 16); *uParam2 = 0; *uParam3 = 91; *uParam4 = 91; break; case 46: StringCopy(sParam1, "DARK_GREEN", 16); *uParam2 = 0; *uParam3 = 49; *uParam4 = 52; break; case 47: StringCopy(sParam1, "RACING_GREEN", 16); *uParam2 = 0; *uParam3 = 50; *uParam4 = 53; break; case 48: StringCopy(sParam1, "SEA_GREEN", 16); *uParam2 = 0; *uParam3 = 51; *uParam4 = 66; break; case 49: StringCopy(sParam1, "OLIVE_GREEN", 16); *uParam2 = 0; *uParam3 = 52; *uParam4 = 59; break; case 50: StringCopy(sParam1, "BRIGHT_GREEN", 16); *uParam2 = 0; *uParam3 = 53; *uParam4 = 59; break; case 51: StringCopy(sParam1, "PETROL_GREEN", 16); *uParam2 = 0; *uParam3 = 54; *uParam4 = 60; break; case 52: StringCopy(sParam1, "LIME_GREEN", 16); *uParam2 = 0; *uParam3 = 92; *uParam4 = 92; break; case 53: StringCopy(sParam1, "MIDNIGHT_BLUE", 16); *uParam2 = 0; *uParam3 = 141; *uParam4 = 73; break; case 54: StringCopy(sParam1, "GALAXY_BLUE", 16); *uParam2 = 0; *uParam3 = 61; *uParam4 = 63; break; case 55: StringCopy(sParam1, "DARK_BLUE", 16); *uParam2 = 0; *uParam3 = 62; *uParam4 = 68; break; case 56: StringCopy(sParam1, "SAXON_BLUE", 16); *uParam2 = 0; *uParam3 = 63; *uParam4 = 87; break; case 57: StringCopy(sParam1, "MARINER_BLUE", 16); *uParam2 = 0; *uParam3 = 65; *uParam4 = 87; break; case 58: StringCopy(sParam1, "HARBOR_BLUE", 16); *uParam2 = 0; *uParam3 = 66; *uParam4 = 60; break; case 59: StringCopy(sParam1, "DIAMOND_BLUE", 16); *uParam2 = 0; *uParam3 = 67; *uParam4 = 67; break; case 60: StringCopy(sParam1, "SURF_BLUE", 16); *uParam2 = 0; *uParam3 = 68; *uParam4 = 68; break; case 61: StringCopy(sParam1, "NAUTICAL_BLUE", 16); *uParam2 = 0; *uParam3 = 69; *uParam4 = 74; break; case 62: StringCopy(sParam1, "RACING_BLUE", 16); *uParam2 = 0; *uParam3 = 73; *uParam4 = 73; break; case 63: StringCopy(sParam1, "ULTRA_BLUE", 16); *uParam2 = 0; *uParam3 = 70; *uParam4 = 70; break; case 64: StringCopy(sParam1, "LIGHT_BLUE", 16); *uParam2 = 0; *uParam3 = 74; *uParam4 = 74; break; case 65: StringCopy(sParam1, "CHOCOLATE_BROWN", 16); *uParam2 = 0; *uParam3 = 96; *uParam4 = 95; break; case 66: StringCopy(sParam1, "BISON_BROWN", 16); *uParam2 = 0; *uParam3 = 101; *uParam4 = 95; break; case 67: StringCopy(sParam1, "CREEK_BROWN", 16); *uParam2 = 0; *uParam3 = 95; *uParam4 = 97; break; case 68: StringCopy(sParam1, "UMBER_BROWN", 16); *uParam2 = 0; *uParam3 = 94; *uParam4 = 104; break; case 69: StringCopy(sParam1, "MAPLE_BROWN", 16); *uParam2 = 0; *uParam3 = 97; *uParam4 = 98; break; case 70: StringCopy(sParam1, "BEECHWOOD_BROWN", 16); *uParam2 = 0; *uParam3 = 103; *uParam4 = 104; break; case 71: StringCopy(sParam1, "SIENNA_BROWN", 16); *uParam2 = 0; *uParam3 = 104; *uParam4 = 104; break; case 72: StringCopy(sParam1, "SADDLE_BROWN", 16); *uParam2 = 0; *uParam3 = 98; *uParam4 = 95; break; case 73: StringCopy(sParam1, "MOSS_BROWN", 16); *uParam2 = 0; *uParam3 = 100; *uParam4 = 100; break; case 74: StringCopy(sParam1, "WOODBEECH_BROWN", 16); *uParam2 = 0; *uParam3 = 102; *uParam4 = 105; break; case 75: StringCopy(sParam1, "STRAW_BROWN", 16); *uParam2 = 0; *uParam3 = 99; *uParam4 = 106; break; case 76: StringCopy(sParam1, "SANDY_BROWN", 16); *uParam2 = 0; *uParam3 = 105; *uParam4 = 105; break; case 77: StringCopy(sParam1, "BLEECHED_BROWN", 16); *uParam2 = 0; *uParam3 = 106; *uParam4 = 106; break; case 78: StringCopy(sParam1, "SPIN_PURPLE", 16); *uParam2 = 0; *uParam3 = 72; *uParam4 = 64; break; case joaat("MPSV_LP0_31"): StringCopy(sParam1, "MIGHT_PURPLE", 16); *uParam2 = 0; *uParam3 = 146; *uParam4 = 145; break; case 80: StringCopy(sParam1, "BRIGHT_PURPLE", 16); *uParam2 = 0; *uParam3 = 145; *uParam4 = 74; break; case 81: StringCopy(sParam1, "CREAM", 16); *uParam2 = 0; *uParam3 = 107; *uParam4 = 107; break; case 82: StringCopy(sParam1, "WHITE", 16); *uParam2 = 0; *uParam3 = 111; *uParam4 = 0; break; case 83: StringCopy(sParam1, "FROST_WHITE", 16); *uParam2 = 0; *uParam3 = 112; *uParam4 = 0; break; case 84: StringCopy(sParam1, "BLACK", 16); *uParam2 = 1; *uParam3 = 0; *uParam4 = 0; break; case 85: StringCopy(sParam1, "BLACK_GRAPHITE", 16); *uParam2 = 1; *uParam3 = 147; *uParam4 = 0; break; case 86: StringCopy(sParam1, "GRAPHITE", 16); *uParam2 = 1; *uParam3 = 1; *uParam4 = 0; break; case 87: StringCopy(sParam1, "ANTHR_BLACK", 16); *uParam2 = 1; *uParam3 = 11; *uParam4 = 0; break; case 88: StringCopy(sParam1, "BLACK_STEEL", 16); *uParam2 = 1; *uParam3 = 2; *uParam4 = 0; break; case 89: StringCopy(sParam1, "DARK_SILVER", 16); *uParam2 = 1; *uParam3 = 3; *uParam4 = 2; break; case 90: StringCopy(sParam1, "SILVER", 16); *uParam2 = 1; *uParam3 = 4; *uParam4 = 4; break; case 91: StringCopy(sParam1, "BLUE_SILVER", 16); *uParam2 = 1; *uParam3 = 5; *uParam4 = 5; break; case 92: StringCopy(sParam1, "ROLLED_STEEL", 16); *uParam2 = 1; *uParam3 = 6; *uParam4 = 0; break; case 93: StringCopy(sParam1, "SHADOW_SILVER", 16); *uParam2 = 1; *uParam3 = 7; *uParam4 = 0; break; case 94: StringCopy(sParam1, "STONE_SILVER", 16); *uParam2 = 1; *uParam3 = 8; *uParam4 = 0; break; case 95: StringCopy(sParam1, "MIDNIGHT_SILVER", 16); *uParam2 = 1; *uParam3 = 9; *uParam4 = 0; break; case 96: StringCopy(sParam1, "CAST_IRON_SIL", 16); *uParam2 = 1; *uParam3 = 10; *uParam4 = 0; break; case 97: StringCopy(sParam1, "RED", 16); *uParam2 = 1; *uParam3 = 27; *uParam4 = 0; break; case 98: StringCopy(sParam1, "TORINO_RED", 16); *uParam2 = 1; *uParam3 = 28; *uParam4 = 0; break; case 99: StringCopy(sParam1, "FORMULA_RED", 16); *uParam2 = 1; *uParam3 = 29; *uParam4 = 0; break; case 100: StringCopy(sParam1, "LAVA_RED", 16); *uParam2 = 1; *uParam3 = 150; *uParam4 = 0; break; case 101: StringCopy(sParam1, "BLAZE_RED", 16); *uParam2 = 1; *uParam3 = 30; *uParam4 = 0; break; case 102: StringCopy(sParam1, "GRACE_RED", 16); *uParam2 = 1; *uParam3 = 31; *uParam4 = 0; break; case 103: StringCopy(sParam1, "GARNET_RED", 16); *uParam2 = 1; *uParam3 = 32; *uParam4 = 0; break; case 104: StringCopy(sParam1, "SUNSET_RED", 16); *uParam2 = 1; *uParam3 = 33; *uParam4 = 0; break; case 105: StringCopy(sParam1, "CABERNET_RED", 16); *uParam2 = 1; *uParam3 = 34; *uParam4 = 0; break; case 106: StringCopy(sParam1, "WINE_RED", 16); *uParam2 = 1; *uParam3 = 143; *uParam4 = 0; break; case 107: StringCopy(sParam1, "CANDY_RED", 16); *uParam2 = 1; *uParam3 = 35; *uParam4 = 0; break; case 108: StringCopy(sParam1, "HOT PINK", 16); *uParam2 = 1; *uParam3 = 135; *uParam4 = 0; break; case 109: StringCopy(sParam1, "PINK", 16); *uParam2 = 1; *uParam3 = 137; *uParam4 = 0; break; case 110: StringCopy(sParam1, "SALMON_PINK", 16); *uParam2 = 1; *uParam3 = 136; *uParam4 = 0; break; case 111: StringCopy(sParam1, "SUNRISE_ORANGE", 16); *uParam2 = 1; *uParam3 = 36; *uParam4 = 0; break; case 112: StringCopy(sParam1, "BRIGHT_ORANGE", 16); *uParam2 = 1; *uParam3 = 138; *uParam4 = 0; break; case 113: StringCopy(sParam1, "GOLD", 16); *uParam2 = 1; *uParam3 = 99; *uParam4 = 99; break; case 114: StringCopy(sParam1, "BRONZE", 16); *uParam2 = 1; *uParam3 = 90; *uParam4 = 102; break; case 115: StringCopy(sParam1, "YELLOW", 16); *uParam2 = 1; *uParam3 = 88; *uParam4 = 0; break; case 116: StringCopy(sParam1, "FLUR_YELLOW", 16); *uParam2 = 1; *uParam3 = 91; *uParam4 = 0; break; case 117: StringCopy(sParam1, "DARK_GREEN", 16); *uParam2 = 1; *uParam3 = 49; *uParam4 = 0; break; case 118: StringCopy(sParam1, "SEA_GREEN", 16); *uParam2 = 1; *uParam3 = 51; *uParam4 = 0; break; case 119: StringCopy(sParam1, "OLIVE_GREEN", 16); *uParam2 = 1; *uParam3 = 52; *uParam4 = 0; break; case 120: StringCopy(sParam1, "BRIGHT_GREEN", 16); *uParam2 = 1; *uParam3 = 53; *uParam4 = 0; break; case 121: StringCopy(sParam1, "PETROL_GREEN", 16); *uParam2 = 1; *uParam3 = 54; *uParam4 = 0; break; case 122: StringCopy(sParam1, "LIME_GREEN", 16); *uParam2 = 1; *uParam3 = 92; *uParam4 = 0; break; case 123: StringCopy(sParam1, "MIDNIGHT_BLUE", 16); *uParam2 = 1; *uParam3 = 141; *uParam4 = 0; break; case 124: StringCopy(sParam1, "GALAXY_BLUE", 16); *uParam2 = 1; *uParam3 = 61; *uParam4 = 0; break; case 125: StringCopy(sParam1, "DARK_BLUE", 16); *uParam2 = 1; *uParam3 = 62; *uParam4 = 0; break; case 126: StringCopy(sParam1, "SAXON_BLUE", 16); *uParam2 = 1; *uParam3 = 63; *uParam4 = 0; break; case 127: StringCopy(sParam1, "BLUE", 16); *uParam2 = 1; *uParam3 = 64; *uParam4 = 0; break; case 128: StringCopy(sParam1, "MARINER_BLUE", 16); *uParam2 = 1; *uParam3 = 65; *uParam4 = 0; break; case 129: StringCopy(sParam1, "HARBOR_BLUE", 16); *uParam2 = 1; *uParam3 = 66; *uParam4 = 0; break; case 130: StringCopy(sParam1, "DIAMOND_BLUE", 16); *uParam2 = 1; *uParam3 = 67; *uParam4 = 0; break; case 131: StringCopy(sParam1, "SURF_BLUE", 16); *uParam2 = 1; *uParam3 = 68; *uParam4 = 0; break; case 132: StringCopy(sParam1, "NAUTICAL_BLUE", 16); *uParam2 = 1; *uParam3 = 69; *uParam4 = 0; break; case 133: StringCopy(sParam1, "RACING_BLUE", 16); *uParam2 = 1; *uParam3 = 73; *uParam4 = 0; break; case 134: StringCopy(sParam1, "LIGHT_BLUE", 16); *uParam2 = 1; *uParam3 = 74; *uParam4 = 0; break; case 135: StringCopy(sParam1, "BISON_BROWN", 16); *uParam2 = 1; *uParam3 = 101; *uParam4 = 0; break; case 136: StringCopy(sParam1, "CREEK_BROWN", 16); *uParam2 = 1; *uParam3 = 95; *uParam4 = 0; break; case 137: StringCopy(sParam1, "UMBER_BROWN", 16); *uParam2 = 1; *uParam3 = 94; *uParam4 = 0; break; case 138: StringCopy(sParam1, "MAPLE_BROWN", 16); *uParam2 = 1; *uParam3 = 97; *uParam4 = 0; break; case 139: StringCopy(sParam1, "BEECHWOOD_BROWN", 16); *uParam2 = 1; *uParam3 = 103; *uParam4 = 0; break; case 140: StringCopy(sParam1, "SIENNA_BROWN", 16); *uParam2 = 1; *uParam3 = 104; *uParam4 = 0; break; case 141: StringCopy(sParam1, "SADDLE_BROWN", 16); *uParam2 = 1; *uParam3 = 98; *uParam4 = 0; break; case 142: StringCopy(sParam1, "MOSS_BROWN", 16); *uParam2 = 1; *uParam3 = 100; *uParam4 = 0; break; case 143: StringCopy(sParam1, "WOODBEECH_BROWN", 16); *uParam2 = 1; *uParam3 = 102; *uParam4 = 0; break; case 144: StringCopy(sParam1, "STRAW_BROWN", 16); *uParam2 = 1; *uParam3 = 99; *uParam4 = 0; break; case 145: StringCopy(sParam1, "SANDY_BROWN", 16); *uParam2 = 1; *uParam3 = 105; *uParam4 = 0; break; case 146: StringCopy(sParam1, "BLEECHED_BROWN", 16); *uParam2 = 1; *uParam3 = 106; *uParam4 = 0; break; case 147: StringCopy(sParam1, "PURPLE", 16); *uParam2 = 1; *uParam3 = 71; *uParam4 = 0; break; case 148: StringCopy(sParam1, "SPIN_PURPLE", 16); *uParam2 = 1; *uParam3 = 72; *uParam4 = 0; break; case 149: StringCopy(sParam1, "MIGHT_PURPLE", 16); *uParam2 = 1; *uParam3 = 142; *uParam4 = 0; break; case 150: StringCopy(sParam1, "BRIGHT_PURPLE", 16); *uParam2 = 1; *uParam3 = 145; *uParam4 = 0; break; case 151: StringCopy(sParam1, "CREAM", 16); *uParam2 = 1; *uParam3 = 107; *uParam4 = 0; break; case 152: StringCopy(sParam1, "FROST_WHITE", 16); *uParam2 = 1; *uParam3 = 112; *uParam4 = 0; break; case 153: StringCopy(sParam1, "BLACK", 16); *uParam2 = 2; *uParam3 = 12; *uParam4 = 0; break; case 154: StringCopy(sParam1, "GREY", 16); *uParam2 = 2; *uParam3 = 13; *uParam4 = 0; break; case 155: StringCopy(sParam1, "LIGHT_GREY", 16); *uParam2 = 2; *uParam3 = 14; *uParam4 = 0; break; case 156: StringCopy(sParam1, "WHITE", 16); *uParam2 = 2; *uParam3 = 131; *uParam4 = 0; break; case 157: StringCopy(sParam1, "BLUE", 16); *uParam2 = 2; *uParam3 = 83; *uParam4 = 0; break; case 158: StringCopy(sParam1, "DARK_BLUE", 16); *uParam2 = 2; *uParam3 = 82; *uParam4 = 0; break; case 159: StringCopy(sParam1, "MIDNIGHT_BLUE", 16); *uParam2 = 2; *uParam3 = 84; *uParam4 = 0; break; case 160: StringCopy(sParam1, "MIGHT_PURPLE", 16); *uParam2 = 2; *uParam3 = 149; *uParam4 = 0; break; case 161: StringCopy(sParam1, "Purple", 16); *uParam2 = 2; *uParam3 = 148; *uParam4 = 0; break; case 162: StringCopy(sParam1, "RED", 16); *uParam2 = 2; *uParam3 = 39; *uParam4 = 0; break; case 163: StringCopy(sParam1, "DARK_RED", 16); *uParam2 = 2; *uParam3 = 40; *uParam4 = 0; break; case 164: StringCopy(sParam1, "ORANGE", 16); *uParam2 = 2; *uParam3 = 41; *uParam4 = 0; break; case 165: StringCopy(sParam1, "YELLOW", 16); *uParam2 = 2; *uParam3 = 42; *uParam4 = 0; break; case 166: StringCopy(sParam1, "GREEN", 16); *uParam2 = 2; *uParam3 = 128; *uParam4 = 0; break; case 167: StringCopy(sParam1, "MATTE_FOR", 16); *uParam2 = 2; *uParam3 = 151; *uParam4 = 0; break; case 168: StringCopy(sParam1, "MATTE_FOIL", 16); *uParam2 = 2; *uParam3 = 155; *uParam4 = 0; break; case 169: StringCopy(sParam1, "MATTE_OD", 16); *uParam2 = 2; *uParam3 = 152; *uParam4 = 0; break; case 170: StringCopy(sParam1, "MATTE_DIRT", 16); *uParam2 = 2; *uParam3 = 153; *uParam4 = 0; break; case 171: StringCopy(sParam1, "MATTE_DESERT", 16); *uParam2 = 2; *uParam3 = 154; *uParam4 = 0; break; case 172: StringCopy(sParam1, "BR_STEEL", 16); *uParam2 = 3; *uParam3 = 117; *uParam4 = 18; break; case 173: StringCopy(sParam1, "BR_ALUMINIUM", 16); *uParam2 = 3; *uParam3 = 119; *uParam4 = 5; break; case 174: StringCopy(sParam1, "GOLD_P", 16); *uParam2 = 3; *uParam3 = 158; *uParam4 = 160; break; case 175: StringCopy(sParam1, "GOLD_S", 16); *uParam2 = 3; *uParam3 = 159; *uParam4 = 160; break; } return *uParam2 != -1; } float func_61(int iParam0) { int iVar0; int iVar1; int iVar2; int iVar3; int iVar4; int iVar5; float fVar6; iVar0 = 100000; iVar1 = 65000; iVar2 = 50000; iVar3 = 20000; iVar4 = 20000; iVar5 = iVar4; if ((ENTITY::DOES_ENTITY_EXIST(iParam0) && VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) && VEHICLE::GET_VEHICLE_MOD_KIT(iParam0) >= 0) { if (VEHICLE::GET_VEHICLE_MOD_KIT_TYPE(iParam0) == 3) { iVar5 = iVar0; } else if (VEHICLE::GET_VEHICLE_MOD_KIT_TYPE(iParam0) == 1) { iVar5 = iVar1; } else if (VEHICLE::GET_VEHICLE_MOD_KIT_TYPE(iParam0) == 2) { iVar5 = iVar2; } else if (VEHICLE::GET_VEHICLE_MOD_KIT_TYPE(iParam0) == 0) { if (VEHICLE::IS_THIS_MODEL_A_BIKE(ENTITY::GET_ENTITY_MODEL(iParam0))) { iVar5 = iVar3; } else { iVar5 = iVar4; } } } fVar6 = (SYSTEM::TO_FLOAT(iVar5) / SYSTEM::TO_FLOAT(iVar4)); return fVar6; } int func_62(int iParam0, bool bParam1, var uParam2) { int iVar0; bool bVar1; *uParam2 = 0; if (!ENTITY::DOES_ENTITY_EXIST(iParam0)) { return 0; } if (!VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) { return 0; } if (!STREAMING::IS_MODEL_A_VEHICLE(ENTITY::GET_ENTITY_MODEL(iParam0))) { return 0; } iVar0 = ENTITY::GET_ENTITY_MODEL(iParam0); if ((!func_90(iVar0, bParam1, uParam2) && !func_89(PLAYER::PLAYER_ID())) && !func_72(iParam0)) { return 0; } if (func_89(PLAYER::PLAYER_ID())) { if (func_71(iVar0)) { return 1; } else { return 0; } } bVar1 = false; if (func_70(PLAYER::PLAYER_ID()) && (VEHICLE::IS_THIS_MODEL_A_HELI(iVar0) || VEHICLE::IS_THIS_MODEL_A_PLANE(iVar0))) { bVar1 = true; } if (((VEHICLE::IS_BIG_VEHICLE(iParam0) && !func_68(iParam0)) && !bVar1) && !(func_67(ENTITY::GET_ENTITY_MODEL(iParam0)) && func_63(PLAYER::PLAYER_ID()))) { switch (ENTITY::GET_ENTITY_MODEL(iParam0)) { case joaat("cerberus"): case joaat("cerberus2"): case joaat("cerberus3"): case joaat("monster3"): case joaat("monster4"): case joaat("monster5"): *uParam2 = 16; break; default: *uParam2 = 2; break; } return 0; } if (!NETWORK::NETWORK_IS_GAME_IN_PROGRESS()) { if ((func_23(iParam0) && ENTITY::GET_ENTITY_MODEL(iParam0) != joaat("sentinel2")) && ENTITY::GET_ENTITY_MODEL(iParam0) != joaat("issi2")) { *uParam2 = 2; return 0; } } return 1; } int func_63(int iParam0) { if (iParam0 != func_66()) { if (func_65(iParam0, 1, 1)) { if (Global_2425869[iParam0 /*443*/].f_314.f_6 != -1) { return func_64(Global_2425869[iParam0 /*443*/].f_314.f_6) == 11; } } } return 0; } int func_64(int iParam0) { switch (iParam0) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: return 0; break; case 60: case 61: case 62: case 63: case 64: case 65: case 66: case 67: case 68: case 69: return 1; break; case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: case 38: case 39: case 40: case 41: return 2; break; case 43: case 42: case 44: case 45: case 46: case 47: case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: case 58: case 59: case 98: case 99: case 100: case 112: case 113: case 114: case 115: case 119: case 116: case 118: case 120: case 121: case 126: case 127: case 134: case 135: case 136: case 137: case 138: case 139: case 140: case 141: case 142: case 143: case 144: return 3; break; case 70: case 71: case 72: case 73: case 74: case 75: case 76: case 77: case 78: case joaat("MPSV_LP0_31"): case 80: return 4; break; case 81: return 5; break; case 82: return 6; break; case 83: case 84: case 85: case 86: case 87: return 7; break; case 88: return 8; break; case 89: case 90: case 91: case 92: case 93: case 94: case 95: case 96: case 97: return 9; break; case 101: return 10; break; case 102: case 103: case 104: case 105: case 106: case 107: case 108: case 109: case 110: case 111: return 11; break; case 117: return 12; break; case 122: return 13; break; case 123: return 14; break; case 124: return 15; break; case 125: return 16; break; case 128: case 129: case 130: case 131: case 132: case 133: return 17; break; case 145: return 18; break; case 146: return 19; break; case 147: return 20; break; } return -1; } int func_65(int iParam0, bool bParam1, bool bParam2) { int iVar0; iVar0 = iParam0; if (iVar0 != -1) { if (NETWORK::NETWORK_IS_PLAYER_ACTIVE(iParam0)) { if (bParam1) { if (!PLAYER::IS_PLAYER_PLAYING(iParam0)) { return 0; } } if (bParam2) { if (!Global_2440049.f_3[iVar0]) { return 0; } } return 1; } } return 0; } int func_66() { return -1; } int func_67(int iParam0) { if (((iParam0 == joaat("mule4") || iParam0 == joaat("pounder2")) || iParam0 == joaat("speedo4")) || iParam0 == joaat("terbyte")) { return 1; } return 0; } int func_68(int iParam0) { switch (ENTITY::GET_ENTITY_MODEL(iParam0)) { case joaat("halftrack"): case joaat("phantom3"): case joaat("hauler2"): case joaat("trailerlarge"): case joaat("trailersmall2"): case joaat("bruiser"): case joaat("scarab"): case joaat("scarab2"): case joaat("scarab3"): case joaat("bruiser2"): case joaat("bruiser3"): return 1; break; case joaat("cerberus"): case joaat("cerberus2"): case joaat("cerberus3"): case joaat("monster3"): case joaat("monster4"): case joaat("monster5"): if (func_69(PLAYER::PLAYER_ID())) { return 1; } break; case joaat("minitank"): case joaat("burrito2"): return 1; } return 0; } int func_69(int iParam0) { if (iParam0 != func_66()) { if (func_65(iParam0, 1, 1)) { if (Global_2425869[iParam0 /*443*/].f_314.f_6 != -1) { return func_64(Global_2425869[iParam0 /*443*/].f_314.f_6) == 13; } } } return 0; } int func_70(int iParam0) { if (iParam0 != func_66()) { if (func_65(iParam0, 1, 1)) { if (Global_2425869[iParam0 /*443*/].f_314.f_6 != -1) { return func_64(Global_2425869[iParam0 /*443*/].f_314.f_6) == 7; } } } return 0; } int func_71(int iParam0) { switch (iParam0) { case joaat("avenger"): case joaat("thruster"): case joaat("riot2"): case joaat("chernobog"): case joaat("khanjali"): return 1; break; } return 0; } int func_72(int iParam0) { if (func_88(PLAYER::PLAYER_ID()) || func_87(PLAYER::PLAYER_ID())) { if (func_73(iParam0)) { return 1; } } return 0; } int func_73(int iParam0) { if ((!ENTITY::DOES_ENTITY_EXIST(iParam0) || !VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) || ENTITY::IS_ENTITY_DEAD(iParam0, false)) { return 0; } if (func_76(iParam0, 0)) { return 1; } if (DECORATOR::DECOR_EXIST_ON(iParam0, "Player_Vehicle")) { if (DECORATOR::DECOR_GET_INT(iParam0, "Player_Vehicle") == NETWORK::NETWORK_HASH_FROM_PLAYER_HANDLE(PLAYER::PLAYER_ID())) { if (func_74(iParam0)) { return 1; } switch (ENTITY::GET_ENTITY_MODEL(iParam0)) { case joaat("ardent"): case joaat("nightshark"): case joaat("deluxo"): case joaat("stromberg"): case joaat("comet4"): case joaat("revolter"): case joaat("savestra"): case joaat("viseris"): case joaat("caracara"): case joaat("paragon2"): return 1; break; } } } return 0; } int func_74(int iParam0) { if (!ENTITY::DOES_ENTITY_EXIST(iParam0) || !VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) { return 0; } if (func_75(ENTITY::GET_ENTITY_MODEL(iParam0))) { return 1; } return 0; } int func_75(int iParam0) { switch (iParam0) { case joaat("apc"): case joaat("dune3"): case joaat("halftrack"): case joaat("oppressor"): case joaat("tampa3"): case joaat("technical3"): case joaat("insurgent3"): case joaat("vigilante"): case joaat("barrage"): case joaat("menacer"): case joaat("scramjet"): return 1; break; } return 0; } int func_76(int iParam0, bool bParam1) { switch (ENTITY::GET_ENTITY_MODEL(iParam0)) { case joaat("technical"): case joaat("insurgent"): if (func_78(ENTITY::GET_ENTITY_MODEL(iParam0), 0)) { if (Global_2540384.f_303 == iParam0) { return 1; } else if (func_77(iParam0) != -1 && !bParam1) { return 1; } } break; } return 0; } int func_77(int iParam0) { int iVar0; if (ENTITY::DOES_ENTITY_EXIST(iParam0)) { iVar0 = 0; while (iVar0 < 32) { if (Global_2440049.f_640[iVar0] == iParam0) { return iVar0; } iVar0++; } } return -1; } int func_78(int iParam0, int iParam1) { if (iParam1 == 0) { if (func_86(iParam0, 0)) { return 1; } } switch (iParam0) { case joaat("faction"): case joaat("buccaneer"): case joaat("chino"): case joaat("moonbeam"): case joaat("primo"): case joaat("voodoo2"): return func_85(); break; case joaat("sabregt"): if (Global_262145.f_14227) { return func_84(); } break; case joaat("tornado"): case joaat("tornado2"): case joaat("tornado3"): if (Global_262145.f_14228) { return func_84(); } break; case joaat("virgo3"): if (Global_262145.f_14226) { return func_84(); } break; case joaat("minivan"): if (Global_262145.f_14229) { return func_84(); } break; case joaat("slamvan"): if (Global_262145.f_14231) { return func_84(); } break; case joaat("sultan"): case joaat("banshee"): return func_83(); break; case joaat("comet2"): if (Global_262145.f_18677) { return func_82(); } break; case joaat("diablous"): if (Global_262145.f_18679) { return func_82(); } break; case joaat("fcr"): if (Global_262145.f_18683) { return func_82(); } break; case joaat("elegy2"): if (Global_262145.f_18680) { return func_82(); } break; case joaat("nero"): if (Global_262145.f_18687) { return func_82(); } break; case joaat("italigtb"): if (Global_262145.f_18685) { return func_82(); } break; case joaat("specter"): if (Global_262145.f_18690) { return func_82(); } break; case joaat("technical"): if (Global_262145.f_20635) { return func_81(); } break; case joaat("insurgent"): if (Global_262145.f_20636) { return func_81(); } break; case joaat("ratloader"): case joaat("ratloader2"): return func_80(); break; case joaat("glendale"): if (func_80() || func_79()) { return 1; } break; case joaat("impaler"): return func_80(); break; case joaat("issi3"): return func_80(); break; case joaat("gargoyle"): return func_80(); break; case joaat("dominator"): return func_80(); break; case joaat("dominator2"): return func_80(); break; case joaat("imperator"): return func_80(); break; case joaat("imperator2"): return func_80(); break; case joaat("imperator3"): return func_80(); break; case joaat("deathbike"): return func_80(); break; case joaat("deathbike2"): return func_80(); break; case joaat("deathbike3"): return func_80(); break; case joaat("impaler2"): case joaat("brutus"): case joaat("bruiser"): case joaat("slamvan4"): case joaat("issi4"): case joaat("monster3"): case joaat("scarab"): case joaat("cerberus"): case joaat("dominator4"): case joaat("zr380"): case joaat("impaler3"): case joaat("brutus2"): case joaat("bruiser2"): case joaat("slamvan5"): case joaat("issi5"): case joaat("monster4"): case joaat("scarab2"): case joaat("cerberus2"): case joaat("dominator5"): case joaat("zr3802"): case joaat("impaler4"): case joaat("brutus3"): case joaat("bruiser3"): case joaat("slamvan6"): case joaat("issi6"): case joaat("monster5"): case joaat("scarab3"): case joaat("cerberus3"): case joaat("dominator6"): case joaat("zr3803"): return func_80(); break; case joaat("youga2"): if (Global_262145.f_28600) { return func_79(); } break; case joaat("gauntlet3"): if (Global_262145.f_28950) { return func_79(); } break; case joaat("manana"): if (Global_262145.f_28599) { return func_79(); } break; case joaat("peyote"): if (Global_262145.f_28949) { return func_79(); } break; case joaat("yosemite"): if (Global_262145.f_28948) { return func_79(); } break; } return 0; } bool func_79() { return DLC::IS_DLC_PRESENT(1815791016); } bool func_80() { return DLC::IS_DLC_PRESENT(1927191088); } bool func_81() { return DLC::IS_DLC_PRESENT(2067165443); } bool func_82() { return DLC::IS_DLC_PRESENT(-957277403); } bool func_83() { return DLC::IS_DLC_PRESENT(210122941); } bool func_84() { return DLC::IS_DLC_PRESENT(-1894522408); } bool func_85() { return DLC::IS_DLC_PRESENT(1630677557); } int func_86(int iParam0, int iParam1) { switch (iParam0) { case joaat("faction2"): case joaat("buccaneer2"): case joaat("chino2"): case joaat("moonbeam2"): case joaat("primo2"): case joaat("voodoo"): return 1; break; case joaat("sabregt2"): if (!Global_262145.f_14227) { return 0; } else { return 1; } break; case joaat("tornado5"): if (!Global_262145.f_14228) { return 0; } else { return 1; } break; case joaat("virgo2"): if (!Global_262145.f_14226) { return 0; } else { return 1; } break; case joaat("minivan2"): if (!Global_262145.f_14229) { return 0; } else { return 1; } break; case joaat("slamvan3"): if (!Global_262145.f_14231) { return 0; } else { return 1; } break; case joaat("faction3"): if (!Global_262145.f_14230) { return 0; } else { return 1; } break; case joaat("sultanrs"): case joaat("banshee2"): if (iParam1 & 1 != 0) { return 0; } return 1; break; case joaat("comet3"): if (Global_262145.f_18677) { if (iParam1 & 1 != 0) { return 0; } return 1; } return 0; break; case joaat("diablous2"): if (Global_262145.f_18679) { if (iParam1 & 1 != 0) { return 0; } return 1; } return 0; break; case joaat("fcr2"): if (Global_262145.f_18683) { if (iParam1 & 1 != 0) { return 0; } return 1; } return 0; break; case joaat("elegy"): if (Global_262145.f_18680) { if (iParam1 & 1 != 0) { return 0; } return 1; } return 0; break; case joaat("nero2"): if (Global_262145.f_18687) { if (iParam1 & 1 != 0) { return 0; } return 1; } return 0; break; case joaat("italigtb2"): if (Global_262145.f_18685) { if (iParam1 & 1 != 0) { return 0; } return 1; } return 0; break; case joaat("specter2"): if (Global_262145.f_18690) { if (iParam1 & 1 != 0) { return 0; } return 1; } return 0; break; case joaat("technical3"): if (Global_262145.f_20635) { if (iParam1 & 1 != 0) { return 0; } return 1; } return 0; break; case joaat("insurgent3"): if (Global_262145.f_20636) { if (iParam1 & 1 != 0) { return 0; } return 1; } return 0; break; case joaat("slamvan4"): case joaat("slamvan5"): case joaat("slamvan6"): if (iParam1 & 1 != 0) { return 0; } return 1; break; case joaat("issi4"): case joaat("issi5"): case joaat("issi6"): if (iParam1 & 1 != 0) { return 0; } return 1; break; case joaat("impaler2"): case joaat("impaler3"): case joaat("impaler4"): if (iParam1 & 1 != 0) { return 0; } return 1; break; case joaat("deathbike"): case joaat("deathbike2"): case joaat("deathbike3"): if (iParam1 & 1 != 0) { return 0; } return 1; break; case joaat("monster3"): case joaat("monster4"): case joaat("monster5"): if (iParam1 & 1 != 0) { return 0; } return 1; break; case joaat("dominator4"): case joaat("dominator5"): case joaat("dominator6"): if (iParam1 & 1 != 0) { return 0; } return 1; break; case joaat("bruiser"): case joaat("bruiser2"): case joaat("bruiser3"): if (iParam1 & 1 != 0) { return 0; } return 1; break; case joaat("youga3"): case joaat("gauntlet5"): case joaat("yosemite3"): if (iParam1 & 1 != 0) { return 0; } return 1; break; case joaat("manana2"): case joaat("peyote3"): case joaat("glendale2"): return 1; break; } return 0; } int func_87(int iParam0) { if (iParam0 != func_66()) { if (func_65(iParam0, 1, 1)) { if (Global_2425869[iParam0 /*443*/].f_314.f_6 != -1 && Global_2425869[iParam0 /*443*/].f_314.f_9 != func_66()) { return func_64(Global_2425869[iParam0 /*443*/].f_314.f_6) == 5; } } } return 0; } int func_88(int iParam0) { if (iParam0 != func_66()) { if (func_65(iParam0, 1, 1)) { if (Global_2425869[iParam0 /*443*/].f_314.f_6 != -1 && Global_2425869[iParam0 /*443*/].f_314.f_9 != func_66()) { return func_64(Global_2425869[iParam0 /*443*/].f_314.f_6) == 8; } } } return 0; } int func_89(int iParam0) { if (iParam0 != func_66()) { if (func_65(iParam0, 1, 1)) { if (Global_2425869[iParam0 /*443*/].f_314.f_6 != -1) { return func_64(Global_2425869[iParam0 /*443*/].f_314.f_6) == 9; } } } return 0; } int func_90(int iParam0, bool bParam1, var uParam2) { bool bVar0; if (!bParam1) { if ((((((((((((((iParam0 == joaat("police") || iParam0 == joaat("policeold1")) || iParam0 == joaat("policeold2")) || iParam0 == joaat("police2")) || iParam0 == joaat("police3")) || iParam0 == joaat("police4")) || iParam0 == joaat("fbi")) || iParam0 == joaat("fbi2")) || iParam0 == joaat("polmav")) || iParam0 == joaat("policeb")) || iParam0 == joaat("policet")) || iParam0 == joaat("riot")) || iParam0 == joaat("sheriff")) || iParam0 == joaat("pranger")) || iParam0 == joaat("sheriff2")) { *uParam2 = 1; return 0; } } if (((((((iParam0 == joaat("ambulance") || iParam0 == joaat("firetruk")) || iParam0 == joaat("taxi")) || iParam0 == joaat("lguard")) || iParam0 == joaat("ripley")) || iParam0 == joaat("dilettante2")) || iParam0 == joaat("airbus")) || iParam0 == joaat("airtug")) { *uParam2 = 2; return 0; } if (((iParam0 == joaat("burrito") || iParam0 == joaat("rumpo2")) || iParam0 == joaat("speedo")) || iParam0 == joaat("speedo2")) { *uParam2 = 2; return 0; } if (((iParam0 == joaat("scorcher") || iParam0 == joaat("bmx")) || iParam0 == joaat("cruiser")) || iParam0 == joaat("fixter")) { *uParam2 = 2; return 0; } if (((((((((((((((((((iParam0 == joaat("caddy") || iParam0 == joaat("forklift")) || iParam0 == joaat("caddy2")) || iParam0 == joaat("crusader")) || iParam0 == joaat("tribike")) || iParam0 == joaat("tribike2")) || iParam0 == joaat("tribike3")) || iParam0 == joaat("tractor")) || iParam0 == joaat("tractor2")) || iParam0 == joaat("mower")) || iParam0 == joaat("tornado4")) || iParam0 == joaat("docktug")) || iParam0 == joaat("stretch")) || iParam0 == joaat("bison2")) || iParam0 == joaat("bison3")) || iParam0 == joaat("benson")) || iParam0 == joaat("pounder")) || iParam0 == joaat("submersible")) || iParam0 == joaat("emperor3")) || iParam0 == joaat("dune2")) { *uParam2 = 2; return 0; } bVar0 = false; if (func_70(PLAYER::PLAYER_ID()) && (VEHICLE::IS_THIS_MODEL_A_HELI(iParam0) || VEHICLE::IS_THIS_MODEL_A_PLANE(iParam0))) { bVar0 = true; } if (((((((((((((!VEHICLE::IS_THIS_MODEL_A_CAR(iParam0) && !VEHICLE::IS_THIS_MODEL_A_BIKE(iParam0)) && iParam0 != joaat("blazer")) && iParam0 != joaat("blazer2")) && iParam0 != joaat("blazer3")) && iParam0 != joaat("blazer4")) && iParam0 != joaat("blazer5")) && iParam0 != joaat("chimera")) && iParam0 != joaat("trailerlarge")) && iParam0 != joaat("trailersmall2")) && iParam0 != joaat("rrocket")) && iParam0 != joaat("stryder")) && iParam0 != joaat("verus")) && !bVar0) { *uParam2 = 2; return 0; } if (iParam0 == joaat("monster")) { *uParam2 = 2; return 0; } if ((iParam0 == joaat("insurgent") || iParam0 == joaat("technical")) || iParam0 == joaat("limo2")) { *uParam2 = 2; return 0; } if (NETWORK::NETWORK_IS_GAME_IN_PROGRESS()) { if (func_91(iParam0)) { *uParam2 = 2; return 0; } } if (!NETWORK::NETWORK_IS_GAME_IN_PROGRESS()) { if (iParam0 == joaat("insurgent") || iParam0 == joaat("insurgent2")) { *uParam2 = 2; } } return 1; } int func_91(int iParam0) { switch (iParam0) { case joaat("towtruck"): case joaat("towtruck2"): case joaat("forklift"): return 1; break; } return 0; } void func_92(int iParam0, int iParam1) { int iVar0; iVar0 = 0; while (iVar0 < 9) { if (!ENTITY::DOES_ENTITY_EXIST(Global_96286[iVar0])) { Global_96286[iVar0] = iParam0; Global_96296[iVar0] = iParam1; Global_96306[iVar0] = ENTITY::GET_ENTITY_MODEL(iParam0); if (VEHICLE::IS_THIS_MODEL_A_CAR(Global_96306[iVar0])) { Global_96334[iParam1 /*3*/][0] = -1; } else { Global_96334[iParam1 /*3*/][1] = -1; } iVar0 = 9; } if (iVar0 == 8) { } iVar0++; } } void func_93(var uParam0) { if (!func_94(*uParam0)) { VEHICLE::SET_VEHICLE_EXTRA(*uParam0, 5, !Global_111858.f_9081.f_99.f_58[119]); } } bool func_94(int iParam0) { return VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(iParam0, 5); } int func_95(var uParam0, var uParam1, var uParam2) { int iVar0; int iVar1; if (!VEHICLE::IS_VEHICLE_DRIVEABLE(*uParam0, false)) { return 0; } if (VEHICLE::GET_NUM_MOD_KITS(*uParam0) == 0) { return 0; } VEHICLE::SET_VEHICLE_MOD_KIT(*uParam0, 0); iVar0 = 0; while (iVar0 < *uParam1) { iVar1 = iVar0; if ((((iVar1 == 17 || iVar1 == 18) || iVar1 == 19) || iVar1 == 20) || iVar1 == 21) { VEHICLE::TOGGLE_VEHICLE_MOD(*uParam0, iVar1, (*uParam1)[iVar0] > 0); } else if (iVar1 == 22) { if ((*uParam1)[iVar0] > 0) { VEHICLE::TOGGLE_VEHICLE_MOD(*uParam0, iVar1, true); if ((*uParam1)[iVar0] == 1) { VEHICLE::_SET_VEHICLE_XENON_LIGHTS_COLOR(*uParam0, 255); } else { VEHICLE::_SET_VEHICLE_XENON_LIGHTS_COLOR(*uParam0, ((*uParam1)[iVar0] - 2)); } } else { VEHICLE::TOGGLE_VEHICLE_MOD(*uParam0, iVar1, false); } } else if (VEHICLE::GET_VEHICLE_MOD(*uParam0, iVar1) != ((*uParam1)[iVar0] - 1)) { VEHICLE::REMOVE_VEHICLE_MOD(*uParam0, iVar1); if ((*uParam1)[iVar0] > 0) { if (iVar0 == 23) { VEHICLE::SET_VEHICLE_MOD(*uParam0, iVar1, ((*uParam1)[iVar0] - 1), (*uParam2)[0] > 0); } else if (iVar0 == 24) { VEHICLE::SET_VEHICLE_MOD(*uParam0, iVar1, ((*uParam1)[iVar0] - 1), (*uParam2)[1] > 0); } else { VEHICLE::SET_VEHICLE_MOD(*uParam0, iVar1, ((*uParam1)[iVar0] - 1), false); } } } iVar0++; } if (func_86(ENTITY::GET_ENTITY_MODEL(*uParam0), 1) && VEHICLE::GET_VEHICLE_MOD(*uParam0, 24) != func_98(*uParam0, ((*uParam1)[38] - 1))) { VEHICLE::SET_VEHICLE_MOD(*uParam0, 24, func_98(*uParam0, ((*uParam1)[38] - 1)), false); } func_97(uParam0); if (func_96(*uParam0)) { VEHICLE::SET_VEHICLE_STRONG(*uParam0, true); VEHICLE::SET_VEHICLE_HAS_STRONG_AXLES(*uParam0, true); } return 1; } int func_96(int iParam0) { int iVar0; int iVar1; int iVar2; char cVar3[32]; if ((ENTITY::DOES_ENTITY_EXIST(iParam0) && VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) && VEHICLE::GET_NUM_MOD_KITS(iParam0) > 0) { VEHICLE::SET_VEHICLE_MOD_KIT(iParam0, 0); iVar0 = 0; while (iVar0 < 49) { iVar1 = iVar0; if (((((iVar1 == 17 || iVar1 == 18) || iVar1 == 19) || iVar1 == 20) || iVar1 == 21) || iVar1 == 22) { } else if (VEHICLE::GET_VEHICLE_MOD(iParam0, iVar1) != -1) { StringCopy(&cVar3, VEHICLE::GET_MOD_TEXT_LABEL(iParam0, iVar1, VEHICLE::GET_VEHICLE_MOD(iParam0, iVar1)), 32); iVar2 = MISC::GET_HASH_KEY(&cVar3); if (iVar2 != 0) { if (iVar2 == MISC::GET_HASH_KEY("MNU_CAGE") || iVar2 == MISC::GET_HASH_KEY("SABRE_CAG")) { return 1; } } } iVar0++; } } return 0; } void func_97(var uParam0) { switch (ENTITY::GET_ENTITY_MODEL(*uParam0)) { case joaat("starling"): if (VEHICLE::GET_VEHICLE_MOD(*uParam0, 4) == 0) { VEHICLE::SET_VEHICLE_MOD(*uParam0, 13, 0, false); } else { VEHICLE::REMOVE_VEHICLE_MOD(*uParam0, 13); } break; } } int func_98(int iParam0, int iParam1) { int iVar0; int iVar1; float fVar2; int iVar3; if (ENTITY::DOES_ENTITY_EXIST(iParam0) && VEHICLE::IS_VEHICLE_DRIVEABLE(iParam0, false)) { switch (ENTITY::GET_ENTITY_MODEL(iParam0)) { case joaat("tornado5"): switch (iParam1) { case 0: return 0; break; case 1: return 1; break; case 2: return 2; break; case 3: return 3; break; case 4: return 4; break; case 5: return 4; break; } break; case joaat("faction3"): return 3; break; } iVar0 = VEHICLE::GET_NUM_VEHICLE_MODS(iParam0, 38); iVar1 = VEHICLE::GET_NUM_VEHICLE_MODS(iParam0, 24); fVar2 = (SYSTEM::TO_FLOAT(iParam1 + 1) / SYSTEM::TO_FLOAT(iVar0)); iVar3 = (SYSTEM::FLOOR((SYSTEM::TO_FLOAT(iVar1) * fVar2)) - 1); if (iVar3 < 0) { iVar3 = 0; } if (iVar3 >= iVar0) { iVar3 = (iVar0 - 1); } return iVar3; } return 0; } int func_99(var uParam0, int iParam1) { if (NETWORK::NETWORK_IS_GAME_IN_PROGRESS()) { } else if (Global_111858.f_20114.f_261) { *uParam0 = { Global_111858.f_20114.f_267 }; *iParam1 = Global_111858.f_20114.f_271; return 1; } return 0; } int func_100(int iParam0, int iParam1) { if (func_2(iParam0)) { return STREAMING::HAS_MODEL_LOADED(func_41(iParam0, iParam1)); } else if (iParam0 != 145) { } return 0; } int func_101(int iParam0, int iParam1, int iParam2, int iParam3, int iParam4, int iParam5, int iParam6, int iParam7, int iParam8, int iParam9, int iParam10, int iParam11, int iParam12, int iParam13) { int iVar0; int iVar1; int iVar2; int iVar3; int iVar4; int iVar5; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; var uVar11; var uVar28; var uVar38; struct<14> Var55; var uVar69; if (PED::IS_PED_INJURED(iParam0) || iParam2 == -99) { return 0; } Global_76645++; iVar5 = -99; iVar6 = -99; iVar7 = -99; iVar8 = -99; iVar9 = -99; iVar10 = ENTITY::GET_ENTITY_MODEL(iParam0); if (iParam5 == 0) { Global_76647[1 /*14*/] = { func_153(iVar10, iParam1, iParam2, -1) }; if (!func_152(iParam3)) { Global_76645 = (Global_76645 - 1); return 0; } func_144(iParam1); } if (iParam1 == 12) { if (iParam7 == 1) { if (iVar10 == joaat("player_one")) { iVar5 = func_142(iParam0, 8); if (iVar5 != 9) { iVar5 = -99; } } iVar6 = func_142(iParam0, 9); if (iVar10 == joaat("player_zero")) { if (iVar6 >= 9 && iVar6 <= 14) { } else { iVar6 = -99; } } else if (iVar10 == joaat("player_one")) { if (iVar6 >= 5 && iVar6 <= 10) { } else { iVar6 = -99; } } else if (iVar10 == joaat("player_two")) { if ((iVar6 >= 9 && iVar6 <= 14) || (iVar6 >= 15 && iVar6 <= 16)) { } else { iVar6 = -99; } } iVar7 = func_141(iParam0, 1); if (!func_140(iVar10, 14, iVar7, -1)) { iVar7 = -99; } iVar8 = func_141(iParam0, 0); if (!func_139(iVar10, 14, iVar8, -1) && !func_138(iVar10, 14, iVar8, -1)) { iVar8 = -99; } if (iVar10 == joaat("player_one")) { iVar9 = func_141(iParam0, 2); } } PED::CLEAR_ALL_PED_PROPS(iParam0); uVar11 = 15; if (iParam5 == 1) { uVar11 = { Global_76690 }; } else { uVar11 = { func_134(iVar10, iParam2) }; } iVar0 = 0; while (iVar0 <= 14) { if (uVar11[iVar0] != -99) { Global_76647[1 /*14*/] = { func_153(iVar10, iVar0, uVar11[iVar0], -1) }; if (MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 0)) { if (iVar0 == 13) { uVar28 = 9; if (iParam5 == 1) { uVar28 = { Global_76707 }; } else { uVar28 = { func_131(iVar10, uVar11[iVar0]) }; } iVar1 = 0; while (iVar1 <= 8) { Global_76647[1 /*14*/] = { func_153(iVar10, 14, uVar28[iVar1], -1) }; func_122(iParam0, Global_76647[1 /*14*/].f_12, Global_76647[1 /*14*/].f_3, Global_76647[1 /*14*/].f_4); func_144(14); if (Global_76645 == 1) { iVar2 = 0; while (iVar2 < 15) { iVar3 = func_114(iParam0, iVar10, 14, uVar28[iVar1], iVar2, 0); if (iVar3 != -99) { func_101(iParam0, iVar2, iVar3, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0); } iVar2++; } } iVar1++; } } else if (iVar0 != 14 && iVar0 != 12) { if ((iVar10 == joaat("player_one") && iVar0 == 2) && uVar11[iVar0] == 20) { func_113(iVar10, 2, 20, &iVar4); } if (iParam4 == -1) { PED::SET_PED_COMPONENT_VARIATION(iParam0, func_112(iVar0), Global_76647[1 /*14*/].f_3, Global_76647[1 /*14*/].f_4, PED::GET_PED_PALETTE_VARIATION(iParam0, func_112(iVar0))); } else { PED::SET_PED_COMPONENT_VARIATION(iParam0, func_112(iVar0), Global_76647[1 /*14*/].f_3, Global_76647[1 /*14*/].f_4, iParam4); } func_144(iVar0); if (Global_76645 == 1) { iVar2 = 0; while (iVar2 < 15) { iVar3 = func_114(iParam0, iVar10, iVar0, uVar11[iVar0], iVar2, 0); if (iVar3 != -99) { func_101(iParam0, iVar2, iVar3, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0); } iVar2++; } } } } } else if (iVar0 != 12 && iVar0 != 14) { Global_76647[1 /*14*/] = { func_153(iVar10, iVar0, func_111(iParam0, iVar0, -1), -1) }; if (MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 3)) { if (iVar0 == 2) { if (iVar10 == joaat("player_one")) { if (func_110(iParam0, iVar10, &iVar4, 1)) { func_101(iParam0, 2, iVar4, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0); } } } else { uVar38 = { func_134(iVar10, 0) }; func_101(iParam0, iVar0, uVar38[iVar0], 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0); } } } iVar0++; } if (iParam7 == 1) { Var55 = { func_153(iVar10, 8, iVar5, -1) }; if (iVar5 != -99) { if (func_108(iVar10, iParam2, 8, iVar5, &uVar11, &Var55)) { func_101(iParam0, 8, iVar5, iParam3, iParam4, iParam5, iParam6, iParam7, -1, -1, -1, 0, 0, 0); } } Var55 = { func_153(iVar10, 9, iVar6, -1) }; if (iVar6 != -99) { if (func_108(iVar10, iParam2, 9, iVar6, &uVar11, &Var55)) { func_101(iParam0, 9, iVar6, iParam3, iParam4, iParam5, iParam6, iParam7, -1, -1, -1, 0, 0, 0); } } Var55 = { func_153(iVar10, 14, iVar7, -1) }; if (iVar7 != -99) { if (func_108(iVar10, iParam2, 14, iVar7, &uVar11, &Var55)) { func_101(iParam0, 14, iVar7, iParam3, iParam4, iParam5, iParam6, iParam7, -1, -1, -1, 0, 0, 0); } } Var55 = { func_153(iVar10, 14, iVar8, -1) }; if (iVar8 != -99) { if (func_108(iVar10, iParam2, 14, iVar8, &uVar11, &Var55)) { func_101(iParam0, 14, iVar8, iParam3, iParam4, iParam5, iParam6, iParam7, -1, -1, -1, 0, 0, 0); } } Var55 = { func_153(iVar10, 14, iVar9, -1) }; if (iVar9 != -99) { if (func_108(iVar10, iParam2, 14, iVar9, &uVar11, &Var55)) { func_101(iParam0, 14, iVar9, iParam3, iParam4, iParam5, iParam6, iParam7, -1, -1, -1, 0, 0, 0); } } } } else if (iParam1 == 13) { uVar69 = { func_131(iVar10, iParam2) }; iVar1 = 0; while (iVar1 <= 8) { Global_76647[1 /*14*/] = { func_153(iVar10, 14, uVar69[iVar1], -1) }; func_122(iParam0, Global_76647[1 /*14*/].f_12, Global_76647[1 /*14*/].f_3, Global_76647[1 /*14*/].f_4); func_144(14); if (Global_76645 == 1) { iVar2 = 0; while (iVar2 < 15) { iVar3 = func_114(iParam0, iVar10, 14, uVar69[iVar1], iVar2, 0); if (iVar3 != -99) { func_101(iParam0, iVar2, iVar3, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0); } iVar2++; } } iVar1++; } } else if (iParam1 == 14) { func_122(iParam0, Global_76647[1 /*14*/].f_12, Global_76647[1 /*14*/].f_3, Global_76647[1 /*14*/].f_4); func_144(iParam1); if (Global_76645 == 1) { iVar2 = 0; while (iVar2 < 15) { iVar3 = func_114(iParam0, iVar10, iParam1, iParam2, iVar2, 0); if (iVar3 != -99) { func_101(iParam0, iVar2, iVar3, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0); } iVar2++; } } } else { if (iParam4 == -1) { PED::SET_PED_COMPONENT_VARIATION(iParam0, func_112(iParam1), Global_76647[1 /*14*/].f_3, Global_76647[1 /*14*/].f_4, PED::GET_PED_PALETTE_VARIATION(iParam0, func_112(iParam1))); } else { PED::SET_PED_COMPONENT_VARIATION(iParam0, func_112(iParam1), Global_76647[1 /*14*/].f_3, Global_76647[1 /*14*/].f_4, iParam4); } if (Global_76645 == 1) { iVar2 = 0; while (iVar2 < 15) { iVar3 = func_114(iParam0, iVar10, iParam1, iParam2, iVar2, 0); if (iVar3 != -99) { func_101(iParam0, iVar2, iVar3, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0); } iVar2++; } } if (iParam6 == 0) { func_105(iVar10, iParam1, iParam2); } } if (Global_76645 == 1) { if (func_110(iParam0, iVar10, &iVar4, 0)) { func_101(iParam0, 2, iVar4, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0); } if (func_102(iParam0, iVar10, &iVar4)) { func_101(iParam0, 1, iVar4, 0, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0); } } Global_76645 = (Global_76645 - 1); return 1; } int func_102(int iParam0, int iParam1, int iParam2) { int iVar0; iVar0 = func_104(iParam1); if (Global_111858.f_2359.f_539[iVar0 /*65*/].f_63 != -99) { if (!func_103(iParam0, Global_111858.f_2359.f_539[iVar0 /*65*/].f_64, Global_111858.f_2359.f_539[iVar0 /*65*/].f_63)) { *iParam2 = Global_111858.f_2359.f_539[iVar0 /*65*/].f_62; Global_111858.f_2359.f_539[iVar0 /*65*/].f_63 = -99; Global_111858.f_2359.f_539[iVar0 /*65*/].f_64 = 1; return 1; } } return 0; } int func_103(int iParam0, int iParam1, int iParam2) { int iVar0; int iVar1; int iVar2; int iVar3; int iVar4; var uVar5; var uVar22; int iVar32; var uVar33; if (PED::IS_PED_INJURED(iParam0)) { return 0; } iVar0 = ENTITY::GET_ENTITY_MODEL(iParam0); Global_76647[1 /*14*/] = { func_153(iVar0, iParam1, iParam2, -1) }; if (!MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 0)) { return 0; } if (iParam1 == 12) { uVar5 = { func_134(iVar0, iParam2) }; iVar2 = 0; while (iVar2 <= 14) { if ((uVar5[iVar2] != -99 && iVar2 != 12) && iVar2 != 14) { if (!func_103(iParam0, iVar2, uVar5[iVar2])) { if (iVar2 == 13) { uVar22 = { func_131(iVar0, uVar5[iVar2]) }; iVar3 = 0; while (iVar3 <= 8) { if (!func_103(iParam0, 14, uVar22[iVar3])) { iVar4 = 0; while (iVar4 <= 19) { Global_76647[2 /*14*/] = { func_153(iVar0, 14, iVar4, -1) }; if (Global_76647[2 /*14*/].f_12 == iVar3) { if (func_103(iParam0, 14, iVar4)) { if (!func_108(iVar0, iParam2, 14, iVar4, &uVar5, &(Global_76647[2 /*14*/]))) { return 0; } } } iVar4++; } } iVar3++; } } else { iVar1 = func_142(iParam0, iVar2); Global_76647[2 /*14*/] = { func_153(iVar0, iVar2, iVar1, -1) }; if (!func_108(iVar0, iParam2, iVar2, iVar1, &uVar5, &(Global_76647[2 /*14*/]))) { return 0; } } } } iVar2++; } return 1; } else if (iParam1 == 13) { uVar33 = { func_131(iVar0, iParam2) }; iVar32 = 0; while (iVar32 <= 8) { if (!func_103(iParam0, 14, uVar33[iVar32])) { return 0; } iVar32++; } return 1; } else if (iParam1 == 14) { if (PED::GET_PED_PROP_INDEX(iParam0, Global_76647[1 /*14*/].f_12) == Global_76647[1 /*14*/].f_3 && (PED::GET_PED_PROP_TEXTURE_INDEX(iParam0, Global_76647[1 /*14*/].f_12) == Global_76647[1 /*14*/].f_4 || Global_76647[1 /*14*/].f_3 == -1)) { return 1; } } else if (Global_76647[1 /*14*/].f_3 == PED::GET_PED_DRAWABLE_VARIATION(iParam0, func_112(iParam1)) && Global_76647[1 /*14*/].f_4 == PED::GET_PED_TEXTURE_VARIATION(iParam0, func_112(iParam1))) { return 1; } return 0; } int func_104(int iParam0) { switch (iParam0) { case joaat("player_zero"): return 0; break; case joaat("player_one"): return 1; break; case joaat("player_two"): return 2; break; default: break; } return 145; } void func_105(int iParam0, int iParam1, int iParam2) { int iVar0; int iVar1; if (iParam0 == joaat("player_zero")) { iVar0 = 5; } else if (iParam0 == joaat("player_one")) { iVar0 = 2; } else if (iParam0 == joaat("player_two")) { iVar0 = 4; } if (func_107(iParam0, 12, iVar0)) { if (func_106(iParam0, iParam1, iParam2)) { iVar1 = func_104(iParam0); if (iParam1 == 3) { Global_111858.f_2359.f_539.f_196[iVar1] = iParam2; } else if (iParam1 == 4) { Global_111858.f_2359.f_539.f_200[iVar1] = iParam2; } } } } int func_106(int iParam0, int iParam1, int iParam2) { if (iParam0 == joaat("player_zero")) { if (iParam1 == 4) { if (iParam2 >= 47 && iParam2 <= 54) { return 1; } } else if (iParam1 == 3) { if (iParam2 >= 77 && iParam2 <= 84) { return 1; } } } else if (iParam0 == joaat("player_one")) { if (iParam1 == 4) { if (iParam2 >= 14 && iParam2 <= 21) { return 1; } } else if (iParam1 == 3) { if (iParam2 >= 41 && iParam2 <= 56) { return 1; } } } else if (iParam0 == joaat("player_two")) { if (iParam1 == 4) { if (iParam2 >= 18 && iParam2 <= 29) { return 1; } } else if (iParam1 == 3) { if (iParam2 >= 54 && iParam2 <= 69) { return 1; } } } return 0; } bool func_107(int iParam0, int iParam1, int iParam2) { Global_76647[1 /*14*/] = { func_153(iParam0, iParam1, iParam2, -1) }; return MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 2); } int func_108(int iParam0, int iParam1, int iParam2, int iParam3, var uParam4, var uParam5) { var uVar0; int iVar10; if ((*uParam4)[iParam2] == iParam3) { return 1; } if (((*uParam4)[iParam2] == -99 && iParam2 != 14) && iParam2 != 13) { return 1; } if (iParam2 == 13 || (iParam2 == 14 && (*uParam4)[13] == 31)) { if ((((((((iParam3 == 0 || iParam3 == 1) || iParam3 == 2) || iParam3 == 3) || iParam3 == 4) || iParam3 == 5) || iParam3 == 6) || iParam3 == 7) || iParam3 == 8) { return 1; } } if (iParam3 == -99 || uParam5->f_1 == -1) { return 1; } if (iParam2 == 14) { uVar0 = { func_131(iParam0, (*uParam4)[13]) }; iVar10 = 0; while (iVar10 <= 8) { if (uVar0[iVar10] == iParam3) { return 1; } iVar10++; } } if (func_109(iParam0, iParam2, iParam3)) { return 1; } if (iParam0 == joaat("player_zero")) { if (func_140(iParam0, iParam2, iParam3, -1)) { if ((((((iParam1 == 1 || iParam1 == 2) || iParam1 == 10) || iParam1 == 11) || iParam1 == 12) || iParam1 == 18) || iParam1 == 50) { return 0; } return 1; } else if (func_139(iParam0, iParam2, iParam3, -1)) { if (((((((((iParam1 == 1 || iParam1 == 2) || iParam1 == 4) || iParam1 == 5) || iParam1 == 10) || iParam1 == 11) || iParam1 == 12) || iParam1 == 14) || iParam1 == 18) || iParam1 == 50) { return 0; } if (iParam2 == 8) { if ((*uParam4)[8] != 0) { return 0; } } else if (iParam2 == 9) { if ((*uParam4)[9] != 0) { return 0; } } return 1; } else if (func_138(iParam0, iParam2, iParam3, -1)) { if (((((((((iParam1 == 1 || iParam1 == 2) || iParam1 == 4) || iParam1 == 5) || iParam1 == 10) || iParam1 == 11) || iParam1 == 12) || iParam1 == 14) || iParam1 == 18) || iParam1 == 50) { return 0; } return 1; } } else if (iParam0 == joaat("player_one")) { if (func_140(iParam0, iParam2, iParam3, -1)) { if ((iParam1 == 3 || iParam1 == 5) || iParam1 == 7) { return 0; } return 1; } else if (func_139(iParam0, iParam2, iParam3, -1)) { if ((((iParam1 == 3 || iParam1 == 5) || iParam1 == 7) || iParam1 == 8) || iParam1 == 21) { if (iParam2 == 8) { if (iParam3 == 9) { if (iParam1 == 8 || iParam1 == 21) { return 1; } } else { return 0; } } else { return 0; } } if (iParam2 == 8) { if ((*uParam4)[8] != 26) { return 0; } } else if (iParam2 == 9) { if ((*uParam4)[9] != 0) { return 0; } if (((iParam1 == 43 || iParam1 == 44) || iParam1 == 45) || iParam1 == 46) { if (iParam3 >= 5 && iParam3 <= 10) { return 0; } } } else if (iParam2 == 14) { if (((iParam1 == 43 || iParam1 == 44) || iParam1 == 45) || iParam1 == 46) { if (iParam3 >= 26 && iParam3 <= 39) { return 0; } } } return 1; } else if (func_138(iParam0, iParam2, iParam3, -1)) { if (((((iParam1 == 3 || iParam1 == 3) || iParam1 == 5) || iParam1 == 7) || iParam1 == 8) || iParam1 == 21) { return 0; } return 1; } else if (iParam2 == 14) { if (iParam3 >= 159 && iParam3 <= 174) { return 1; } } } else if (iParam0 == joaat("player_two")) { if (iParam1 == 2) { if (iParam2 == 14 && iParam3 == 0) { return 1; } } if (func_140(iParam0, iParam2, iParam3, -1)) { if (((((iParam1 == 1 || iParam1 == 2) || iParam1 == 6) || iParam1 == 8) || iParam1 == 45) || iParam1 == 12) { return 0; } return 1; } else if (func_139(iParam0, iParam2, iParam3, -1)) { if (((((((iParam1 == 1 || iParam1 == 2) || iParam1 == 3) || iParam1 == 6) || iParam1 == 8) || iParam1 == 11) || iParam1 == 45) || iParam1 == 12) { return 0; } if (iParam2 == 8) { if ((*uParam4)[8] != 15) { return 0; } } else if (iParam2 == 9) { if ((*uParam4)[9] != 0) { return 0; } } return 1; } else if (func_138(iParam0, iParam2, iParam3, -1)) { if ((((((iParam1 == 1 || iParam1 == 2) || iParam1 == 3) || iParam1 == 6) || iParam1 == 8) || iParam1 == 11) || iParam1 == 12) { return 0; } return 1; } } return 0; } int func_109(int iParam0, int iParam1, int iParam2) { switch (iParam0) { case joaat("player_zero"): switch (iParam1) { case 8: if (iParam2 == 15) { return 1; } break; case 9: if (iParam2 == 6) { return 1; } break; } break; case joaat("player_one"): switch (iParam1) { case 8: if (iParam2 == 1 || iParam2 == 10) { return 1; } break; } break; case joaat("player_two"): switch (iParam1) { case 8: if (iParam2 == 4) { return 1; } break; } break; } return 0; } int func_110(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; iVar0 = func_104(iParam1); if (Global_111858.f_2359.f_539[iVar0 /*65*/].f_60 != -99) { if (!func_103(iParam0, Global_111858.f_2359.f_539[iVar0 /*65*/].f_61, Global_111858.f_2359.f_539[iVar0 /*65*/].f_60) || iParam3 == 1) { *iParam2 = Global_111858.f_2359.f_539[iVar0 /*65*/].f_59; Global_111858.f_2359.f_539[iVar0 /*65*/].f_60 = -99; Global_111858.f_2359.f_539[iVar0 /*65*/].f_61 = 2; return 1; } } return 0; } int func_111(int iParam0, int iParam1, int iParam2) { int iVar0; int iVar1; if (!PED::IS_PED_INJURED(iParam0)) { if (iParam1 == 12) { iVar0 = 0; while (iVar0 <= 53) { if (func_103(iParam0, iParam1, iVar0)) { return iVar0; } iVar0++; } } else if (iParam1 == 13) { iVar1 = 0; while (iVar1 <= 19) { if (func_103(iParam0, iParam1, iVar1)) { return iVar1; } iVar1++; } return 31; } else if (iParam1 == 14) { if (iParam2 == -1) { } else { return func_141(iParam0, iParam2); } } else { return func_142(iParam0, iParam1); } } return -99; } int func_112(int iParam0) { switch (iParam0) { case 0: return 0; break; case 2: return 2; break; case 3: return 3; break; case 4: return 4; break; case 6: return 6; break; case 5: return 5; break; case 8: return 8; break; case 9: return 9; break; case 10: return 10; break; case 1: return 1; break; case 7: return 7; break; case 11: return 11; break; } return 0; } int func_113(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; *iParam3 = -99; switch (iParam0) { case joaat("player_zero"): switch (iParam1) { case 8: if (iParam2 == 7 || iParam2 == 23) { *iParam3 = 1; } break; case 9: if (iParam2 == 8 || (iParam2 >= 9 && iParam2 <= 14)) { *iParam3 = 1; } break; case 10: if (iParam2 >= 44 && iParam2 <= 47) { *iParam3 = 1; } break; case 14: if ((((((iParam2 >= 31 && iParam2 <= 32) || (iParam2 >= 33 && iParam2 <= 34)) || (iParam2 >= 35 && iParam2 <= 36)) || iParam2 == 37) || (iParam2 >= 40 && iParam2 <= 41)) || iParam2 == 46) { *iParam3 = 1; } break; } break; case joaat("player_one"): switch (iParam1) { case 2: if (iParam2 == 20) { *iParam3 = 20; } break; case 8: if (iParam2 == 4) { *iParam3 = 19; } break; case 9: if (iParam2 >= 5 && iParam2 <= 10) { *iParam3 = 19; } break; case 10: if (iParam2 >= 47 && iParam2 <= 50) { *iParam3 = 19; } break; case 14: if (((((iParam2 >= 26 && iParam2 <= 27) || (iParam2 >= 28 && iParam2 <= 29)) || (iParam2 >= 30 && iParam2 <= 31)) || iParam2 == 32) || (iParam2 >= 35 && iParam2 <= 36)) { *iParam3 = 19; } break; } break; case joaat("player_two"): switch (iParam1) { case 8: if (iParam2 == 7) { *iParam3 = 2; } break; case 9: if ((iParam2 >= 9 && iParam2 <= 14) || (iParam2 >= 15 && iParam2 <= 16)) { *iParam3 = 2; } break; case 10: if (iParam2 >= 29 && iParam2 <= 32) { *iParam3 = 2; } break; case 14: if ((((((iParam2 >= 47 && iParam2 <= 48) || (iParam2 >= 49 && iParam2 <= 50)) || (iParam2 >= 51 && iParam2 <= 52)) || iParam2 == 53) || (iParam2 >= 56 && iParam2 <= 57)) || iParam2 == 62) { *iParam3 = 2; } break; } break; } if (*iParam3 != -99) { iVar0 = func_104(iParam0); Global_111858.f_2359.f_539[iVar0 /*65*/].f_60 = iParam2; Global_111858.f_2359.f_539[iVar0 /*65*/].f_61 = iParam1; return 1; } return 0; } int func_114(int iParam0, int iParam1, int iParam2, int iParam3, int iParam4, int iParam5) { int iVar0; int iVar1; int iVar2; int iVar3; int iVar4; int iVar5; int iVar6; int iVar7; int iVar8; int iVar9; iVar0 = -99; if (iParam4 == 0) { switch (iParam2) { case 2: iVar1 = func_142(iParam0, 1); iVar0 = func_121(iParam1, iParam3, iVar1); break; case 1: iVar2 = func_142(iParam0, 2); iVar0 = func_121(iParam1, iVar2, iParam3); break; } } else if (iParam4 == 2) { func_113(iParam1, iParam2, iParam3, &iVar0); } else if (iParam4 == 1) { func_120(iParam1, iParam2, iParam3, &iVar0); } else if (iParam4 == 6) { if (iParam2 == 4) { if (func_119(iParam1, iParam3, &iVar0)) { } } } else { switch (iParam1) { case joaat("player_zero"): switch (iParam4) { case 3: switch (iParam2) { case 10: switch (iParam3) { case 36: iVar0 = 17; break; case 37: iVar0 = 17; break; case 38: iVar0 = 18; break; case 39: iVar0 = 18; break; case 40: iVar0 = 19; break; case 41: iVar0 = 19; break; case 42: iVar0 = 20; break; case 43: iVar0 = 20; break; } break; case 11: if (iParam3 >= 2 && iParam3 <= 7) { if (!func_118(iParam0, 3, 44, 59)) { iVar0 = 44; } } else if (((iParam3 >= 8 && iParam3 <= 17) || (iParam3 >= 18 && iParam3 <= 27)) || (iParam3 >= 28 && iParam3 <= 43)) { if (!func_118(iParam0, 3, 135, 150)) { iVar0 = func_117(iParam1, 3, 135, 150); } } break; } break; case 10: switch (iParam2) { case 3: switch (iParam3) { case 63: iVar0 = 4; break; case 61: iVar0 = 3; break; case 16: iVar0 = 1; break; case 114: iVar0 = 15; break; case 115: iVar0 = 17; break; case 116: iVar0 = 16; break; case 117: iVar0 = 18; break; case 118: iVar0 = 20; break; case 119: iVar0 = 19; break; case 125: iVar0 = 21; break; case 120: iVar0 = 22; break; case 124: iVar0 = 23; break; case 126: iVar0 = 24; break; case 121: iVar0 = 25; break; case 127: iVar0 = 26; break; case 128: iVar0 = 27; break; case 85: iVar0 = 6; break; case 77: iVar0 = 7; break; case 78: iVar0 = 8; break; case joaat("MPSV_LP0_31"): iVar0 = 9; break; case 80: iVar0 = 10; break; case 81: iVar0 = 11; break; case 82: iVar0 = 12; break; case 83: iVar0 = 13; break; case 84: iVar0 = 14; break; case 21: iVar0 = 31; break; case 22: iVar0 = 30; break; case 23: iVar0 = 29; break; case 24: iVar0 = 28; break; case 25: iVar0 = 33; break; case 26: iVar0 = 35; break; case 27: iVar0 = 34; break; case 28: iVar0 = 32; break; default: if (iParam3 >= 17 && iParam3 <= 20) { } else { iVar0 = 0; } break; } break; case 11: if (iParam3 != 0) { iVar0 = 0; } break; } break; case 11: if (iParam2 == 3) { if ((iParam3 >= 44 && iParam3 <= 59) || (iParam3 >= 135 && iParam3 <= 150)) { } else { iVar0 = 0; } } else if (iParam2 == 10) { if (iParam3 >= 36 && iParam3 <= 43) { iVar0 = 0; } } break; } break; case joaat("player_one"): switch (iParam4) { case 10: switch (iParam2) { case 3: switch (iParam3) { case 17: iVar0 = 2; break; case 90: iVar0 = 1; break; case 268: iVar0 = 3; break; case 269: iVar0 = 5; break; case 270: iVar0 = 4; break; case 271: iVar0 = 6; break; case 272: iVar0 = 8; break; case 273: iVar0 = 7; break; case 279: iVar0 = 9; break; case 274: iVar0 = 10; break; case 278: iVar0 = 11; break; case 280: iVar0 = 12; break; case 275: iVar0 = 13; break; case 281: iVar0 = 14; break; case 282: iVar0 = 15; break; case 107: iVar0 = 16; break; case 108: iVar0 = 17; break; case 109: iVar0 = 18; break; case 110: iVar0 = 19; break; case 111: iVar0 = 20; break; case 112: iVar0 = 21; break; case 113: iVar0 = 22; break; case 114: iVar0 = 23; break; case 115: iVar0 = 24; break; case 116: iVar0 = 25; break; case 117: iVar0 = 52; break; case 118: iVar0 = 27; break; case 119: iVar0 = 28; break; case 120: iVar0 = 29; break; case 121: iVar0 = 30; break; case 122: iVar0 = 31; break; case 296: iVar0 = 32; break; case 297: iVar0 = 33; break; case 298: iVar0 = 34; break; case 299: iVar0 = 35; break; case 300: iVar0 = 36; break; case 301: iVar0 = 37; break; case 302: iVar0 = 38; break; case 309: iVar0 = 39; break; case 310: iVar0 = 40; break; case 311: iVar0 = 41; break; case 312: iVar0 = 42; break; case 313: iVar0 = 43; break; case 314: iVar0 = 44; break; case 315: iVar0 = 45; break; case 316: iVar0 = 46; break; case 317: iVar0 = 51; break; default: iVar0 = 0; break; } break; case 11: if (iParam3 != 0) { iVar0 = 0; } break; } break; case 3: switch (iParam2) { case 11: if (iParam3 >= 47 && iParam3 <= 62) { if (!func_118(iParam0, 3, 209, 222)) { iVar0 = func_117(iParam1, 3, 209, 222); } } else if ((iParam3 >= 1 && iParam3 <= 4) || (iParam3 >= 5 && iParam3 <= 8)) { if (!func_118(iParam0, 3, 243, 258)) { if (iParam3 == 1 || iParam3 == 5) { iVar0 = func_117(iParam1, 3, 243, 246); } else if (iParam3 == 2 || iParam3 == 6) { iVar0 = func_117(iParam1, 3, 247, 250); } else if (iParam3 == 3 || iParam3 == 7) { iVar0 = func_117(iParam1, 3, 251, 254); } else if (iParam3 == 4 || iParam3 == 8) { iVar0 = func_117(iParam1, 3, 255, 258); } } } else if (iParam3 == 41 || iParam3 == 42) { if (!func_118(iParam0, 3, 176, 191) && !func_118(iParam0, 3, 227, 242)) { iVar0 = func_117(iParam1, 3, 176, 191); } } break; } break; case 8: if (iParam2 == 11 || iParam2 == 3) { if (iParam2 == 11) { iVar5 = iParam3; iVar4 = func_142(iParam0, 3); } else if (iParam2 == 3) { iVar4 = iParam3; iVar5 = func_142(iParam0, 11); iVar5 = func_116(iParam1, iVar4, iVar5, 0); } iVar3 = func_142(iParam0, 8); if (((iVar5 >= 5 && iVar5 <= 8) || (iVar5 >= 25 && iVar5 <= 40)) || (iVar5 >= 42 && iVar5 <= 43)) { if (!func_115(joaat("player_one"), iVar3, iVar5, iVar4, &iVar6)) { if (iVar6 != -99) { iVar0 = iVar6; } } } else if (((iVar3 >= 27 && iVar3 <= 42) || (iVar3 >= 43 && iVar3 <= 58)) || (iVar3 >= 59 && iVar3 <= 74)) { iVar0 = 26; } } break; case 11: if (iParam2 == 3) { if (iParam3 >= 209 && iParam3 <= 222) { } else if (((iParam3 >= 176 && iParam3 <= 191) || (iParam3 >= 227 && iParam3 <= 242)) || (iParam3 >= 243 && iParam3 <= 258)) { iVar7 = func_142(iParam0, 8); iVar8 = func_142(iParam0, 11); if (((iVar7 >= 27 && iVar7 <= 42) || (iVar7 >= 43 && iVar7 <= 58)) || (iVar7 >= 59 && iVar7 <= 74)) { iVar0 = func_116(iParam1, iParam3, iVar8, 0); } else { iVar0 = func_116(iParam1, iParam3, iVar8, 1); } } else if (iParam3 >= 41 && iParam3 <= 56) { iVar0 = 45; } else if (iParam3 >= 223 && iParam3 <= 226) { iVar0 = 44; } else { iVar0 = 0; } } else if (iParam2 == 8) { if (((iParam3 >= 27 && iParam3 <= 42) || (iParam3 >= 43 && iParam3 <= 58)) || (iParam3 >= 59 && iParam3 <= 74)) { iVar9 = func_142(iParam0, 11); iVar0 = func_116(iParam1, -99, iVar9, 0); } } break; } break; case joaat("player_two"): switch (iParam4) { case 10: switch (iParam2) { case 3: switch (iParam3) { case 50: iVar0 = 3; break; case 81: iVar0 = 5; break; case 82: iVar0 = 6; break; case 83: iVar0 = 7; break; case 84: iVar0 = 10; break; case 85: iVar0 = 9; break; case 86: iVar0 = 8; break; case 92: iVar0 = 22; break; case 87: iVar0 = 23; break; case 91: iVar0 = 24; break; case 93: iVar0 = 25; break; case 88: iVar0 = 26; break; case 94: iVar0 = 27; break; case 120: iVar0 = 11; break; case 121: iVar0 = 13; break; case 122: iVar0 = 14; break; case 124: iVar0 = 12; break; case 126: iVar0 = 18; break; case 128: iVar0 = 17; break; case 130: iVar0 = 19; break; case 131: iVar0 = 16; break; case 134: iVar0 = 15; break; case 135: iVar0 = 20; break; default: iVar0 = 0; break; } break; } break; } break; } } return iVar0; } int func_115(int iParam0, int iParam1, int iParam2, int iParam3, var uParam4) { int iVar0; switch (iParam0) { case joaat("player_zero"): break; case joaat("player_one"): *uParam4 = 0; if (iParam1 >= 27 && iParam1 <= 42) { if (iParam2 != -99) { if ((iParam2 >= 5 && iParam2 <= 8) || (iParam2 >= 25 && iParam2 <= 40)) { } else { if (iParam2 >= 42 && iParam2 <= 43) { if (iParam3 >= 176 && iParam3 <= 191) { iVar0 = (iParam1 - 27); *uParam4 = (59 + iVar0); } else if (iParam3 >= 227 && iParam3 <= 242) { iVar0 = (iParam1 - 27); *uParam4 = (43 + iVar0); } } return 0; } } if (iParam3 != -99) { if (((iParam3 >= 227 && iParam3 <= 242) || (iParam3 >= 176 && iParam3 <= 191)) || (iParam3 >= 243 && iParam3 <= 258)) { } else { return 0; } } } else if (iParam1 >= 43 && iParam1 <= 58) { if (iParam2 != -99) { if (iParam2 >= 42 && iParam2 <= 43) { } else { if ((iParam2 >= 5 && iParam2 <= 8) || (iParam2 >= 25 && iParam2 <= 40)) { iVar0 = (iParam1 - 43); *uParam4 = (27 + iVar0); } return 0; } } if (iParam3 != -99) { if (iParam3 >= 227 && iParam3 <= 242) { } else { if (iParam3 >= 176 && iParam3 <= 191) { if (iParam2 >= 42 && iParam2 <= 43) { iVar0 = (iParam1 - 43); *uParam4 = (59 + iVar0); } } return 0; } } } else if (iParam1 >= 59 && iParam1 <= 74) { if (iParam2 != -99) { if (iParam2 >= 42 && iParam2 <= 43) { } else { if ((iParam2 >= 5 && iParam2 <= 8) || (iParam2 >= 25 && iParam2 <= 40)) { iVar0 = (iParam1 - 59); *uParam4 = (27 + iVar0); } return 0; } } if (iParam3 != -99) { if (iParam3 >= 176 && iParam3 <= 191) { } else { if (iParam3 >= 227 && iParam3 <= 242) { if (iParam2 >= 42 && iParam2 <= 43) { iVar0 = (iParam1 - 59); *uParam4 = (43 + iVar0); } } else if ((iParam2 >= 5 && iParam2 <= 8) || (iParam2 >= 25 && iParam2 <= 40)) { iVar0 = (iParam1 - 59); *uParam4 = (27 + iVar0); } return 0; } } } break; case joaat("player_two"): if (iParam1 == 12) { if (iParam3 != 241) { return 0; } } break; } return 1; } int func_116(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; if (iParam1 >= 243 && iParam1 <= 246) { if (iParam3 == 1) { return 1; } else { return 5; } } else if (iParam1 >= 247 && iParam1 <= 250) { if (iParam3 == 1) { return 2; } else { return 6; } } else if (iParam1 >= 251 && iParam1 <= 254) { if (iParam3 == 1) { return 3; } else { return 7; } } else if (iParam1 >= 255 && iParam1 <= 258) { if (iParam3 == 1) { return 4; } else { return 8; } } else if (iParam1 >= 255 && iParam1 <= 258) { if (iParam3 == 1) { return 4; } else { return 8; } } else if ((iParam1 >= 176 && iParam1 <= 191) || (iParam1 >= 227 && iParam1 <= 242)) { if (iParam2 >= 9 && iParam2 <= 24) { if (iParam3 == 1) { return iParam2; } else { iVar0 = (iParam2 - 9); iParam2 = (25 + iVar0); return iParam2; } } else if (iParam2 >= 25 && iParam2 <= 40) { if (iParam3 == 1) { iVar0 = (iParam2 - 25); iParam2 = (9 + iVar0); return iParam2; } else { return iParam2; } } else if (iParam2 == 41 || iParam2 == 42) { if (iParam3 == 1) { return 41; } else { return 42; } } else { if (iParam3 == 1) { iParam2 = func_117(iParam0, 11, 9, 24); } else { iParam2 = func_117(iParam0, 11, 25, 40); } if (iParam2 == -99) { if (iParam3 == 1) { return 41; } else { return 42; } } else { return iParam2; } } } else if (iParam2 >= 1 && iParam2 <= 4) { if (iParam3 == 1) { return iParam2; } else { iVar0 = (iParam2 - 1); iParam2 = (5 + iVar0); return iParam2; } } else if (iParam2 >= 5 && iParam2 <= 8) { if (iParam3 == 1) { iVar0 = (iParam2 - 5); iParam2 = (1 + iVar0); return iParam2; } else { return iParam2; } } else if (iParam2 >= 9 && iParam2 <= 24) { if (iParam3 == 1) { return iParam2; } else { iVar0 = (iParam2 - 9); iParam2 = (25 + iVar0); return iParam2; } } else if (iParam2 >= 25 && iParam2 <= 40) { if (iParam3 == 1) { iVar0 = (iParam2 - 25); iParam2 = (9 + iVar0); return iParam2; } else { return iParam2; } } else if (iParam2 == 41 || iParam2 == 42) { if (iParam3 == 1) { return 41; } else { return 42; } } return -99; } int func_117(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; int iVar1; iVar0 = iParam2; while (iVar0 <= (iParam3 - 1)) { iVar1 = iVar0; if (func_107(iParam0, iParam1, iVar1)) { return iVar1; } iVar0++; } return -99; } int func_118(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; iVar0 = func_142(iParam0, iParam1); if (iVar0 >= iParam2 && iVar0 <= iParam3) { return 1; } return 0; } int func_119(int iParam0, int iParam1, int iParam2) { *iParam2 = -99; switch (iParam0) { case joaat("player_zero"): if ((((((((((((((((((iParam1 == 16 || iParam1 == 17) || iParam1 == 21) || iParam1 == 22) || iParam1 == 32) || (iParam1 >= 34 && iParam1 <= 39)) || (iParam1 >= 41 && iParam1 <= 45)) || iParam1 == 46) || (iParam1 >= 47 && iParam1 <= 54)) || (iParam1 >= 55 && iParam1 <= 70)) || (iParam1 >= 72 && iParam1 <= 79)) || iParam1 == 80) || (iParam1 >= 81 && iParam1 <= 83)) || (iParam1 >= 84 && iParam1 <= 87)) || iParam1 == 88) || (iParam1 >= 89 && iParam1 <= 91)) || iParam1 == 95) || (iParam1 >= 96 && iParam1 <= 111)) || iParam1 == 112) { *iParam2 = 6; return 1; } break; case joaat("player_one"): if ((((((iParam1 == 12 || (iParam1 >= 14 && iParam1 <= 21)) || iParam1 == 32) || iParam1 == 52) || (iParam1 >= 69 && iParam1 <= 70)) || iParam1 == 71) || (iParam1 >= 72 && iParam1 <= 77)) { *iParam2 = 17; return 1; } break; case joaat("player_two"): if (((((((((((((((iParam1 == 4 || iParam1 == 5) || iParam1 == 6) || iParam1 == 7) || iParam1 == 14) || (iParam1 >= 18 && iParam1 <= 29)) || iParam1 == 31) || iParam1 == 32) || iParam1 == 33) || iParam1 == 34) || (iParam1 >= 35 && iParam1 <= 42)) || (iParam1 >= 43 && iParam1 <= 53)) || (iParam1 >= 54 && iParam1 <= 61)) || (iParam1 >= 71 && iParam1 <= 80)) || (iParam1 >= 81 && iParam1 <= 90)) || (iParam1 >= 94 && iParam1 <= 103)) { *iParam2 = 8; return 1; } break; } return 0; } int func_120(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; *iParam3 = -99; switch (iParam0) { case joaat("player_zero"): switch (iParam1) { case 10: if (iParam2 >= 44 && iParam2 <= 47) { *iParam3 = 0; } break; case 14: if (((((((iParam2 >= 31 && iParam2 <= 32) || (iParam2 >= 33 && iParam2 <= 34)) || (iParam2 >= 35 && iParam2 <= 36)) || iParam2 == 37) || (iParam2 >= 38 && iParam2 <= 39)) || (iParam2 >= 40 && iParam2 <= 41)) || (iParam2 >= 42 && iParam2 <= 44)) { *iParam3 = 0; } break; } break; case joaat("player_one"): switch (iParam1) { case 10: if (iParam2 >= 47 && iParam2 <= 50) { *iParam3 = 0; } break; case 14: if (((((iParam2 >= 26 && iParam2 <= 27) || (iParam2 >= 28 && iParam2 <= 29)) || (iParam2 >= 30 && iParam2 <= 31)) || iParam2 == 32) || (iParam2 >= 35 && iParam2 <= 36)) { *iParam3 = 0; } break; } break; case joaat("player_two"): switch (iParam1) { case 9: if (iParam2 >= 15 && iParam2 <= 16) { *iParam3 = 0; } break; case 10: if (iParam2 >= 29 && iParam2 <= 32) { *iParam3 = 0; } break; case 14: if (((((((iParam2 >= 47 && iParam2 <= 48) || (iParam2 >= 49 && iParam2 <= 50)) || (iParam2 >= 51 && iParam2 <= 52)) || iParam2 == 53) || (iParam2 >= 54 && iParam2 <= 55)) || (iParam2 >= 56 && iParam2 <= 57)) || (iParam2 >= 58 && iParam2 <= 60)) { *iParam3 = 0; } break; } break; } if (*iParam3 != -99) { iVar0 = func_104(iParam0); Global_111858.f_2359.f_539[iVar0 /*65*/].f_63 = iParam2; Global_111858.f_2359.f_539[iVar0 /*65*/].f_64 = iParam1; return 1; } return 0; } int func_121(int iParam0, int iParam1, int iParam2) { switch (iParam0) { case joaat("player_zero"): if (iParam1 == 1) { if (iParam2 == 0) { return 1; } else if (iParam2 == 4) { return 5; } else { return 3; } } else if (iParam2 == 0) { return 0; } else if (iParam2 == 4) { return 4; } else { return 2; } break; case joaat("player_one"): if (iParam1 >= 0 && iParam1 <= 15) { if (iParam2 == 0) { return 0; } else { return 3; } } else if (iParam1 >= 16 && iParam1 <= 17) { if (iParam2 == 0) { return 2; } else { return 5; } } else if (iParam1 == 18) { if (iParam2 == 0) { return 6; } else { return 7; } } else if (iParam1 == 19) { if (iParam2 == 0) { return 1; } else { return 4; } } else if (iParam2 == 0) { return 1; } else { return 4; } break; case joaat("player_two"): if (iParam1 == 2) { if (iParam2 == 0) { return 2; } else { return 3; } } else if (iParam1 == 3) { if (iParam2 == 0) { return 4; } else { return 6; } } else if (iParam1 == 8) { return 5; } else if (iParam2 == 0) { return 0; } else { return 1; } break; } return -99; } void func_122(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; if (iParam2 == -1) { PED::CLEAR_PED_PROP(iParam0, iParam1); if (iParam1 == 0) { PED::SET_PED_CONFIG_FLAG(iParam0, 34, false); PED::SET_PED_CONFIG_FLAG(iParam0, 36, false); } } else { PED::SET_PED_PROP_INDEX(iParam0, iParam1, iParam2, iParam3, NETWORK::NETWORK_IS_GAME_IN_PROGRESS()); if (iParam1 == 0) { iVar0 = func_127(iParam0, iParam2, iParam3, iParam1); if (func_123(ENTITY::GET_ENTITY_MODEL(iParam0), 14, iVar0, FILES::GET_HASH_NAME_FOR_PROP(iParam0, 0, iParam2, iParam3))) { PED::SET_PED_CONFIG_FLAG(iParam0, 34, true); PED::SET_PED_CONFIG_FLAG(iParam0, 36, true); } else { PED::SET_PED_CONFIG_FLAG(iParam0, 34, false); PED::SET_PED_CONFIG_FLAG(iParam0, 36, false); } } } } int func_123(int iParam0, int iParam1, int iParam2, int iParam3) { switch (iParam0) { case joaat("mp_m_freemode_01"): switch (iParam1) { case 14: if (iParam3 == -1) { iParam3 = func_124(iParam0, iParam2, 14, 3); } if ((iParam2 >= 131 && iParam2 <= 154) || (iParam2 >= 327 && FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("HELMET"), 1))) { return 1; } break; } break; case joaat("mp_f_freemode_01"): switch (iParam1) { case 14: if (iParam3 == -1) { iParam3 = func_124(iParam0, iParam2, 14, 4); } if ((iParam2 >= 131 && iParam2 <= 154) || (iParam2 >= 327 && FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("HELMET"), 1))) { return 1; } break; } break; } return 0; } int func_124(int iParam0, int iParam1, int iParam2, int iParam3) { struct<2> Var0; int iVar17; int iVar18; struct<2> Var19; int iVar36; int iVar37; if (iParam2 == 12) { } else if (iParam2 == 13) { } else if (iParam2 == 14) { FILES::INIT_SHOP_PED_PROP(&Var0); iVar17 = (iParam1 - func_126(iParam0)); if (iVar17 < 0) { return -1; } iVar18 = FILES::_GET_NUM_PROPS_FROM_OUTFIT(iParam3, 7, -1, true, -1, -1); if (iVar18 <= iVar17) { return -1; } FILES::GET_SHOP_PED_QUERY_PROP(iVar17, &Var0); return Var0.f_1; } else { FILES::INIT_SHOP_PED_COMPONENT(&Var19); iVar36 = (iParam1 - func_125(iParam0, func_112(iParam2))); if (iVar36 < 0) { return -1; } if ((iParam0 == Global_76769.f_26[iParam2] && iParam1 == Global_76769[iParam2]) && Global_76769.f_13[iParam2] != 0) { return Global_76769.f_13[iParam2]; } iVar37 = FILES::_GET_NUM_PROPS_FROM_OUTFIT(iParam3, 7, -1, false, -1, func_112(iParam2)); if (iVar37 <= iVar36) { return -1; } FILES::GET_SHOP_PED_QUERY_COMPONENT(iVar36, &Var19); Global_76769.f_13[iParam2] = Var19.f_1; Global_76769[iParam2] = iParam1; Global_76769.f_26[iParam2] = iParam0; return Var19.f_1; } return -1; } int func_125(int iParam0, int iParam1) { switch (iParam0) { case joaat("player_zero"): switch (iParam1) { case 0: return 7; break; case 1: return 5; break; case 2: return 6; break; case 3: return 181; break; case 4: return 113; break; case 5: return 14; break; case 6: return 99; break; case 7: return 1; break; case 8: return 24; break; case 9: return 20; break; case 10: return 48; break; case 11: return 45; break; } break; case joaat("player_one"): switch (iParam1) { case 0: return 10; break; case 1: return 5; break; case 2: return 21; break; case 3: return 318; break; case 4: return 117; break; case 5: return 7; break; case 6: return 134; break; case 7: return 1; break; case 8: return 77; break; case 9: return 12; break; case 10: return 53; break; case 11: return 63; break; } break; case joaat("player_two"): switch (iParam1) { case 0: return 7; break; case 1: return 6; break; case 2: return 9; break; case 3: return 242; break; case 4: return 104; break; case 5: return 7; break; case 6: return 84; break; case 7: return 1; break; case 8: return 18; break; case 9: return 17; break; case 10: return 33; break; case 11: return 1; break; } break; } switch (iParam0) { case joaat("mp_m_freemode_01"): switch (iParam1) { case 0: return 0; break; case 1: return 26; break; case 2: return 91; break; case 3: return 16; break; case 4: return 256; break; case 5: return 9; break; case 6: return 256; break; case 7: return 92; break; case 8: return 241; break; case 9: return 46; break; case 10: return 7; break; case 11: return 237; break; } break; case joaat("mp_f_freemode_01"): switch (iParam1) { case 0: return 0; break; case 1: return 26; break; case 2: return 92; break; case 3: return 16; break; case 4: return 256; break; case 5: return 9; break; case 6: return 256; break; case 7: return 55; break; case 8: return 136; break; case 9: return 36; break; case 10: return 6; break; case 11: return 256; break; } break; } return -99; } int func_126(int iParam0) { switch (iParam0) { case joaat("player_zero"): return 113; break; case joaat("player_one"): return 175; break; case joaat("player_two"): return 155; break; } switch (iParam0) { case joaat("mp_m_freemode_01"): return 327; break; case joaat("mp_f_freemode_01"): return 327; break; } return -99; } int func_127(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; int iVar1; int iVar2; int iVar3; int iVar4; int iVar5; int iVar6; if (iParam1 == -1) { return func_130(iParam3); } iVar0 = ENTITY::GET_ENTITY_MODEL(iParam0); iVar1 = FILES::GET_HASH_NAME_FOR_PROP(iParam0, iParam3, iParam1, iParam2); if (iVar1 != -1 && iVar1 != 0) { if (iVar0 == joaat("mp_m_freemode_01")) { return func_129(ENTITY::GET_ENTITY_MODEL(iParam0), iVar1, 14, 3); } else if (iVar0 == joaat("mp_f_freemode_01")) { return func_129(ENTITY::GET_ENTITY_MODEL(iParam0), iVar1, 14, 4); } } iVar2 = PED::GET_NUMBER_OF_PED_PROP_DRAWABLE_VARIATIONS(iParam0, iParam3); iVar4 = 0; while (iVar4 <= (iVar2 - 1)) { iVar6 = PED::GET_NUMBER_OF_PED_PROP_TEXTURE_VARIATIONS(iParam0, iParam3, iVar4); if (iVar4 != iParam1) { iVar3 = (iVar3 + iVar6); } else { iVar5 = 0; while (iVar5 <= (iVar6 - 1)) { if (iVar4 == iParam1 && iVar5 == iParam2) { iVar3 = (iVar3 + func_128(iParam0, iParam3)); return iVar3; } else { iVar3++; } iVar5++; } } iVar4++; } return func_130(iParam3); } int func_128(int iParam0, int iParam1) { int iVar0; iVar0 = ENTITY::GET_ENTITY_MODEL(iParam0); switch (iVar0) { case joaat("player_zero"): switch (iParam1) { case 0: return 10; break; case 1: return 58; break; case 2: return 112; break; } break; case joaat("player_one"): switch (iParam1) { case 0: return 10; break; case 1: return 82; break; case 2: return 158; break; } break; case joaat("player_two"): switch (iParam1) { case 0: return 10; break; case 1: return 88; break; case 2: return 154; break; } break; case joaat("mp_m_freemode_01"): switch (iParam1) { case 0: return 10; break; case 1: return 155; break; case 6: return 319; break; } break; case joaat("mp_f_freemode_01"): switch (iParam1) { case 0: return 10; break; case 1: return 155; break; case 6: return 319; break; } break; } return -99; } int func_129(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; int iVar1; if (iParam2 == 12) { } else if (iParam2 == 13) { } else if (iParam2 == 14) { FILES::_GET_NUM_PROPS_FROM_OUTFIT(iParam3, 7, -1, true, -1, -1); iVar0 = unk_0x6CEBE002E58DEE97(iParam1); if (iVar0 != -1) { return (func_126(iParam0) + iVar0); } } else { FILES::_GET_NUM_PROPS_FROM_OUTFIT(iParam3, 7, -1, false, -1, func_112(iParam2)); iVar1 = unk_0x96E2929292A4DB77(iParam1); if (iVar1 != -1) { return (func_125(iParam0, func_112(iParam2)) + iVar1); } } return -99; } int func_130(int iParam0) { switch (iParam0) { case 0: return 0; break; case 1: return 1; break; case 2: return 2; break; case 3: return 3; break; case 4: return 4; break; case 5: return 5; break; case 6: return 6; break; case 7: return 7; break; case 8: return 8; break; } return 0; } struct<10> func_131(int iParam0, int iParam1) { int iVar0; struct<10> Var1; Var1 = 9; iVar0 = 0; while (iVar0 <= 8) { Var1[iVar0] = -99; iVar0++; } switch (iParam0) { case joaat("player_zero"): switch (iParam1) { case 31: func_133(&Var1, 0, 1, 2, 3, 4, 5, 6, 7, 8); break; case 0: func_133(&Var1, 10, 1, 2, 3, 4, 5, 6, 7, 8); break; case 1: func_133(&Var1, 19, 1, 2, 3, 4, 5, 6, 7, 8); break; case 2: func_133(&Var1, 14, 1, 2, 3, 4, 5, 6, 7, 8); break; case 3: func_133(&Var1, 18, 1, 2, 3, 4, 5, 6, 7, 8); break; case 4: func_133(&Var1, 0, 59, 112, 3, 4, 5, 6, 7, 8); break; case 5: func_133(&Var1, 0, 60, 112, 3, 4, 5, 6, 7, 8); break; case 6: func_133(&Var1, 15, 1, 2, 3, 4, 5, 6, 7, 8); break; case 7: func_133(&Var1, 0, 60, 2, 3, 4, 5, 6, 7, 8); break; case 8: func_133(&Var1, 55, 1, 2, 3, 4, 5, 6, 7, 8); break; case 9: func_133(&Var1, 0, 1, 112, 3, 4, 5, 6, 7, 8); break; default: func_132(&Var1, iParam0, iParam1, 10); break; } break; case joaat("player_one"): switch (iParam1) { case 31: func_133(&Var1, 0, 1, 2, 3, 4, 5, 6, 7, 8); break; case 0: func_133(&Var1, 10, 1, 2, 3, 4, 5, 6, 7, 8); break; case 1: func_133(&Var1, 0, 82, 158, 3, 4, 5, 6, 7, 8); break; case 2: func_133(&Var1, 0, 1, 158, 3, 4, 5, 6, 7, 8); break; case 3: func_133(&Var1, 15, 1, 2, 3, 4, 5, 6, 7, 8); break; case 4: func_133(&Var1, 41, 1, 2, 3, 4, 5, 6, 7, 8); break; case 5: func_133(&Var1, 40, 1, 2, 3, 4, 5, 6, 7, 8); break; case 6: func_133(&Var1, 41, 95, 2, 3, 4, 5, 6, 7, 8); break; case 7: func_133(&Var1, 0, 95, 2, 3, 4, 5, 6, 7, 8); break; case 8: func_133(&Var1, 69, 95, 2, 3, 4, 5, 6, 7, 8); break; default: func_132(&Var1, iParam0, iParam1, 9); break; } break; case joaat("player_two"): switch (iParam1) { case 31: func_133(&Var1, 0, 1, 2, 3, 4, 5, 6, 7, 8); break; case 0: func_133(&Var1, 11, 1, 2, 3, 4, 5, 6, 7, 8); break; case 1: func_133(&Var1, 17, 90, 2, 3, 4, 5, 6, 7, 8); break; case 2: func_133(&Var1, 15, 1, 2, 3, 4, 5, 6, 7, 8); break; case 3: func_133(&Var1, 0, 88, 154, 3, 4, 5, 6, 7, 8); break; case 4: func_133(&Var1, 0, 1, 154, 3, 4, 5, 6, 7, 8); break; case 5: func_133(&Var1, 16, 1, 2, 3, 4, 5, 6, 7, 8); break; case 6: func_133(&Var1, 36, 1, 2, 3, 4, 5, 6, 7, 8); break; case 7: func_133(&Var1, 0, 123, 2, 3, 4, 5, 6, 7, 8); break; case 8: func_133(&Var1, 69, 1, 2, 3, 4, 5, 6, 7, 8); break; default: func_132(&Var1, iParam0, iParam1, 9); break; } break; case joaat("mp_m_freemode_01"): switch (iParam1) { case 31: func_133(&Var1, 0, 1, 2, 3, 4, 5, 6, 7, 8); break; case 0: func_133(&Var1, 129, 167, 2, 3, 4, 5, 6, 7, 8); break; case 1: func_133(&Var1, 90, 1, 2, 3, 4, 5, 6, 7, 8); break; case 2: func_133(&Var1, 23, 251, 2, 3, 4, 5, 6, 7, 8); break; case 3: func_133(&Var1, 36, 262, 2, 3, 4, 5, 6, 7, 8); break; case 4: func_133(&Var1, 88, 1, 2, 3, 4, 5, 6, 7, 8); break; case 5: func_133(&Var1, 125, 175, 2, 3, 4, 5, 6, 7, 8); break; case 6: func_133(&Var1, 35, 1, 2, 3, 4, 5, 6, 7, 8); break; case 7: func_133(&Var1, 44, 208, 2, 3, 4, 5, 6, 7, 8); break; case 8: func_133(&Var1, 52, 189, 2, 3, 4, 5, 6, 7, 8); break; case 9: func_133(&Var1, 0, 261, 2, 3, 4, 5, 6, 7, 8); break; case 10: func_133(&Var1, 0, 243, 2, 3, 4, 5, 6, 7, 8); break; case 11: func_133(&Var1, 0, 243, 2, 3, 4, 5, 6, 7, 8); break; case 12: func_133(&Var1, 0, 212, 2, 3, 4, 5, 6, 7, 8); break; case 13: func_133(&Var1, 64, 291, 2, 3, 4, 5, 6, 7, 8); break; case 14: func_133(&Var1, 61, 207, 2, 3, 4, 5, 6, 7, 8); break; case 15: func_133(&Var1, 0, 291, 2, 3, 4, 5, 6, 7, 8); break; case 16: func_133(&Var1, 0, 208, 2, 3, 4, 5, 6, 7, 8); break; case 17: func_133(&Var1, 0, 229, 2, 3, 4, 5, 6, 7, 8); break; case 18: func_133(&Var1, 36, 249, 2, 3, 4, 5, 6, 7, 8); break; case 19: func_133(&Var1, 0, 259, 2, 3, 4, 5, 6, 7, 8); break; case 20: func_133(&Var1, 0, 174, 2, 3, 4, 5, 6, 7, 8); break; case 21: func_133(&Var1, 35, 180, 2, 3, 4, 5, 6, 7, 8); break; case 22: func_133(&Var1, 36, 1, 2, 3, 4, 5, 6, 7, 8); break; case 23: func_133(&Var1, 0, 259, 2, 3, 4, 5, 6, 7, 8); break; case 24: func_133(&Var1, 35, 1, 2, 3, 4, 5, 6, 7, 8); break; default: func_132(&Var1, iParam0, iParam1, 25); break; } break; case joaat("mp_f_freemode_01"): switch (iParam1) { case 31: func_133(&Var1, 0, 1, 2, 3, 4, 5, 6, 7, 8); break; case 0: func_133(&Var1, 35, 233, 2, 3, 4, 5, 6, 7, 8); break; case 1: func_133(&Var1, 36, 178, 2, 3, 4, 5, 6, 7, 8); break; case 2: func_133(&Var1, 53, 221, 2, 3, 4, 5, 6, 7, 8); break; case 3: func_133(&Var1, 38, 170, 2, 3, 4, 5, 6, 7, 8); break; case 4: func_133(&Var1, 37, 1, 2, 3, 4, 5, 6, 7, 8); break; case 5: func_133(&Var1, 113, 203, 2, 3, 4, 5, 6, 7, 8); break; case 6: func_133(&Var1, 114, 183, 2, 3, 4, 5, 6, 7, 8); break; case 7: func_133(&Var1, 0, 221, 2, 3, 4, 5, 6, 7, 8); break; case 8: func_133(&Var1, 0, 221, 2, 3, 4, 5, 6, 7, 8); break; case 9: func_133(&Var1, 0, 199, 2, 3, 4, 5, 6, 7, 8); break; case 10: func_133(&Var1, 0, 182, 2, 3, 4, 5, 6, 7, 8); break; case 11: func_133(&Var1, 0, 233, 2, 3, 4, 5, 6, 7, 8); break; case 12: func_133(&Var1, 107, 167, 2, 3, 4, 5, 6, 7, 8); break; case 13: func_133(&Var1, 109, 170, 2, 3, 4, 5, 323, 7, 8); break; case 14: func_133(&Var1, 119, 237, 2, 3, 4, 5, 6, 7, 8); break; case 15: func_133(&Var1, 0, 221, 2, 3, 4, 5, 6, 7, 8); break; case 16: func_133(&Var1, 114, 1, 2, 3, 4, 5, 6, 7, 8); break; case 17: func_133(&Var1, 35, 268, 2, 3, 4, 5, 6, 7, 8); break; case 18: func_133(&Var1, 0, 266, 2, 3, 4, 5, 6, 7, 8); break; case 19: func_133(&Var1, 42, 1, 2, 3, 4, 5, 6, 7, 8); break; case 20: func_133(&Var1, 76, 1, 2, 3, 4, 5, 6, 7, 8); break; case 21: func_133(&Var1, 39, 235, 2, 3, 4, 5, 6, 7, 8); break; case 22: func_133(&Var1, 41, 183, 2, 3, 4, 5, 6, 7, 8); break; case 23: func_133(&Var1, 111, 194, 2, 3, 4, 5, 6, 7, 8); break; default: func_132(&Var1, iParam0, iParam1, 25); break; } break; } return Var1; } void func_132(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; struct<4> Var1; struct<3> Var16; int iVar19; if (iParam2 != 0 && iParam2 != -99) { (*iParam0)[0] = 0; (*iParam0)[1] = 1; (*iParam0)[2] = 2; (*iParam0)[3] = 3; (*iParam0)[4] = 4; (*iParam0)[5] = 5; (*iParam0)[6] = 6; (*iParam0)[7] = 7; (*iParam0)[8] = 8; iVar0 = 0; if (iParam1 == joaat("player_zero")) { iVar0 = 0; } else if (iParam1 == joaat("player_one")) { iVar0 = 1; } else if (iParam1 == joaat("player_two")) { iVar0 = 2; } else if (iParam1 == joaat("mp_m_freemode_01")) { iVar0 = 3; } else if (iParam1 == joaat("mp_f_freemode_01")) { iVar0 = 4; } FILES::GET_SHOP_PED_OUTFIT(iParam2, &Var1); if (!FILES::IS_CONTENT_ITEM_LOCKED(Var1)) { iVar19 = 0; while (iVar19 < Var1.f_3) { if (FILES::GET_SHOP_PED_OUTFIT_PROP_VARIANT(Var1.f_1, iVar19, &Var16) && Var16.f_2 != -1) { if ((Var16.x != 0 && Var16.x != -1) && Var16.x != joaat("0")) { (*iParam0)[Var16.f_2] = func_129(iParam1, Var16.x, 14, iVar0); } else if (Var16.f_1 != -1) { (*iParam0)[Var16.f_2] = Var16.f_1; } } iVar19++; } } } } void func_133(int iParam0, int iParam1, int iParam2, int iParam3, int iParam4, int iParam5, int iParam6, int iParam7, int iParam8, int iParam9) { (*iParam0)[0] = iParam1; (*iParam0)[1] = iParam2; (*iParam0)[2] = iParam3; (*iParam0)[3] = iParam4; (*iParam0)[4] = iParam5; (*iParam0)[5] = iParam6; (*iParam0)[6] = iParam7; (*iParam0)[7] = iParam8; (*iParam0)[8] = iParam9; } struct<17> func_134(int iParam0, int iParam1) { int iVar0; struct<17> Var1; Var1 = 15; iVar0 = 0; while (iVar0 <= 14) { Var1[iVar0] = -99; iVar0++; } Var1.f_16 = 0; switch (iParam0) { case joaat("player_zero"): switch (iParam1) { case 0: if (Global_111858.f_9081.f_99.f_58[120]) { func_137(&Var1, -99, -99, 1, 1, 0, 0, 0, 0, 0, -99, 0, 0, 31); } else { func_137(&Var1, -99, -99, 0, 0, 0, 0, 0, 0, 0, -99, 0, 0, 31); } break; case 1: func_137(&Var1, -99, -99, 16, 16, 6, 1, 1, 0, 1, -99, 0, 0, 0); break; case 2: func_137(&Var1, -99, -99, 36, 21, 6, 1, 5, 0, 0, -99, 0, 0, 8); break; case 3: func_137(&Var1, -99, -99, 65, 36, 6, 0, 2, 0, 0, -99, 0, 0, 31); break; case 4: func_137(&Var1, -99, -99, 61, 32, 6, 0, 0, 7, 3, -99, 0, 0, 2); break; case 5: func_137(&Var1, -99, -99, Global_111858.f_2359.f_539.f_196[0], Global_111858.f_2359.f_539.f_200[0], 6, 3, 0, 0, 0, -99, 0, 0, 3); break; case 6: func_137(&Var1, -99, -99, 92, 72, 7, 0, 0, 0, 0, -99, 0, 0, 31); break; case 7: func_137(&Var1, -99, -99, 85, 95, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 8: func_137(&Var1, -99, -99, 170, 80, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 9: func_137(&Var1, -99, -99, 171, 89, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 10: func_137(&Var1, -99, -99, 33, 18, 8, 10, 3, 8, 0, -99, 0, 0, 4); break; case 11: func_137(&Var1, -99, -99, 33, 18, 17, 10, 4, 8, 0, -99, 0, 0, 5); break; case 12: func_137(&Var1, -99, -99, 35, 20, 9, 10, 23, 0, 0, -99, 0, 0, 31); break; case 13: func_137(&Var1, -99, -99, 69, 40, 13, 0, 0, 0, 0, -99, 0, 0, 31); break; case 14: func_137(&Var1, -99, -99, 62, 33, 38, 0, 8, 0, 0, -99, 0, 0, 6); break; case 15: func_137(&Var1, -99, -99, 63, 34, 6, 10, 0, 0, 4, -99, 0, 0, 31); break; case 16: func_137(&Var1, -99, -99, 174, 93, 18, 0, 18, 0, 0, -99, 0, 0, 31); break; case 17: func_137(&Var1, -99, -99, 76, 46, 6, 10, 0, 0, 0, -99, 0, 0, 31); break; case 18: func_137(&Var1, -99, -99, 35, 20, 9, 10, 0, 4, 0, -99, 0, 0, 7); break; case 19: func_137(&Var1, -99, -99, 64, 35, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 20: func_137(&Var1, -99, -99, 66, 37, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 21: func_137(&Var1, -99, -99, 67, 38, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 22: func_137(&Var1, -99, -99, 68, 39, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 23: func_137(&Var1, -99, -99, 177, 94, 19, 9, 0, 0, 0, -99, 0, 0, 31); break; case 24: func_137(&Var1, -99, -99, 35, 20, 9, 10, 4, 0, 0, -99, 0, 0, 31); break; case 25: func_137(&Var1, -99, -99, 97, 81, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 26: func_137(&Var1, -99, -99, 3, 3, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 27: func_137(&Var1, -99, -99, 129, 81, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 28: func_137(&Var1, -99, -99, 170, 80, 6, 0, 13, 0, 0, -99, 0, 0, 31); break; case 29: func_137(&Var1, -99, -99, 2, 2, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 30: func_137(&Var1, -99, -99, 161, 3, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 31: func_137(&Var1, -99, -99, 3, 3, 0, 12, 0, 0, 0, -99, 0, 1, 31); break; case 32: func_137(&Var1, -99, -99, 85, 55, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 33: func_137(&Var1, -99, -99, 86, 4, 20, 0, 0, 0, 0, -99, 0, 0, 31); break; case 34: func_137(&Var1, -99, -99, 44, 97, 6, 0, 0, 0, 0, -99, 0, 2, 31); break; case 35: func_137(&Var1, -99, -99, 85, 81, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 36: func_137(&Var1, -99, -99, 4, 4, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 37: func_137(&Var1, -99, -99, 5, 5, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 38: func_137(&Var1, -99, -99, 6, 6, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 39: func_137(&Var1, -99, -99, 7, 7, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 40: func_137(&Var1, -99, -99, 8, 8, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 41: func_137(&Var1, -99, -99, 9, 9, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 42: func_137(&Var1, -99, -99, 10, 10, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 43: func_137(&Var1, -99, -99, 11, 11, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 44: func_137(&Var1, -99, -99, 12, 12, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 45: func_137(&Var1, -99, -99, 13, 13, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 46: func_137(&Var1, -99, -99, 14, 14, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 47: func_137(&Var1, -99, -99, 15, 15, 0, 0, 0, 0, 0, -99, 0, 0, 31); break; case 48: func_137(&Var1, -99, -99, 91, 71, 14, 13, 0, 0, 0, -99, 0, 0, 31); break; case 49: func_137(&Var1, -99, -99, 35, 20, 9, 10, 0, 0, 0, -99, 0, 0, 31); break; case 50: func_137(&Var1, -99, -99, 33, 18, 8, 10, 3, 8, 0, -99, 0, 0, 9); break; case 51: func_137(&Var1, -99, -99, 169, 95, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; case 52: func_137(&Var1, -99, -99, 169, 72, 6, 0, 0, 0, 0, -99, 0, 0, 31); break; default: func_135(&Var1, iParam0, iParam1, 53); break; } break; case joaat("player_one"): switch (iParam1) { case 0: func_137(&Var1, -99, -99, 73, 24, 18, 0, 26, 0, 0, -99, 0, 0, 31); break; case 1: func_137(&Var1, -99, -99, 22, 10, 64, 0, 24, 0, 0, -99, 0, 43, 31); break; case 2: func_137(&Var1, -99, -99, Global_111858.f_2359.f_539.f_196[1], Global_111858.f_2359.f_539.f_200[1], 17, 2, 26, 0, 0, -99, 0, 45, 31); break; case 3: func_137(&Var1, -99, -99, 23, 11, 13, 5, 2, 4, 0, -99, 0, 0, 1); break; case 4: func_137(&Var1, -99, -99, 23, 11, 34, 5, 26, 0, 0, -99, 0, 0, 2); break; case 5: func_137(&Var1, -99, 20, 159, 69, 17, 5, 26, 0, 0, -99, 0, 0, 31); break; case 6: func_137(&Var1, -99, -99, 40, 13, 14, 0, 0, 0, 0, -99, 0, 0, 31); break; case 7: func_137(&Var1, -99, -99, 90, 32, 17, 1, 8, 0, 1, -99, 0, 0, 3); break; case 8: func_137(&Var1, -99, -99, 17, 5, 12, 0, 26, 0, 2, -99, 0, 0, 5); break; case 9: func_137(&Var1, -99, -99, 16, 4, 12, 0, 26, 0, 0, -99, 0, 0, 31); break; case 10: func_137(&Var1, -99, -99, 208, 71, 17, 0, 26, 0, 0, -99, 0, 0, 31); break; case 11: func_137(&Var1, -99, -99, 259, 10, 35, 0, 24, 0, 0, -99, 0, 43, 31); break; case 12: func_137(&Var1, -99, -99, 18, 6, 12, 0, 26, 0, 0, -99, 0, 0, 31); break; case 13: func_137(&Var1, -99, -99, 19, 7, 12, 0, 26, 0, 0, -99, 0, 0, 31); break; case 14: func_137(&Var1, -99, -99, 20, 8, 12, 0, 26, 0, 0, -99, 0, 0, 31); break; case 15: func_137(&Var1, -99, -99, 21, 9, 12, 0, 26, 0, 0, -99, 0, 0, 31); break; case 16: func_137(&Var1, -99, -99, 135, 40, 0, 0, 26, 0, 0, -99, 0, 0, 31); break; case 17: func_137(&Var1, -99, -99, 74, 24, 52, 0, 26, 0, 0, -99, 0, 0, 31); break; case 18: func_137(&Var1, -99, -99, 176, 53, 26, 5, 26, 0, 0, -99, 0, 41, 31); break; case 19: func_137(&Var1, -99, -99, 125, 24, 18, 0, 26, 0, 0, -99, 0, 0, 31); break; case 20: func_137(&Var1, -99, -99, 162, 24, 36, 0, 26, 0, 0, -99, 0, 0, 31); break; case 21: func_137(&Var1, -99, -99, 75, 24, 36, 0, 26, 0, 0, -99, 0, 0, 4); break; case 22: func_137(&Var1, -99, -99, 227, 53, 25, 0, 27, 0, 0, -99, 0, 25, 31); break; case 23: func_137(&Var1, -99, -99, 228, 54, 25, 0, 28, 0, 0, -99, 0, 26, 31); break; case 24: func_137(&Var1, -99, -99, 229, 55, 25, 0, 29, 0, 0, -99, 0, 27, 31); break; case 25: func_137(&Var1, -99, -99, 230, 56, 25, 0, 30, 0, 0, -99, 0, 28, 31); break; case 26: func_137(&Var1, -99, -99, 231, 57, 25, 0, 31, 0, 0, -99, 0, 29, 31); break; case 27: func_137(&Var1, -99, -99, 232, 58, 25, 0, 32, 0, 0, -99, 0, 30, 31); break; case 28: func_137(&Var1, -99, -99, 233, 59, 25, 0, 33, 0, 0, -99, 0, 31, 31); break; case 29: func_137(&Var1, -99, -99, 234, 60, 25, 0, 34, 0, 0, -99, 0, 32, 31); break; case 30: func_137(&Var1, -99, -99, 235, 61, 25, 0, 35, 0, 0, -99, 0, 33, 31); break; case 31: func_137(&Var1, -99, -99, 236, 62, 25, 0, 36, 0, 0, -99, 0, 34, 31); break; case 32: func_137(&Var1, -99, -99, 237, 63, 25, 0, 37, 0, 0, -99, 0, 35, 31); break; case 33: func_137(&Var1, -99, -99, 238, 64, 25, 0, 38, 0, 0, -99, 0, 36, 31); break; case 34: func_137(&Var1, -99, -99, 239, 65, 25, 0, 39, 0, 0, -99, 0, 37, 31); break; case 35: func_137(&Var1, -99, -99, 240, 66, 25, 0, 40, 0, 0, -99, 0, 38, 31); break; case 36: func_137(&Var1, -99, -99, 241, 67, 25, 0, 41, 0, 0, -99, 0, 39, 31); break; case 37: func_137(&Var1, -99, -99, 242, 68, 25, 0, 42, 0, 0, -99, 0, 40, 31); break; case 38: func_137(&Var1, -99, -99, 260, 72, 17, 0, 26, 0, 0, -99, 0, 0, 31); break; case 39: func_137(&Var1, -99, -99, 125, 24, 0, 0, 26, 0, 0, -99, 0, 0, 31); break; case 40: func_137(&Var1, -99, -99, 123, 24, 0, 0, 26, 0, 0, -99, 0, 0, 31); break; case 41: func_137(&Var1, -99, -99, 159, 69, 17, 5, 26, 0, 0, -99, 0, 0, 31); break; case 42: func_137(&Var1, -99, -99, 89, 22, 15, 6, 26, 0, 0, -99, 0, 0, 31); break; case 43: func_137(&Var1, -99, -99, 317, 69, 17, 0, 0, 0, 51, -99, 0, 0, 6); break; case 44: func_137(&Var1, -99, -99, 30, 23, 16, 0, 0, 0, 0, -99, 0, 0, 7); break; case 45: func_137(&Var1, -99, -99, 106, 70, 17, 5, 26, 0, 0, -99, 0, 0, 8); break; case 46: func_137(&Var1, -99, -99, 117, 24, 20, 5, 26, 0, 52, -99, 0, 0, 31); break; default: func_135(&Var1, iParam0, iParam1, 47); break; } break; case joaat("player_two"): switch (iParam1) { case 0: func_137(&Var1, -99, -99, 0, 91, 28, 0, 0, 0, 0, -99, 0, 0, 31); break; case 1: func_137(&Var1, -99, -99, 17, 5, 8, 2, 3, 0, 0, -99, 0, 0, 8); break; case 2: func_137(&Var1, -99, -99, 43, 8, 12, 3, 5, 0, 0, -99, 0, 0, 1); break; case 3: func_137(&Var1, -99, -99, 50, 14, 8, 0, 15, 6, 3, -99, 0, 0, 2); break; case 4: func_137(&Var1, -99, -99, Global_111858.f_2359.f_539.f_196[2], Global_111858.f_2359.f_539.f_200[2], 8, 0, 0, 0, 0, -99, 0, 0, 31); break; case 5: func_137(&Var1, -99, -99, 95, 33, 8, 0, 15, 0, 0, -99, 0, 0, 6); break; case 6: func_137(&Var1, -99, -99, 49, 13, 10, 4, 6, 0, 0, -99, 0, 0, 3); break; case 7: func_137(&Var1, -99, -99, 49, 13, 14, 4, 15, 0, 0, -99, 0, 0, 4); break; case 8: func_137(&Var1, -99, -99, 79, 32, 8, 5, 7, 0, 0, -99, 0, 0, 31); break; case 9: func_137(&Var1, -99, -99, 53, 17, 11, 0, 15, 0, 0, -99, 0, 0, 31); break; case 10: func_137(&Var1, -99, -99, 96, 81, 8, 0, 0, 0, 0, -99, 0, 0, 31); break; case 11: func_137(&Var1, -99, -99, 51, 15, 33, 0, 8, 0, 0, -99, 0, 0, 5); break; case 12: func_137(&Var1, -99, -99, 0, 93, 29, 0, 13, 0, 0, -99, 0, 0, 31); break; case 13: func_137(&Var1, -99, -99, 52, 16, 30, 5, 15, 0, 0, -99, 0, 0, 31); break; case 14: func_137(&Var1, -99, -99, 241, 92, 16, 0, 12, 0, 0, -99, 0, 0, 31); break; case 15: func_137(&Var1, -99, -99, 97, 34, 8, 0, 0, 0, 0, -99, 0, 0, 31); break; case 16: func_137(&Var1, -99, -99, 44, 9, 12, 0, 15, 0, 0, -99, 0, 0, 31); break; case 17: func_137(&Var1, -99, -99, 45, 10, 12, 0, 15, 0, 0, -99, 0, 0, 31); break; case 18: func_137(&Var1, -99, -99, 46, 11, 12, 0, 15, 0, 0, -99, 0, 0, 31); break; case 19: func_137(&Var1, -99, -99, 47, 12, 12, 0, 15, 0, 0, -99, 0, 0, 31); break; case 20: func_137(&Var1, -99, -99, 161, 53, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 21: func_137(&Var1, -99, -99, 0, 44, 8, 0, 0, 0, 0, -99, 0, 0, 31); break; case 22: func_137(&Var1, -99, -99, 98, 0, 28, 0, 15, 0, 0, -99, 0, 0, 31); break; case 23: func_137(&Var1, -99, -99, 27, 0, 31, 0, 15, 0, 0, -99, 0, 0, 31); break; case 24: func_137(&Var1, -99, -99, 190, 71, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 25: func_137(&Var1, -99, -99, 191, 72, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 26: func_137(&Var1, -99, -99, 192, 73, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 27: func_137(&Var1, -99, -99, 193, 74, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 28: func_137(&Var1, -99, -99, 194, 75, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 29: func_137(&Var1, -99, -99, 195, 76, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 30: func_137(&Var1, -99, -99, 196, 77, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 31: func_137(&Var1, -99, -99, 197, 78, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 32: func_137(&Var1, -99, -99, 198, 79, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 33: func_137(&Var1, -99, -99, 199, 80, 8, 0, 15, 0, 0, -99, 0, 0, 31); break; case 34: func_137(&Var1, -99, -99, 200, 62, 16, 0, 15, 0, 0, -99, 0, 0, 31); break; case 35: func_137(&Var1, -99, -99, 201, 63, 16, 0, 15, 0, 0, -99, 0, 0, 31); break; case 36: func_137(&Var1, -99, -99, 202, 64, 16, 0, 15, 0, 0, -99, 0, 0, 31); break; case 37: func_137(&Var1, -99, -99, 203, 65, 16, 0, 15, 0, 0, -99, 0, 0, 31); break; case 38: func_137(&Var1, -99, -99, 204, 66, 16, 0, 15, 0, 0, -99, 0, 0, 31); break; case 39: func_137(&Var1, -99, -99, 205, 67, 16, 0, 15, 0, 0, -99, 0, 0, 31); break; case 40: func_137(&Var1, -99, -99, 206, 68, 16, 0, 15, 0, 0, -99, 0, 0, 31); break; case 41: func_137(&Var1, -99, -99, 2, 43, 8, 0, 0, 0, 0, -99, 0, 0, 31); break; case 42: func_137(&Var1, -99, -99, 55, 0, 28, 0, 0, 0, 0, -99, 0, 0, 31); break; case 43: func_137(&Var1, -99, -99, 0, 52, 8, 0, 0, 0, 0, -99, 0, 0, 31); break; case 44: func_137(&Var1, -99, -99, 70, 30, 32, 6, 15, 0, 0, -99, 0, 0, 31); break; case 45: func_137(&Var1, -99, -99, 19, 91, 28, 0, 0, 0, 0, -99, 0, 0, 7); break; case 46: func_137(&Var1, -99, -99, 0, 0, 28, 0, 0, 0, 0, -99, 0, 0, 31); break; case 47: func_137(&Var1, -99, -99, 79, 32, 8, 5, 15, 0, 0, -99, 0, 0, 31); break; default: func_135(&Var1, iParam0, iParam1, 48); break; } break; case joaat("mp_m_freemode_01"): switch (iParam1) { case 0: func_137(&Var1, -99, -99, 0, 0, 10, -99, 0, -99, -99, 0, 0, 0, 31); break; case 1: func_137(&Var1, -99, -99, 1, 127, 38, -99, 2, 0, 0, 0, 0, 62, 0); break; case 2: func_137(&Var1, -99, -99, 0, 248, 45, -99, 240, 0, 0, 0, 0, 144, 1); break; case 3: func_137(&Var1, -99, -99, 4, 31, 25, -99, 240, 0, 0, 0, 0, 231, 2); break; case 4: func_137(&Var1, -99, -99, 1, 66, 10, -99, 21, 0, 0, 0, 0, 123, 3); break; case 5: func_137(&Var1, -99, -99, 1, 93, 141, -99, 3, 0, 0, 0, 0, 114, 4); break; case 6: func_137(&Var1, -99, -99, 1, 116, 113, -99, 7, 0, 0, 0, 0, 113, 5); break; case 7: func_137(&Var1, -99, -99, 1, 61, 136, -99, 27, 0, 0, 0, 0, 61, 6); break; case 8: func_137(&Var1, -99, -99, 0, 112, 10, -99, 240, 0, 0, 0, 0, 8, 7); break; case 9: func_137(&Var1, -99, -99, 4, 131, 24, -99, 240, 0, 0, 0, 0, 223, 8); break; case 10: func_137(&Var1, -99, -99, 1, 209, 188, -99, 208, 0, 0, 0, 0, 64, 9); break; case 11: func_137(&Var1, -99, -99, 1, 209, 160, -99, 211, 0, 0, 0, 43, 157, 10); break; case 12: func_137(&Var1, -99, -99, 1, 162, 174, -99, 201, 0, 0, 0, 0, 158, 11); break; case 13: func_137(&Var1, -99, -99, 1, 4, 240, -99, 34, 0, 0, 0, 0, 97, 12); break; case 14: func_137(&Var1, -99, -99, 1, 128, 232, -99, 43, 0, 0, 0, 0, 102, 13); break; case 15: func_137(&Var1, -99, -99, 1, 66, 65, -99, 224, 0, 0, 0, 0, 100, 14); break; case 16: func_137(&Var1, -99, -99, 1, 65, 172, -99, 202, 0, 0, 0, 0, 64, 15); break; case 17: func_137(&Var1, -99, -99, 1, 64, 10, -99, 1, 0, 0, 0, 0, 66, 16); break; case 18: func_137(&Var1, -99, -99, 5, 98, 80, -99, 240, 0, 0, 0, 0, 87, 17); break; case 19: func_137(&Var1, -99, -99, 5, 192, 96, -99, 240, 0, 0, 0, 0, 80, 18); break; case 20: func_137(&Var1, -99, -99, 1, 124, 96, -99, 11, 0, 0, 0, 0, 110, 19); break; case 21: func_137(&Var1, -99, -99, 0, 80, 114, -99, 240, 0, 0, 0, 0, 2, 20); break; case 22: func_137(&Var1, -99, -99, 6, 43, 112, -99, 82, 0, 0, 0, 0, 48, 21); break; case 23: func_137(&Var1, -99, -99, 1, 116, 144, -99, 2, 0, 0, 0, 0, 108, 22); break; case 24: func_137(&Var1, -99, -99, 1, 63, 38, -99, 3, 0, 0, 0, 0, 63, 23); break; case 25: func_137(&Var1, -99, -99, 2, 64, 10, -99, 240, 0, 0, 0, 0, 41, 24); break; default: func_135(&Var1, iParam0, iParam1, 26); break; } break; case joaat("mp_f_freemode_01"): switch (iParam1) { case 0: func_137(&Var1, -99, -99, 0, 0, 0, -99, 0, -99, -99, 0, -99, 0, 31); break; case 1: func_137(&Var1, -99, -99, 5, 136, 241, -99, 47, 0, 0, 0, 0, 21, 31); break; case 2: func_137(&Var1, -99, -99, 4, 1, 96, -99, 32, 0, 0, 0, 7, 215, 0); break; case 3: func_137(&Var1, -99, -99, 1, 73, 241, -99, 3, 0, 0, 0, 0, 25, 1); break; case 4: func_137(&Var1, -99, -99, 2, 88, 217, -99, 32, 0, 0, 0, 0, 33, 2); break; case 5: func_137(&Var1, -99, -99, 9, 7, 98, -99, 32, 0, 0, 0, 7, 153, 3); break; case 6: func_137(&Var1, -99, -99, 1, 140, 241, -99, 7, 0, 0, 0, 31, 16, 4); break; case 7: func_137(&Var1, -99, -99, 4, 139, 112, -99, 32, 0, 0, 0, 49, 78, 5); break; case 8: func_137(&Var1, -99, -99, 1, 193, 48, -99, 108, 0, 0, 0, 0, 17, 6); break; case 9: func_137(&Var1, -99, -99, 5, 114, 97, -99, 103, 0, 0, 0, 0, 98, 7); break; case 10: func_137(&Var1, -99, -99, 9, 134, 239, -99, 32, 0, 0, 0, 2, 144, 8); break; case 11: func_137(&Var1, -99, -99, 5, 152, 96, -99, 10, 0, 0, 0, 31, 96, 9); break; case 12: func_137(&Var1, -99, -99, 6, 129, 1, -99, 96, 0, 0, 0, 5, 120, 10); break; case 13: func_137(&Var1, -99, -99, 5, 0, 0, -99, 10, 0, 0, 0, 0, 130, 31); break; case 14: func_137(&Var1, -99, -99, 4, 159, 96, -99, 32, 0, 0, 0, 22, 214, 11); break; case 15: func_137(&Var1, -99, -99, 9, 232, 213, -99, 32, 0, 0, 0, 22, 147, 12); break; case 16: func_137(&Var1, -99, -99, 2, 8, 98, -99, 32, 0, 0, 0, 33, 39, 13); break; case 17: func_137(&Var1, -99, -99, 5, 150, 235, -99, 106, 0, 0, 0, 0, 128, 14); break; case 18: func_137(&Var1, -99, -99, 6, 96, 97, -99, 7, 0, 0, 0, 32, 114, 15); break; case 19: func_137(&Var1, -99, -99, 4, 48, 64, -99, 32, 0, 0, 0, 0, 89, 16); break; case 20: func_137(&Var1, -99, -99, 4, 62, 64, -99, 32, 0, 0, 0, 0, 78, 17); break; case 21: func_137(&Var1, -99, -99, 4, 49, 65, -99, 32, 0, 0, 0, 8, 80, 31); break; case 22: func_137(&Var1, -99, -99, 3, 20, 16, -99, 32, 0, 0, 0, 0, 49, 18); break; case 23: func_137(&Var1, -99, -99, 0, 73, 178, -99, 32, 0, 0, 0, 38, 11, 19); break; case 24: func_137(&Var1, -99, -99, 5, 135, 53, -99, 9, 0, 0, 0, 29, 27, 20); break; case 25: func_137(&Var1, -99, -99, 7, 233, 176, -99, 120, 0, 0, 0, 11, 160, 21); break; case 26: func_137(&Var1, -99, -99, 4, 34, 179, -99, 32, 0, 0, 0, 0, 77, 22); break; case 27: func_137(&Var1, -99, -99, 15, 131, 93, -99, 32, 0, 0, 0, 0, 250, 23); break; default: func_135(&Var1, iParam0, iParam1, 28); break; } break; } return Var1; } void func_135(var uParam0, int iParam1, int iParam2, int iParam3) { int iVar0; struct<5> Var1; struct<3> Var16; struct<2> Var19; int iVar36; (*uParam0)[0] = 0; (*uParam0)[2] = -99; (*uParam0)[3] = 0; (*uParam0)[4] = 0; (*uParam0)[6] = 0; (*uParam0)[5] = 0; (*uParam0)[8] = 0; (*uParam0)[9] = 0; (*uParam0)[10] = 0; (*uParam0)[1] = 0; (*uParam0)[7] = 0; (*uParam0)[11] = 0; (*uParam0)[13] = -99; (*uParam0)[14] = -99; uParam0->f_16 = 0; iVar0 = 0; if (iParam1 == joaat("player_zero")) { iVar0 = 0; (*uParam0)[13] = (10 + (iParam2 - iParam3)); } else if (iParam1 == joaat("player_one")) { iVar0 = 1; (*uParam0)[13] = (9 + (iParam2 - iParam3)); } else if (iParam1 == joaat("player_two")) { iVar0 = 2; (*uParam0)[13] = (9 + (iParam2 - iParam3)); } else if (iParam1 == joaat("mp_m_freemode_01")) { iVar0 = 3; } else if (iParam1 == joaat("mp_f_freemode_01")) { iVar0 = 4; } FILES::_0xF3FBE2D50A6A8C28(iVar0, false); FILES::GET_SHOP_PED_QUERY_OUTFIT((iParam2 - iParam3), &Var1); if (!FILES::IS_CONTENT_ITEM_LOCKED(Var1)) { iVar36 = 0; while (iVar36 < Var1.f_4) { if (FILES::GET_SHOP_PED_OUTFIT_COMPONENT_VARIANT(Var1.f_1, iVar36, &Var16)) { if ((Var16.x != 0 && Var16.x != -1) && Var16.x != joaat("0")) { if (Var16.f_2 == 10) { FILES::INIT_SHOP_PED_COMPONENT(&Var19); FILES::GET_SHOP_PED_COMPONENT(Var16.x, &Var19); if (Var16.x != Var19.f_1) { uParam0->f_16 = 1; } } if (Var16.f_2 == 10 && uParam0->f_16) { (*uParam0)[func_136(Var16.f_2)] = Var16.x; uParam0->f_16 = 1; } else { (*uParam0)[func_136(Var16.f_2)] = func_129(iParam1, Var16.x, func_136(Var16.f_2), iVar0); } } else if (Var16.f_1 != -1) { (*uParam0)[func_136(Var16.f_2)] = Var16.f_1; } } iVar36++; } if (Var1.f_3 == 0) { (*uParam0)[13] = -99; } else { (*uParam0)[13] = Var1.f_1; } } } int func_136(int iParam0) { switch (iParam0) { case 0: return 0; break; case 2: return 2; break; case 3: return 3; break; case 4: return 4; break; case 6: return 6; break; case 5: return 5; break; case 8: return 8; break; case 9: return 9; break; case 10: return 10; break; case 1: return 1; break; case 7: return 7; break; case 11: return 11; break; } return 0; } void func_137(var uParam0, int iParam1, int iParam2, int iParam3, int iParam4, int iParam5, int iParam6, int iParam7, int iParam8, int iParam9, int iParam10, int iParam11, int iParam12, int iParam13) { (*uParam0)[0] = iParam1; (*uParam0)[2] = iParam2; (*uParam0)[3] = iParam3; (*uParam0)[4] = iParam4; (*uParam0)[6] = iParam5; (*uParam0)[5] = iParam6; (*uParam0)[8] = iParam7; (*uParam0)[9] = iParam8; (*uParam0)[10] = iParam9; (*uParam0)[1] = iParam10; (*uParam0)[7] = iParam11; (*uParam0)[11] = iParam12; (*uParam0)[13] = iParam13; (*uParam0)[14] = -99; } int func_138(int iParam0, int iParam1, int iParam2, int iParam3) { switch (iParam0) { case joaat("player_zero"): switch (iParam1) { case 14: if (iParam2 == 16) { return 1; } break; } break; case joaat("player_one"): switch (iParam1) { case 14: if ((iParam2 == 40 || (iParam2 >= 41 && iParam2 <= 56)) || (iParam2 >= 64 && iParam2 <= 79)) { return 1; } break; } break; case joaat("player_two"): switch (iParam1) { case 14: if ((iParam2 >= 17 && iParam2 <= 18) || (iParam2 >= 71 && iParam2 <= 86)) { return 1; } break; } break; case joaat("mp_m_freemode_01"): switch (iParam1) { case 14: if (iParam2 >= 18 && iParam2 <= 130) { return 1; } else if (iParam2 >= 10 && iParam2 <= 17) { return 1; } else if (iParam2 >= 327) { if (iParam3 == -1) { iParam3 = func_124(iParam0, iParam2, 14, 3); } return (FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("HAT"), 1) || FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(func_124(iParam0, iParam2, 14, 3), -1842686353, 1)); } break; case 1: if (iParam2 >= 26) { if (iParam3 == -1) { iParam3 = func_124(iParam0, iParam2, 1, 3); } return (FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("HAT"), 0) || FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(func_124(iParam0, iParam2, 1, 3), -1842686353, 0)); } break; } break; case joaat("mp_f_freemode_01"): switch (iParam1) { case 14: if (iParam2 >= 18 && iParam2 <= 130) { return 1; } else if (iParam2 >= 10 && iParam2 <= 17) { return 1; } else if (iParam2 >= 327) { if (iParam3 == -1) { iParam3 = func_124(iParam0, iParam2, 14, 4); } return (FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("HAT"), 1) || FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(func_124(iParam0, iParam2, 14, 4), -1842686353, 1)); } break; case 1: if (iParam2 >= 26) { if (iParam3 == -1) { iParam3 = func_124(iParam0, iParam2, 1, 4); } return (FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("HAT"), 0) || FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(func_124(iParam0, iParam2, 1, 4), -1842686353, 0)); } break; } break; } return 0; } int func_139(int iParam0, int iParam1, int iParam2, int iParam3) { if (iParam0 == joaat("player_zero")) { if (iParam1 == 6) { if (iParam2 == 10) { return 1; } } else if (iParam1 == 8) { if ((iParam2 == 9 || iParam2 == 7) || iParam2 == 23) { return 1; } } else if (iParam1 == 9) { if (iParam2 >= 9 && iParam2 <= 14) { return 1; } } else if (iParam1 == 14) { if ((((((((((((((((iParam2 == 12 || iParam2 == 59) || iParam2 == 60) || iParam2 == 31) || iParam2 == 32) || iParam2 == 33) || iParam2 == 34) || iParam2 == 35) || iParam2 == 36) || iParam2 == 37) || iParam2 == 38) || iParam2 == 39) || iParam2 == 40) || iParam2 == 41) || (iParam2 >= 42 && iParam2 <= 44)) || iParam2 == 54) || iParam2 == 55) { return 1; } } } else if (iParam0 == joaat("player_one")) { if (iParam1 == 2) { if (iParam2 == 20) { return 1; } } else if (iParam1 == 8) { if ((iParam2 == 3 || iParam2 == 5) || iParam2 == 9) { return 1; } } else if (iParam1 == 9) { if (iParam2 >= 5 && iParam2 <= 10) { return 1; } } else if (iParam1 == 14) { if (((((((((((((iParam2 == 82 || iParam2 == 10) || iParam2 == 26) || iParam2 == 27) || iParam2 == 28) || iParam2 == 29) || iParam2 == 30) || iParam2 == 31) || iParam2 == 32) || iParam2 == 33) || iParam2 == 34) || iParam2 == 35) || iParam2 == 36) || (iParam2 >= 37 && iParam2 <= 39)) { return 1; } } } else if (iParam0 == joaat("player_two")) { if (iParam1 == 8) { if (iParam2 == 14 || iParam2 == 7) { return 1; } } else if (iParam1 == 9) { if (((iParam2 == 8 || (iParam2 >= 9 && iParam2 <= 14)) || iParam2 == 15) || iParam2 == 16) { return 1; } } else if (iParam1 == 14) { if (((((((((((((iParam2 == 88 || iParam2 == 12) || iParam2 == 47) || iParam2 == 48) || iParam2 == 49) || iParam2 == 50) || iParam2 == 51) || iParam2 == 52) || iParam2 == 53) || iParam2 == 54) || iParam2 == 55) || iParam2 == 56) || iParam2 == 57) || (iParam2 >= 58 && iParam2 <= 60)) { return 1; } } } else if (iParam0 == joaat("mp_m_freemode_01")) { if (iParam1 == 1) { if (iParam2 > 0) { if (iParam2 >= 26) { if (iParam3 == -1) { iParam3 = func_124(iParam0, iParam2, 1, 3); } if (FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("HAT"), 0) || FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("HAIR_SHRINK"), 0)) { return 0; } } return 1; } } } else if (iParam0 == joaat("mp_f_freemode_01")) { if (iParam1 == 1) { if (iParam2 > 0) { if (iParam2 >= 26) { if (iParam3 == -1) { iParam3 = func_124(iParam0, iParam2, 1, 4); } if (FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("HAT"), 0) || FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("HAIR_SHRINK"), 0)) { return 0; } } return 1; } } } return 0; } int func_140(int iParam0, int iParam1, int iParam2, int iParam3) { switch (iParam0) { case joaat("player_zero"): if (iParam1 == 14) { if ((((((((iParam2 == 58 || iParam2 == 61) || (iParam2 >= 62 && iParam2 <= 69)) || (iParam2 >= 70 && iParam2 <= 79)) || (iParam2 >= 80 && iParam2 <= 89)) || iParam2 == 90) || (iParam2 >= 91 && iParam2 <= 102)) || (iParam2 >= 103 && iParam2 <= 110)) || iParam2 == 111) { return 1; } } break; case joaat("player_one"): if (iParam1 == 14) { if (((((((((((iParam2 >= 83 && iParam2 <= 92) || iParam2 == 93) || iParam2 == 94) || (iParam2 >= 95 && iParam2 <= 101)) || (iParam2 >= 102 && iParam2 <= 111)) || (iParam2 >= 112 && iParam2 <= 121)) || (iParam2 >= 122 && iParam2 <= 131)) || (iParam2 >= 132 && iParam2 <= 139)) || (iParam2 >= 140 && iParam2 <= 149)) || (iParam2 >= 150 && iParam2 <= 156)) || iParam2 == 157) { return 1; } } break; case joaat("player_two"): if (iParam1 == 14) { if (((((((((iParam2 == 89 || (iParam2 >= 90 && iParam2 <= 99)) || (iParam2 >= 100 && iParam2 <= 109)) || iParam2 == 111) || iParam2 == 112) || (iParam2 >= 113 && iParam2 <= 122)) || (iParam2 >= 123 && iParam2 <= 132)) || (iParam2 >= 133 && iParam2 <= 142)) || (iParam2 >= 143 && iParam2 <= 152)) || iParam2 == 153) { return 1; } } break; case joaat("mp_m_freemode_01"): if (iParam1 == 14) { if (iParam2 >= 155 && iParam2 <= 318) { return 1; } else if (iParam2 >= 327) { if (iParam3 == -1) { iParam3 = func_124(iParam0, iParam2, 14, 3); } return FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("GLASSES"), 1); } } break; case joaat("mp_f_freemode_01"): if (iParam1 == 14) { if (iParam2 >= 155 && iParam2 <= 318) { return 1; } else if (iParam2 >= 327) { if (iParam3 == -1) { iParam3 = func_124(iParam0, iParam2, 14, 4); } return FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(iParam3, joaat("GLASSES"), 1); } } break; } return 0; } int func_141(int iParam0, int iParam1) { int iVar0; int iVar1; if (PED::IS_PED_INJURED(iParam0)) { return -99; } iVar0 = PED::GET_PED_PROP_INDEX(iParam0, iParam1); if (iVar0 == -1) { return func_130(iParam1); } iVar1 = PED::GET_PED_PROP_TEXTURE_INDEX(iParam0, iParam1); return func_127(iParam0, iVar0, iVar1, iParam1); } int func_142(int iParam0, int iParam1) { int iVar0; int iVar1; int iVar2; if (((iParam1 == 12 || iParam1 == 13) || iParam1 == 14) || PED::IS_PED_INJURED(iParam0)) { return -99; } iVar0 = func_112(iParam1); iVar1 = PED::GET_PED_DRAWABLE_VARIATION(iParam0, iVar0); iVar2 = PED::GET_PED_TEXTURE_VARIATION(iParam0, iVar0); return func_143(iParam0, iVar1, iVar2, iParam1); } int func_143(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; int iVar1; int iVar2; int iVar3; int iVar4; int iVar5; iVar0 = func_112(iParam3); iVar1 = PED::GET_NUMBER_OF_PED_DRAWABLE_VARIATIONS(iParam0, iVar0); iVar3 = 0; while (iVar3 <= (iVar1 - 1)) { iVar5 = PED::GET_NUMBER_OF_PED_TEXTURE_VARIATIONS(iParam0, iVar0, iVar3); if (iVar3 != iParam1) { iVar2 = (iVar2 + iVar5); } else { iVar4 = 0; while (iVar4 <= (iVar5 - 1)) { if (iVar3 == iParam1 && iVar4 == iParam2) { return iVar2; } else { iVar2++; } iVar4++; } } iVar3++; } return -99; } void func_144(int iParam0) { if (MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 1) && !MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 6)) { func_151(iParam0, Global_76647[1 /*14*/].f_5, Global_76647[1 /*14*/].f_2, 2, Global_76647[1 /*14*/].f_1, 1, 0); } if (MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 1) && MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 6)) { if (iParam0 == 12) { func_145(Global_2621444, 2, 1, 1, -1); } else if (iParam0 == 13) { } else if (iParam0 == 14) { func_145(Global_2621444, 2, 1, 1, -1); } else { func_145(Global_2621444, 2, 1, 1, -1); } } } void func_145(int iParam0, int iParam1, bool bParam2, bool bParam3, int iParam4) { int iVar0; int iVar1; int iVar2; int iVar3; iVar0 = Global_76644; if (iParam4 != -1) { iVar0 = iParam4; } if (func_150(iParam0, iParam1, &iVar2, &iVar1, bParam2, bParam3)) { iVar3 = func_149(iVar2, iVar0, 0); MISC::SET_BIT(&iVar3, iVar1); func_146(iVar2, iVar3, iVar0, 1, 0); } } void func_146(int iParam0, int iParam1, int iParam2, bool bParam3, bool bParam4) { int iVar0; if (bParam4) { } iVar0 = Global_2551832[iParam0 /*3*/][func_147(iParam2)]; if (iVar0 != 0) { STATS::STAT_SET_INT(iVar0, iParam1, bParam3); } } int func_147(var uParam0) { int iVar0; int iVar1; iVar0 = uParam0; if (iVar0 == -1) { iVar1 = func_148(); if (iVar1 > -1) { Global_2551544 = 0; iVar0 = iVar1; } else { iVar0 = 0; Global_2551544 = 1; } } return iVar0; } var func_148() { return Global_1312763; } int func_149(int iParam0, int iParam1, int iParam2) { int iVar0; var uVar1; if (iParam0 != 11771) { if (iParam2 == 0) { } iVar0 = Global_2551832[iParam0 /*3*/][func_147(iParam1)]; if (STATS::STAT_GET_INT(iVar0, &uVar1, -1)) { return uVar1; } } return 0; } bool func_150(int iParam0, int iParam1, var uParam2, var uParam3, bool bParam4, bool bParam5) { int iVar0; *uParam2 = 11771; if ((bParam4 && Global_4268238) || (!bParam4 && bParam5)) { switch (iParam1) { case 1: switch (iParam0) { case joaat("DLC_MP_STUNT_M_PHEAD_15_0"): case joaat("DLC_MP_STUNT_M_PHEAD_0_0"): *uParam2 = 971; *uParam3 = 19; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_1"): case joaat("DLC_MP_STUNT_M_PHEAD_0_1"): *uParam2 = 971; *uParam3 = 20; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_2"): case joaat("DLC_MP_STUNT_M_PHEAD_0_2"): *uParam2 = 971; *uParam3 = 21; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_3"): case joaat("DLC_MP_STUNT_M_PHEAD_0_3"): *uParam2 = 971; *uParam3 = 22; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_4"): case joaat("DLC_MP_STUNT_M_PHEAD_0_4"): *uParam2 = 971; *uParam3 = 23; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_5"): case joaat("DLC_MP_STUNT_M_PHEAD_0_5"): *uParam2 = 971; *uParam3 = 24; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_6"): case joaat("DLC_MP_STUNT_M_PHEAD_0_6"): *uParam2 = 971; *uParam3 = 25; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_7"): case joaat("DLC_MP_STUNT_M_PHEAD_0_7"): *uParam2 = 971; *uParam3 = 26; return 1; break; case joaat("DLC_MP_BIKER_M_SPECIAL_0_0"): case joaat("DLC_MP_BIKER_M_SPECIAL_2_0"): case joaat("DLC_MP_BIKER_M_SPECIAL_4_0"): *uParam2 = 935; *uParam3 = 0; return 1; break; case joaat("DLC_MP_BIKER_M_SPECIAL_0_1"): case joaat("DLC_MP_BIKER_M_SPECIAL_2_1"): case joaat("DLC_MP_BIKER_M_SPECIAL_4_1"): *uParam2 = 935; *uParam3 = 1; return 1; break; case joaat("DLC_MP_BIKER_M_SPECIAL_0_2"): case joaat("DLC_MP_BIKER_M_SPECIAL_2_2"): case joaat("DLC_MP_BIKER_M_SPECIAL_4_2"): *uParam2 = 935; *uParam3 = 2; return 1; break; case joaat("DLC_MP_BIKER_M_SPECIAL_0_3"): case joaat("DLC_MP_BIKER_M_SPECIAL_2_3"): case joaat("DLC_MP_BIKER_M_SPECIAL_4_3"): *uParam2 = 935; *uParam3 = 3; return 1; break; case joaat("DLC_MP_BIKER_M_SPECIAL_0_4"): case joaat("DLC_MP_BIKER_M_SPECIAL_2_4"): case joaat("DLC_MP_BIKER_M_SPECIAL_4_4"): *uParam2 = 935; *uParam3 = 4; return 1; break; case joaat("DLC_MP_BIKER_M_SPECIAL_0_5"): case joaat("DLC_MP_BIKER_M_SPECIAL_2_5"): case joaat("DLC_MP_BIKER_M_SPECIAL_4_5"): *uParam2 = 935; *uParam3 = 5; return 1; break; case joaat("DLC_MP_BIKER_M_SPECIAL_0_7"): case joaat("DLC_MP_BIKER_M_SPECIAL_2_7"): case joaat("DLC_MP_BIKER_M_SPECIAL_4_7"): *uParam2 = 935; *uParam3 = 7; return 1; break; case joaat("DLC_MP_BIKER_M_SPECIAL_0_8"): case joaat("DLC_MP_BIKER_M_SPECIAL_2_8"): case joaat("DLC_MP_BIKER_M_SPECIAL_4_8"): *uParam2 = 935; *uParam3 = 8; return 1; break; case joaat("DLC_MP_BIKER_M_SPECIAL_0_11"): case joaat("DLC_MP_BIKER_M_SPECIAL_2_11"): case joaat("DLC_MP_BIKER_M_SPECIAL_4_11"): *uParam2 = 935; *uParam3 = 11; return 1; break; } break; case 2: switch (iParam0) { case joaat("DLC_MP_STUNT_M_PHEAD_15_0"): case joaat("DLC_MP_STUNT_M_PHEAD_0_0"): *uParam2 = 1023; *uParam3 = 19; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_1"): case joaat("DLC_MP_STUNT_M_PHEAD_0_1"): *uParam2 = 1023; *uParam3 = 20; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_2"): case joaat("DLC_MP_STUNT_M_PHEAD_0_2"): *uParam2 = 1023; *uParam3 = 21; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_3"): case joaat("DLC_MP_STUNT_M_PHEAD_0_3"): *uParam2 = 1023; *uParam3 = 22; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_4"): case joaat("DLC_MP_STUNT_M_PHEAD_0_4"): *uParam2 = 1023; *uParam3 = 23; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_5"): case joaat("DLC_MP_STUNT_M_PHEAD_0_5"): *uParam2 = 1023; *uParam3 = 24; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_6"): case joaat("DLC_MP_STUNT_M_PHEAD_0_6"): *uParam2 = 1023; *uParam3 = 25; return 1; break; case joaat("DLC_MP_STUNT_M_PHEAD_15_7"): case joaat("DLC_MP_STUNT_M_PHEAD_0_7"): *uParam2 = 1023; *uParam3 = 26; return 1; break; } break; } } else { switch (iParam1) { case 1: switch (iParam0) { case joaat("DLC_MP_STUNT_F_PHEAD_15_0"): case joaat("DLC_MP_STUNT_F_PHEAD_0_0"): *uParam2 = 971; *uParam3 = 19; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_1"): case joaat("DLC_MP_STUNT_F_PHEAD_0_1"): *uParam2 = 971; *uParam3 = 20; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_2"): case joaat("DLC_MP_STUNT_F_PHEAD_0_2"): *uParam2 = 971; *uParam3 = 21; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_3"): case joaat("DLC_MP_STUNT_F_PHEAD_0_3"): *uParam2 = 971; *uParam3 = 22; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_4"): case joaat("DLC_MP_STUNT_F_PHEAD_0_4"): *uParam2 = 971; *uParam3 = 23; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_5"): case joaat("DLC_MP_STUNT_F_PHEAD_0_5"): *uParam2 = 971; *uParam3 = 24; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_6"): case joaat("DLC_MP_STUNT_F_PHEAD_0_6"): *uParam2 = 971; *uParam3 = 25; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_7"): case joaat("DLC_MP_STUNT_F_PHEAD_0_7"): *uParam2 = 971; *uParam3 = 26; return 1; break; } break; case 2: switch (iParam0) { case joaat("DLC_MP_STUNT_F_PHEAD_15_0"): case joaat("DLC_MP_STUNT_F_PHEAD_0_0"): *uParam2 = 1023; *uParam3 = 19; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_1"): case joaat("DLC_MP_STUNT_F_PHEAD_0_1"): *uParam2 = 1023; *uParam3 = 20; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_2"): case joaat("DLC_MP_STUNT_F_PHEAD_0_2"): *uParam2 = 1023; *uParam3 = 21; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_3"): case joaat("DLC_MP_STUNT_F_PHEAD_0_3"): *uParam2 = 1023; *uParam3 = 22; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_4"): case joaat("DLC_MP_STUNT_F_PHEAD_0_4"): *uParam2 = 1023; *uParam3 = 23; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_5"): case joaat("DLC_MP_STUNT_F_PHEAD_0_5"): *uParam2 = 1023; *uParam3 = 24; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_6"): case joaat("DLC_MP_STUNT_F_PHEAD_0_6"): *uParam2 = 1023; *uParam3 = 25; return 1; break; case joaat("DLC_MP_STUNT_F_PHEAD_15_7"): case joaat("DLC_MP_STUNT_F_PHEAD_0_7"): *uParam2 = 1023; *uParam3 = 26; return 1; break; } break; } } iVar0 = -1; if (bParam4) { if (Global_4268238) { iVar0 = PED::_0x1E77FA7A62EE6C4C(iParam0); } else { iVar0 = PED::_0xF033419D1B81FAE8(iParam0); } } else if (bParam5) { iVar0 = PED::_0x1E77FA7A62EE6C4C(iParam0); } else { iVar0 = PED::_0xF033419D1B81FAE8(iParam0); } if (iVar0 == -1) { return 0; } switch (iParam1) { case 1: switch (SYSTEM::FLOOR((SYSTEM::TO_FLOAT(iVar0) / 32f))) { case 0: *uParam2 = 1760; break; case 1: *uParam2 = 1761; break; case 2: *uParam2 = 1762; break; case 3: *uParam2 = 1763; break; case 4: *uParam2 = 1764; break; case 5: *uParam2 = 1765; break; case 6: *uParam2 = 1772; break; case 7: *uParam2 = 1773; break; case 8: *uParam2 = 1774; break; case 9: *uParam2 = 1775; break; case 10: *uParam2 = 1776; break; case 11: *uParam2 = 1777; break; case 12: *uParam2 = 1778; break; case 13: *uParam2 = 1786; break; case 14: *uParam2 = 1787; break; case 15: *uParam2 = 1888; break; case 16: *uParam2 = 1889; break; case 17: *uParam2 = 1920; break; case 18: *uParam2 = 1934; break; case 19: *uParam2 = 1935; break; case 20: *uParam2 = 1936; break; case 21: *uParam2 = 1937; break; case 22: *uParam2 = 1938; break; case 23: *uParam2 = 2042; break; case 24: *uParam2 = 2043; break; case 25: *uParam2 = 2069; break; case 26: *uParam2 = 2070; break; case 27: *uParam2 = 2071; break; case 28: *uParam2 = 2072; break; case 29: *uParam2 = 2073; break; case 30: *uParam2 = 2074; break; case 31: *uParam2 = 2075; break; case 32: *uParam2 = 2076; break; case 33: *uParam2 = 2077; break; case 34: *uParam2 = 2078; break; case 35: *uParam2 = 2325; break; case 36: *uParam2 = 2326; break; case 37: *uParam2 = 2390; break; case 38: *uParam2 = 2391; break; case 39: *uParam2 = 2392; break; case 40: *uParam2 = 2393; break; case 41: *uParam2 = 2452; break; case 42: *uParam2 = 2453; break; case 43: *uParam2 = 2454; break; case 44: *uParam2 = 2455; break; case 45: *uParam2 = 2456; break; case 46: *uParam2 = 2457; break; case 47: *uParam2 = 2458; break; case 48: *uParam2 = 2459; break; case 49: *uParam2 = 2460; break; case 50: *uParam2 = 2461; break; case 51: *uParam2 = 2590; break; case 52: *uParam2 = 2591; break; case 53: *uParam2 = 2592; break; case 54: *uParam2 = 2593; break; case 55: *uParam2 = 2594; break; case 56: *uParam2 = 2595; break; case 57: *uParam2 = 2596; break; case 58: *uParam2 = 2597; break; case 59: *uParam2 = 2598; break; case 60: *uParam2 = 2599; break; case 61: *uParam2 = 2600; break; case 62: *uParam2 = 3197; break; case 63: *uParam2 = 3198; break; case 64: *uParam2 = 3199; break; case 65: *uParam2 = 3200; break; case 66: *uParam2 = 3201; break; case 67: *uParam2 = 3202; break; case 68: *uParam2 = 3670; break; case 69: *uParam2 = 3671; break; case 70: *uParam2 = 3672; break; case 71: *uParam2 = 3673; break; case 72: *uParam2 = 3674; break; case 73: *uParam2 = 3675; break; case 74: *uParam2 = 3676; break; case 75: *uParam2 = 3677; break; case 76: *uParam2 = 3678; break; case 77: *uParam2 = 3679; break; case 78: *uParam2 = 3793; break; case joaat("MPSV_LP0_31"): *uParam2 = 3794; break; case 80: *uParam2 = 3795; break; case 81: *uParam2 = 3796; break; case 82: *uParam2 = 3797; break; case 83: *uParam2 = 3798; break; case 84: *uParam2 = 3799; break; case 85: *uParam2 = 3800; break; case 86: *uParam2 = 3903; break; case 87: *uParam2 = 3904; break; case 88: *uParam2 = 3905; break; case 89: *uParam2 = 5338; break; case 90: *uParam2 = 5339; break; case 91: *uParam2 = 5340; break; case 92: *uParam2 = 5341; break; case 93: *uParam2 = 5342; break; case 94: *uParam2 = 5343; break; case 95: *uParam2 = 5344; break; case 96: *uParam2 = 5345; break; case 97: *uParam2 = 5346; break; case 98: *uParam2 = 5347; break; case 99: *uParam2 = 5348; break; } switch (SYSTEM::FLOOR((SYSTEM::TO_FLOAT(iVar0) / 32f))) { case 100: *uParam2 = 5349; break; case 101: *uParam2 = 5395; break; case 102: *uParam2 = 5396; break; case 103: *uParam2 = 5397; break; case 104: *uParam2 = 5398; break; case 105: *uParam2 = 5399; break; case 106: *uParam2 = 5400; break; case 107: *uParam2 = 5401; break; case 108: *uParam2 = 5402; break; case 109: *uParam2 = 5403; break; case 110: *uParam2 = 5404; break; case 111: *uParam2 = 5405; break; case 112: *uParam2 = 5406; break; case 113: *uParam2 = 5407; break; case 114: *uParam2 = 5408; break; case 115: *uParam2 = 5409; break; case 116: *uParam2 = 5410; break; case 117: *uParam2 = 5411; break; case 118: *uParam2 = 5412; break; case 119: *uParam2 = 5413; break; case 120: *uParam2 = 5414; break; case 121: *uParam2 = 5415; break; case 122: *uParam2 = 5416; break; case 123: *uParam2 = 5417; break; case 124: *uParam2 = 6123; break; case 125: *uParam2 = 6124; break; case 126: *uParam2 = 6125; break; case 127: *uParam2 = 6126; break; case 128: *uParam2 = 6127; break; case 129: *uParam2 = 6128; break; case 130: *uParam2 = 6129; break; case 131: *uParam2 = 6130; break; case 132: *uParam2 = 6131; break; case 133: *uParam2 = 6132; break; case 134: *uParam2 = 6133; break; case 135: *uParam2 = 6134; break; case 136: *uParam2 = 6135; break; case 137: *uParam2 = 6136; break; case 138: *uParam2 = 6137; break; case 139: *uParam2 = 6436; break; case 140: *uParam2 = 6437; break; case 141: *uParam2 = 6438; break; case 142: *uParam2 = 6439; break; case 143: *uParam2 = 6440; break; case 144: *uParam2 = 6441; break; case 145: *uParam2 = 6442; break; case 146: *uParam2 = 6443; break; case 147: *uParam2 = 6444; break; case 148: *uParam2 = 6445; break; case 149: *uParam2 = 6446; break; case 150: *uParam2 = 6447; break; case 151: *uParam2 = 6448; break; case 152: *uParam2 = 6449; break; case 153: *uParam2 = 6450; break; case 154: *uParam2 = 7267; break; case 155: *uParam2 = 7268; break; case 156: *uParam2 = 7269; break; case 157: *uParam2 = 7270; break; case 158: *uParam2 = 7271; break; case 159: *uParam2 = 7272; break; case 160: *uParam2 = 7273; break; case 161: *uParam2 = 7880; break; case 162: *uParam2 = 7881; break; case 163: *uParam2 = 7882; break; case 164: *uParam2 = 7883; break; case 165: *uParam2 = 7884; break; case 166: *uParam2 = 7885; break; case 167: *uParam2 = 7886; break; case 168: *uParam2 = 7887; break; case 169: *uParam2 = 7888; break; case 170: *uParam2 = 7889; break; case 171: *uParam2 = 7890; break; case 172: *uParam2 = 7891; break; case 173: *uParam2 = 7892; break; case 174: *uParam2 = 7893; break; case 175: *uParam2 = 7894; break; case 176: *uParam2 = 8300; break; case 177: *uParam2 = 8301; break; case 178: *uParam2 = 8302; break; case 179: *uParam2 = 8303; break; case 180: *uParam2 = 8304; break; case 181: *uParam2 = 8305; break; case 182: *uParam2 = 8306; break; case 183: *uParam2 = 8307; break; case 184: *uParam2 = 8308; break; case 185: *uParam2 = 8309; break; case 186: *uParam2 = 8310; break; case 187: *uParam2 = 8311; break; case 188: *uParam2 = 8312; break; case 189: *uParam2 = 8313; break; case 190: *uParam2 = 8314; break; case 191: *uParam2 = 8315; break; case 192: *uParam2 = 8316; break; case 193: *uParam2 = 8317; break; case 194: *uParam2 = 8318; break; case 195: *uParam2 = 8319; break; case 196: *uParam2 = 8320; break; case 197: *uParam2 = 8321; break; case 198: *uParam2 = 8322; break; case 199: *uParam2 = 8323; break; } switch (SYSTEM::FLOOR((SYSTEM::TO_FLOAT(iVar0) / 32f))) { case 200: *uParam2 = 8324; break; case 201: *uParam2 = 8937; break; case 202: *uParam2 = 8938; break; case 203: *uParam2 = 8939; break; case 204: *uParam2 = 8940; break; case 205: *uParam2 = 8941; break; case 206: *uParam2 = 9420; break; case 207: *uParam2 = 9421; break; case 208: *uParam2 = 9422; break; case 209: *uParam2 = 9423; break; case 210: *uParam2 = 9424; break; case 211: *uParam2 = 9425; break; case 212: *uParam2 = 9426; break; case 213: *uParam2 = 9427; break; case 214: *uParam2 = 9428; break; case 215: *uParam2 = 9429; break; case 216: *uParam2 = 9430; break; case 217: *uParam2 = 9431; break; case 218: *uParam2 = 9432; break; case 219: *uParam2 = 9433; break; case 220: *uParam2 = 9434; break; case 221: *uParam2 = 9435; break; case 222: *uParam2 = 9436; break; case 223: *uParam2 = 9437; break; case 224: *uParam2 = 9438; break; case 225: *uParam2 = 9439; break; case 226: *uParam2 = 9440; break; case 227: *uParam2 = 9441; break; case 228: *uParam2 = 9442; break; case 229: *uParam2 = 9443; break; case 230: *uParam2 = 9444; break; } break; case 2: switch (SYSTEM::FLOOR((SYSTEM::TO_FLOAT(iVar0) / 32f))) { case 0: *uParam2 = 1766; break; case 1: *uParam2 = 1767; break; case 2: *uParam2 = 1768; break; case 3: *uParam2 = 1769; break; case 4: *uParam2 = 1770; break; case 5: *uParam2 = 1771; break; case 6: *uParam2 = 1779; break; case 7: *uParam2 = 1780; break; case 8: *uParam2 = 1781; break; case 9: *uParam2 = 1782; break; case 10: *uParam2 = 1783; break; case 11: *uParam2 = 1784; break; case 12: *uParam2 = 1785; break; case 13: *uParam2 = 1788; break; case 14: *uParam2 = 1789; break; case 15: *uParam2 = 1890; break; case 16: *uParam2 = 1891; break; case 17: *uParam2 = 1921; break; case 18: *uParam2 = 1939; break; case 19: *uParam2 = 1940; break; case 20: *uParam2 = 1941; break; case 21: *uParam2 = 1942; break; case 22: *uParam2 = 1943; break; case 23: *uParam2 = 2044; break; case 24: *uParam2 = 2045; break; case 25: *uParam2 = 2079; break; case 26: *uParam2 = 2080; break; case 27: *uParam2 = 2081; break; case 28: *uParam2 = 2082; break; case 29: *uParam2 = 2083; break; case 30: *uParam2 = 2084; break; case 31: *uParam2 = 2085; break; case 32: *uParam2 = 2086; break; case 33: *uParam2 = 2087; break; case 34: *uParam2 = 2088; break; case 35: *uParam2 = 2327; break; case 36: *uParam2 = 2328; break; case 37: *uParam2 = 2394; break; case 38: *uParam2 = 2395; break; case 39: *uParam2 = 2396; break; case 40: *uParam2 = 2397; break; case 41: *uParam2 = 2462; break; case 42: *uParam2 = 2463; break; case 43: *uParam2 = 2464; break; case 44: *uParam2 = 2465; break; case 45: *uParam2 = 2466; break; case 46: *uParam2 = 2467; break; case 47: *uParam2 = 2468; break; case 48: *uParam2 = 2469; break; case 49: *uParam2 = 2470; break; case 50: *uParam2 = 2471; break; case 51: *uParam2 = 2601; break; case 52: *uParam2 = 2602; break; case 53: *uParam2 = 2603; break; case 54: *uParam2 = 2604; break; case 55: *uParam2 = 2605; break; case 56: *uParam2 = 2606; break; case 57: *uParam2 = 2607; break; case 58: *uParam2 = 2608; break; case 59: *uParam2 = 2609; break; case 60: *uParam2 = 2610; break; case 61: *uParam2 = 2611; break; case 62: *uParam2 = 3203; break; case 63: *uParam2 = 3204; break; case 64: *uParam2 = 3205; break; case 65: *uParam2 = 3206; break; case 66: *uParam2 = 3207; break; case 67: *uParam2 = 3208; break; case 68: *uParam2 = 3680; break; case 69: *uParam2 = 3681; break; case 70: *uParam2 = 3682; break; case 71: *uParam2 = 3683; break; case 72: *uParam2 = 3684; break; case 73: *uParam2 = 3685; break; case 74: *uParam2 = 3686; break; case 75: *uParam2 = 3687; break; case 76: *uParam2 = 3688; break; case 77: *uParam2 = 3689; break; case 78: *uParam2 = 3801; break; case joaat("MPSV_LP0_31"): *uParam2 = 3802; break; case 80: *uParam2 = 3803; break; case 81: *uParam2 = 3804; break; case 82: *uParam2 = 3805; break; case 83: *uParam2 = 3806; break; case 84: *uParam2 = 3807; break; case 85: *uParam2 = 3808; break; case 86: *uParam2 = 3906; break; case 87: *uParam2 = 3907; break; case 88: *uParam2 = 3908; break; case 89: *uParam2 = 5350; break; case 90: *uParam2 = 5351; break; case 91: *uParam2 = 5352; break; case 92: *uParam2 = 5353; break; case 93: *uParam2 = 5354; break; case 94: *uParam2 = 5355; break; case 95: *uParam2 = 5356; break; case 96: *uParam2 = 5357; break; case 97: *uParam2 = 5358; break; case 98: *uParam2 = 5359; break; case 99: *uParam2 = 5360; break; } switch (SYSTEM::FLOOR((SYSTEM::TO_FLOAT(iVar0) / 32f))) { case 100: *uParam2 = 5361; break; case 101: *uParam2 = 5418; break; case 102: *uParam2 = 5419; break; case 103: *uParam2 = 5420; break; case 104: *uParam2 = 5421; break; case 105: *uParam2 = 5422; break; case 106: *uParam2 = 5423; break; case 107: *uParam2 = 5424; break; case 108: *uParam2 = 5425; break; case 109: *uParam2 = 5426; break; case 110: *uParam2 = 5427; break; case 111: *uParam2 = 5428; break; case 112: *uParam2 = 5429; break; case 113: *uParam2 = 5430; break; case 114: *uParam2 = 5431; break; case 115: *uParam2 = 5432; break; case 116: *uParam2 = 5433; break; case 117: *uParam2 = 5434; break; case 118: *uParam2 = 5435; break; case 119: *uParam2 = 5436; break; case 120: *uParam2 = 5437; break; case 121: *uParam2 = 5438; break; case 122: *uParam2 = 5439; break; case 123: *uParam2 = 5440; break; case 124: *uParam2 = 6138; break; case 125: *uParam2 = 6139; break; case 126: *uParam2 = 6140; break; case 127: *uParam2 = 6141; break; case 128: *uParam2 = 6142; break; case 129: *uParam2 = 6143; break; case 130: *uParam2 = 6144; break; case 131: *uParam2 = 6145; break; case 132: *uParam2 = 6146; break; case 133: *uParam2 = 6147; break; case 134: *uParam2 = 6148; break; case 135: *uParam2 = 6149; break; case 136: *uParam2 = 6150; break; case 137: *uParam2 = 6151; break; case 138: *uParam2 = 6152; break; case 139: *uParam2 = 6451; break; case 140: *uParam2 = 6452; break; case 141: *uParam2 = 6453; break; case 142: *uParam2 = 6454; break; case 143: *uParam2 = 6455; break; case 144: *uParam2 = 6456; break; case 145: *uParam2 = 6457; break; case 146: *uParam2 = 6458; break; case 147: *uParam2 = 6459; break; case 148: *uParam2 = 6460; break; case 149: *uParam2 = 6461; break; case 150: *uParam2 = 6462; break; case 151: *uParam2 = 6463; break; case 152: *uParam2 = 6464; break; case 153: *uParam2 = 6465; break; case 154: *uParam2 = 7274; break; case 155: *uParam2 = 7275; break; case 156: *uParam2 = 7276; break; case 157: *uParam2 = 7277; break; case 158: *uParam2 = 7278; break; case 159: *uParam2 = 7279; break; case 160: *uParam2 = 7280; break; case 161: *uParam2 = 7895; break; case 162: *uParam2 = 7896; break; case 163: *uParam2 = 7897; break; case 164: *uParam2 = 7898; break; case 165: *uParam2 = 7899; break; case 166: *uParam2 = 7900; break; case 167: *uParam2 = 7901; break; case 168: *uParam2 = 7902; break; case 169: *uParam2 = 7903; break; case 170: *uParam2 = 7904; break; case 171: *uParam2 = 7905; break; case 172: *uParam2 = 7906; break; case 173: *uParam2 = 7907; break; case 174: *uParam2 = 7908; break; case 175: *uParam2 = 7909; break; case 176: *uParam2 = 8325; break; case 177: *uParam2 = 8326; break; case 178: *uParam2 = 8327; break; case 179: *uParam2 = 8328; break; case 180: *uParam2 = 8329; break; case 181: *uParam2 = 8330; break; case 182: *uParam2 = 8331; break; case 183: *uParam2 = 8332; break; case 184: *uParam2 = 8333; break; case 185: *uParam2 = 8334; break; case 186: *uParam2 = 8335; break; case 187: *uParam2 = 8336; break; case 188: *uParam2 = 8337; break; case 189: *uParam2 = 8338; break; case 190: *uParam2 = 8339; break; case 191: *uParam2 = 8340; break; case 192: *uParam2 = 8341; break; case 193: *uParam2 = 8342; break; case 194: *uParam2 = 8343; break; case 195: *uParam2 = 8344; break; case 196: *uParam2 = 8345; break; case 197: *uParam2 = 8346; break; case 198: *uParam2 = 8347; break; case 199: *uParam2 = 8348; break; } switch (SYSTEM::FLOOR((SYSTEM::TO_FLOAT(iVar0) / 32f))) { case 200: *uParam2 = 8349; break; case 201: *uParam2 = 8942; break; case 202: *uParam2 = 8943; break; case 203: *uParam2 = 8944; break; case 204: *uParam2 = 8945; break; case 205: *uParam2 = 8946; break; case 206: *uParam2 = 9445; break; case 207: *uParam2 = 9446; break; case 208: *uParam2 = 9447; break; case 209: *uParam2 = 9448; break; case 210: *uParam2 = 9449; break; case 211: *uParam2 = 9450; break; case 212: *uParam2 = 9451; break; case 213: *uParam2 = 9452; break; case 214: *uParam2 = 9453; break; case 215: *uParam2 = 9454; break; case 216: *uParam2 = 9455; break; case 217: *uParam2 = 9456; break; case 218: *uParam2 = 9457; break; case 219: *uParam2 = 9458; break; case 220: *uParam2 = 9459; break; case 221: *uParam2 = 9460; break; case 222: *uParam2 = 9461; break; case 223: *uParam2 = 9462; break; case 224: *uParam2 = 9463; break; case 225: *uParam2 = 9464; break; case 226: *uParam2 = 9465; break; case 227: *uParam2 = 9466; break; case 228: *uParam2 = 9467; break; case 229: *uParam2 = 9468; break; case 230: *uParam2 = 9469; break; } break; } *uParam3 = (iVar0 % 32); return *uParam2 != 11771; } int func_151(int iParam0, int iParam1, int iParam2, int iParam3, int iParam4, int iParam5, int iParam6) { if (iParam0 == 0) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/][iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/][iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/][iParam3], iParam4); } else if (iParam0 == 1) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_4[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_4[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_4[iParam3], iParam4); } else if (iParam0 == 2) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_8[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_8[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_8[iParam3], iParam4); } else if (iParam0 == 3) { if (iParam2 == 0) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_12[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_12[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_12[iParam3], iParam4); } else if (iParam2 == 1) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_16[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_16[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_16[iParam3], iParam4); } else if (iParam2 == 2) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_20[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_20[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_20[iParam3], iParam4); } else if (iParam2 == 3) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_24[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_24[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_24[iParam3], iParam4); } else if (iParam2 == 4) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_28[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_28[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_28[iParam3], iParam4); } else if (iParam2 == 5) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_32[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_32[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_32[iParam3], iParam4); } else if (iParam2 == 6) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_36[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_36[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_36[iParam3], iParam4); } else if (iParam2 == 7) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_40[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_40[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_40[iParam3], iParam4); } else if (iParam2 == 8) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_44[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_44[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_44[iParam3], iParam4); } else if (iParam2 == 9) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_48[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_48[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_48[iParam3], iParam4); } } else if (iParam0 == 4) { if (iParam2 == 0) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_52[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_52[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_52[iParam3], iParam4); } else if (iParam2 == 1) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_56[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_56[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_56[iParam3], iParam4); } else if (iParam2 == 2) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_60[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_60[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_60[iParam3], iParam4); } else if (iParam2 == 3) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_64[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_64[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_64[iParam3], iParam4); } } else if (iParam0 == 5) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_68[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_68[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_68[iParam3], iParam4); } else if (iParam0 == 6) { if (iParam2 == 0) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_72[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_72[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_72[iParam3], iParam4); } else if (iParam2 == 1) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_76[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_76[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_76[iParam3], iParam4); } else if (iParam2 == 2) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_80[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_80[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_80[iParam3], iParam4); } else if (iParam2 == 3) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_84[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_84[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_84[iParam3], iParam4); } else if (iParam2 == 4) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_88[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_88[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_88[iParam3], iParam4); } } else if (iParam0 == 7) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_92[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_92[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_92[iParam3], iParam4); } else if (iParam0 == 8) { if (iParam2 == 0) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_96[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_96[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_96[iParam3], iParam4); } else if (iParam2 == 1) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_100[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_100[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_100[iParam3], iParam4); } else if (iParam2 == 2) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_104[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_104[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_104[iParam3], iParam4); } } else if (iParam0 == 9) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_108[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_108[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_108[iParam3], iParam4); } else if (iParam0 == 10) { if (iParam2 == 0) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_112[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_112[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_112[iParam3], iParam4); } else if (iParam2 == 1) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_116[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_116[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_116[iParam3], iParam4); } } else if (iParam0 == 11) { if (iParam2 == 0) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_120[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_120[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_120[iParam3], iParam4); } else if (iParam2 == 1) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_124[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_124[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_124[iParam3], iParam4); } } else if (iParam0 == 12) { if (iParam2 == 0) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_128[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_128[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_128[iParam3], iParam4); } else if (iParam2 == 1) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_132[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_132[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_132[iParam3], iParam4); } } else if (iParam0 == 13) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_136[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_136[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_136[iParam3], iParam4); } else if (iParam0 == 14) { if (iParam2 == 0) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_140[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_140[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_140[iParam3], iParam4); } else if (iParam2 == 1) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_144[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_144[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_144[iParam3], iParam4); } else if (iParam2 == 2) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_148[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_148[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_148[iParam3], iParam4); } else if (iParam2 == 3) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_152[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_152[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_152[iParam3], iParam4); } else if (iParam2 == 4) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_156[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_156[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_156[iParam3], iParam4); } else if (iParam2 == 5) { if (iParam5 == 1) { MISC::SET_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_160[iParam3]), iParam4); } if (iParam6 == 1) { MISC::CLEAR_BIT(&(Global_111858.f_2359[iParam1 /*164*/].f_160[iParam3]), iParam4); } return MISC::IS_BIT_SET(Global_111858.f_2359[iParam1 /*164*/].f_160[iParam3], iParam4); } } return 0; } int func_152(int iParam0) { if (!MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 0)) { return 0; } if (iParam0 == 1) { if (!MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 1)) { return 0; } if (!MISC::IS_BIT_SET(Global_76647[1 /*14*/].f_6, 2)) { return 0; } } return 1; } struct<14> func_153(int iParam0, int iParam1, int iParam2, int iParam3) { func_217(); if (iParam0 == joaat("player_zero")) { func_199(iParam1, iParam2); } else if (iParam0 == joaat("player_one")) { func_180(iParam1, iParam2); } else if (iParam0 == joaat("player_two")) { func_154(iParam1, iParam2); } return Global_76647[0 /*14*/]; } void func_154(int iParam0, int iParam1) { switch (iParam0) { case 0: func_179(iParam1); break; case 2: func_178(iParam1); break; case 3: func_175(iParam1); break; case 4: func_174(iParam1); break; case 6: func_173(iParam1); break; case 5: func_172(iParam1); break; case 8: func_171(iParam1); break; case 9: func_170(iParam1); break; case 10: func_169(iParam1); break; case 1: func_168(iParam1); break; case 7: func_167(iParam1); break; case 11: func_166(iParam1); break; case 12: func_165(iParam1); break; case 13: func_164(iParam1); break; case 14: func_155(iParam1); break; } } void func_155(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 14; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 1; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 2; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 3; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 4; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 5; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 6; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 7; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 8; break; case 154: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; iVar8 = 2; break; case 88: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; iVar8 = 10; break; case 89: StringCopy(&Var2, "PROPS_P2_E1", 16); iVar6 = 1; iVar7 = 0; iVar1 = 45; iVar8 = 10; break; case 90: StringCopy(&Var2, "PROPS_P2_E2", 16); iVar6 = 2; iVar7 = 0; iVar8 = 10; break; case 91: StringCopy(&Var2, "PROPS_P2_E2_1", 16); iVar6 = 2; iVar7 = 1; iVar1 = 50; iVar8 = 10; break; case 92: StringCopy(&Var2, "PROPS_P2_E2_2", 16); iVar6 = 2; iVar7 = 2; iVar1 = 55; iVar8 = 10; break; case 93: StringCopy(&Var2, "PROPS_P2_E2_3", 16); iVar6 = 2; iVar7 = 3; iVar1 = 52; iVar8 = 10; break; case 94: StringCopy(&Var2, "PROPS_P2_E2_4", 16); iVar6 = 2; iVar7 = 4; iVar1 = 54; iVar8 = 10; break; case 95: StringCopy(&Var2, "PROPS_P2_E2_5", 16); iVar6 = 2; iVar7 = 5; iVar1 = 54; iVar8 = 10; break; case 96: StringCopy(&Var2, "PROPS_P2_E2_6", 16); iVar6 = 2; iVar7 = 6; iVar1 = 55; iVar8 = 10; break; case 97: StringCopy(&Var2, "PROPS_P2_E2_7", 16); iVar6 = 2; iVar7 = 7; iVar1 = 55; iVar8 = 10; break; case 98: StringCopy(&Var2, "PROPS_P2_E2_8", 16); iVar6 = 2; iVar7 = 8; iVar1 = 58; iVar8 = 10; break; case 99: StringCopy(&Var2, "PROPS_P2_E2_9", 16); iVar6 = 2; iVar7 = 9; iVar1 = 58; iVar8 = 10; break; case 100: StringCopy(&Var2, "PROPS_P2_E3", 16); iVar6 = 3; iVar7 = 0; iVar1 = 75; iVar8 = 10; break; case 101: StringCopy(&Var2, "PROPS_P2_E3_1", 16); iVar6 = 3; iVar7 = 1; iVar1 = 75; iVar8 = 10; break; case 102: StringCopy(&Var2, "PROPS_P2_E3_2", 16); iVar6 = 3; iVar7 = 2; iVar1 = 75; iVar8 = 10; break; case 103: StringCopy(&Var2, "PROPS_P2_E3_3", 16); iVar6 = 3; iVar7 = 3; iVar1 = 75; iVar8 = 10; break; case 104: StringCopy(&Var2, "PROPS_P2_E3_4", 16); iVar6 = 3; iVar7 = 4; iVar1 = 75; iVar8 = 10; break; case 105: StringCopy(&Var2, "PROPS_P2_E3_5", 16); iVar6 = 3; iVar7 = 5; iVar1 = 75; iVar8 = 10; break; case 106: StringCopy(&Var2, "PROPS_P2_E3_6", 16); iVar6 = 3; iVar7 = 6; iVar1 = 75; iVar8 = 10; break; case 107: StringCopy(&Var2, "PROPS_P2_E3_7", 16); iVar6 = 3; iVar7 = 7; iVar1 = 75; iVar8 = 10; break; case 108: StringCopy(&Var2, "PROPS_P2_E3_8", 16); iVar6 = 3; iVar7 = 8; iVar1 = 75; iVar8 = 10; break; case 109: StringCopy(&Var2, "PROPS_P2_E3_9", 16); iVar6 = 3; iVar7 = 9; iVar1 = 75; iVar8 = 10; break; case 110: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; iVar8 = 10; break; case 111: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; iVar8 = 10; break; case 112: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; iVar8 = 10; break; case 113: StringCopy(&Var2, "PROPS_P2_E7_0", 16); iVar6 = 7; iVar7 = 0; iVar1 = 60; iVar8 = 10; break; case 114: StringCopy(&Var2, "PROPS_P2_E7_1", 16); iVar6 = 7; iVar7 = 1; iVar1 = 50; iVar8 = 10; break; case 115: StringCopy(&Var2, "PROPS_P2_E7_2", 16); iVar6 = 7; iVar7 = 2; iVar1 = 50; iVar8 = 10; break; case 116: StringCopy(&Var2, "PROPS_P2_E7_3", 16); iVar6 = 7; iVar7 = 3; iVar1 = 59; iVar8 = 10; break; case 117: StringCopy(&Var2, "PROPS_P2_E7_4", 16); iVar6 = 7; iVar7 = 4; iVar1 = 55; iVar8 = 10; break; case 118: StringCopy(&Var2, "PROPS_P2_E7_5", 16); iVar6 = 7; iVar7 = 5; iVar1 = 55; iVar8 = 10; break; case 119: StringCopy(&Var2, "PROPS_P2_E7_6", 16); iVar6 = 7; iVar7 = 6; iVar1 = 65; iVar8 = 10; break; case 120: StringCopy(&Var2, "PROPS_P2_E7_7", 16); iVar6 = 7; iVar7 = 7; iVar1 = 59; iVar8 = 10; break; case 121: StringCopy(&Var2, "PROPS_P2_E7_8", 16); iVar6 = 7; iVar7 = 8; iVar1 = 79; iVar8 = 10; break; case 122: StringCopy(&Var2, "PROPS_P2_E7_9", 16); iVar6 = 7; iVar7 = 9; iVar1 = 79; iVar8 = 10; break; case 123: StringCopy(&Var2, "PROPS_P2_E8_0", 16); iVar6 = 8; iVar7 = 0; iVar1 = 150; iVar8 = 10; break; case 124: StringCopy(&Var2, "PROPS_P2_E8_1", 16); iVar6 = 8; iVar7 = 1; iVar1 = 150; iVar8 = 10; break; case 125: StringCopy(&Var2, "PROPS_P2_E8_2", 16); iVar6 = 8; iVar7 = 2; iVar1 = 170; iVar8 = 10; break; case 126: StringCopy(&Var2, "PROPS_P2_E8_3", 16); iVar6 = 8; iVar7 = 3; iVar1 = 175; iVar8 = 10; break; case 127: StringCopy(&Var2, "PROPS_P2_E8_4", 16); iVar6 = 8; iVar7 = 4; iVar1 = 180; iVar8 = 10; break; case 128: StringCopy(&Var2, "PROPS_P2_E8_5", 16); iVar6 = 8; iVar7 = 5; iVar1 = 185; iVar8 = 10; break; case 129: StringCopy(&Var2, "PROPS_P2_E8_6", 16); iVar6 = 8; iVar7 = 6; iVar1 = 189; iVar8 = 10; break; case 130: StringCopy(&Var2, "PROPS_P2_E8_7", 16); iVar6 = 8; iVar7 = 7; iVar1 = 195; iVar8 = 10; break; case 131: StringCopy(&Var2, "PROPS_P2_E8_8", 16); iVar6 = 8; iVar7 = 8; iVar1 = 210; iVar8 = 10; break; case 132: StringCopy(&Var2, "PROPS_P2_E8_9", 16); iVar6 = 8; iVar7 = 9; iVar1 = 215; iVar8 = 10; break; case 133: StringCopy(&Var2, "PROPS_P2_E9_0", 16); iVar6 = 9; iVar7 = 0; iVar1 = 165; iVar8 = 10; break; case 134: StringCopy(&Var2, "PROPS_P2_E9_1", 16); iVar6 = 9; iVar7 = 1; iVar1 = 165; iVar8 = 10; break; case 135: StringCopy(&Var2, "PROPS_P2_E9_2", 16); iVar6 = 9; iVar7 = 2; iVar1 = 169; iVar8 = 10; break; case 136: StringCopy(&Var2, "PROPS_P2_E9_3", 16); iVar6 = 9; iVar7 = 3; iVar1 = 169; iVar8 = 10; break; case 137: StringCopy(&Var2, "PROPS_P2_E9_4", 16); iVar6 = 9; iVar7 = 4; iVar1 = 175; iVar8 = 10; break; case 138: StringCopy(&Var2, "PROPS_P2_E9_5", 16); iVar6 = 9; iVar7 = 5; iVar1 = 175; iVar8 = 10; break; case 139: StringCopy(&Var2, "PROPS_P2_E9_6", 16); iVar6 = 9; iVar7 = 6; iVar1 = 175; iVar8 = 10; break; case 140: StringCopy(&Var2, "PROPS_P2_E9_7", 16); iVar6 = 9; iVar7 = 7; iVar1 = 189; iVar8 = 10; break; case 141: StringCopy(&Var2, "PROPS_P2_E9_8", 16); iVar6 = 9; iVar7 = 8; iVar1 = 195; iVar8 = 10; break; case 142: StringCopy(&Var2, "PROPS_P2_E9_9", 16); iVar6 = 9; iVar7 = 9; iVar1 = 195; iVar8 = 10; break; case 143: StringCopy(&Var2, "PROPS_P2_E10_0", 16); iVar6 = 10; iVar7 = 0; iVar1 = 49; iVar8 = 10; break; case 144: StringCopy(&Var2, "PROPS_P2_E10_1", 16); iVar6 = 10; iVar7 = 1; iVar1 = 50; iVar8 = 10; break; case 145: StringCopy(&Var2, "PROPS_P2_E10_2", 16); iVar6 = 10; iVar7 = 2; iVar1 = 52; iVar8 = 10; break; case 146: StringCopy(&Var2, "PROPS_P2_E10_3", 16); iVar6 = 10; iVar7 = 3; iVar1 = 55; iVar8 = 10; break; case 147: StringCopy(&Var2, "PROPS_P2_E10_4", 16); iVar6 = 10; iVar7 = 4; iVar1 = 60; iVar8 = 10; break; case 148: StringCopy(&Var2, "PROPS_P2_E10_5", 16); iVar6 = 10; iVar7 = 5; iVar1 = 58; iVar8 = 10; break; case 149: StringCopy(&Var2, "PROPS_P2_E10_6", 16); iVar6 = 10; iVar7 = 6; iVar1 = 60; iVar8 = 10; break; case 150: StringCopy(&Var2, "PROPS_P2_E10_7", 16); iVar6 = 10; iVar7 = 7; iVar1 = 63; iVar8 = 10; break; case 151: StringCopy(&Var2, "PROPS_P2_E10_8", 16); iVar6 = 10; iVar7 = 8; iVar1 = 65; iVar8 = 10; break; case 152: StringCopy(&Var2, "PROPS_P2_E10_9", 16); iVar6 = 10; iVar7 = 9; iVar1 = 68; iVar8 = 10; break; case 153: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; iVar1 = 100; iVar8 = 10; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 12: StringCopy(&Var2, "PROPS_P2_H2_0", 16); iVar6 = 2; iVar7 = 0; iVar1 = 320; iVar8 = 0; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 17: StringCopy(&Var2, "PROPS_P2_H7_0", 16); iVar6 = 7; iVar7 = 0; iVar8 = 0; break; case 18: StringCopy(&Var2, "PROPS_P2_H7_1", 16); iVar6 = 7; iVar7 = 1; iVar8 = 0; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; iVar8 = 0; break; case 21: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 1; iVar8 = 0; break; case 22: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 2; iVar8 = 0; break; case 23: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 3; iVar8 = 0; break; case 24: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 4; iVar8 = 0; break; case 25: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 5; iVar8 = 0; break; case 26: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 6; iVar8 = 0; break; case 27: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 7; iVar8 = 0; break; case 28: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 8; iVar8 = 0; break; case 29: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 9; iVar8 = 0; break; case 30: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 10; iVar8 = 0; break; case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 11; iVar8 = 0; break; case 32: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 12; iVar8 = 0; break; case 33: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 13; iVar8 = 0; break; case 34: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 14; iVar8 = 0; break; case 35: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 15; iVar8 = 0; break; case 36: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 37: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; iVar8 = 0; break; case 38: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 1; iVar8 = 0; break; case 39: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 2; iVar8 = 0; break; case 40: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 3; iVar8 = 0; break; case 41: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 4; iVar8 = 0; break; case 42: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 5; iVar8 = 0; break; case 43: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 6; iVar8 = 0; break; case 44: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 7; iVar8 = 0; break; case 45: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; iVar8 = 0; break; case 46: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 13; iVar7 = 0; iVar8 = 0; break; case 47: StringCopy(&Var2, "PROPS_P1_H8_0", 16); iVar6 = 14; iVar7 = 0; iVar1 = 270; iVar8 = 0; break; case 48: StringCopy(&Var2, "PROPS_P1_H8_1", 16); iVar6 = 14; iVar7 = 1; iVar1 = 270; iVar8 = 0; break; case 49: StringCopy(&Var2, "PROPS_P1_H9_0", 16); iVar6 = 15; iVar7 = 0; iVar1 = 200; iVar8 = 0; break; case 50: StringCopy(&Var2, "PROPS_P1_H9_1", 16); iVar6 = 15; iVar7 = 1; iVar1 = 200; iVar8 = 0; break; case 51: StringCopy(&Var2, "PROPS_P1_H10_0", 16); iVar6 = 16; iVar7 = 0; iVar1 = 350; iVar8 = 0; break; case 52: StringCopy(&Var2, "PROPS_P1_H10_1", 16); iVar6 = 16; iVar7 = 1; iVar1 = 350; iVar8 = 0; break; case 53: StringCopy(&Var2, "PROPS_P1_H11_0", 16); iVar6 = 17; iVar7 = 0; iVar1 = 450; iVar8 = 0; break; case 54: StringCopy(&Var2, "PROPS_P1_H12_0", 16); iVar6 = 18; iVar7 = 0; iVar1 = 500; iVar8 = 0; break; case 55: StringCopy(&Var2, "PROPS_P1_H12_1", 16); iVar6 = 18; iVar7 = 1; iVar1 = 500; iVar8 = 0; break; case 56: StringCopy(&Var2, "PROPS_P1_H13_0", 16); iVar6 = 19; iVar7 = 0; iVar1 = 50; iVar8 = 0; break; case 57: StringCopy(&Var2, "PROPS_P1_H13_1", 16); iVar6 = 19; iVar7 = 1; iVar1 = 50; iVar8 = 0; break; case 58: StringCopy(&Var2, "PROPS_P1_H14_0", 16); iVar6 = 20; iVar7 = 0; iVar1 = 99; iVar8 = 0; break; case 59: StringCopy(&Var2, "PROPS_P1_H14_1", 16); iVar6 = 20; iVar7 = 1; iVar1 = 99; iVar8 = 0; break; case 60: StringCopy(&Var2, "PROPS_P1_H14_2", 16); iVar6 = 20; iVar7 = 2; iVar1 = 99; iVar8 = 0; break; case 61: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 21; iVar7 = 0; iVar8 = 0; break; case 62: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 22; iVar7 = 0; iVar8 = 0; break; case 63: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 0; iVar8 = 0; break; case 64: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 1; iVar8 = 0; break; case 65: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 2; iVar8 = 0; break; case 66: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 3; iVar8 = 0; break; case 67: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 4; iVar8 = 0; break; case 68: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 5; iVar8 = 0; break; case 69: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 24; iVar7 = 0; iVar8 = 0; break; case 70: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 25; iVar7 = 0; iVar8 = 0; break; case 71: StringCopy(&Var2, "PROPS_P1_H26_0", 16); iVar6 = 26; iVar7 = 0; iVar1 = 20; iVar8 = 0; break; case 72: StringCopy(&Var2, "PROPS_P1_H26_1", 16); iVar6 = 26; iVar7 = 1; iVar1 = 25; iVar8 = 0; break; case 73: StringCopy(&Var2, "PROPS_P1_H26_2", 16); iVar6 = 26; iVar7 = 2; iVar1 = 25; iVar8 = 0; break; case 74: StringCopy(&Var2, "PROPS_P1_H26_3", 16); iVar6 = 26; iVar7 = 3; iVar1 = 22; iVar8 = 0; break; case 75: StringCopy(&Var2, "PROPS_P1_H26_4", 16); iVar6 = 26; iVar7 = 4; iVar1 = 20; iVar8 = 0; break; case 76: StringCopy(&Var2, "PROPS_P1_H26_5", 16); iVar6 = 26; iVar7 = 5; iVar1 = 25; iVar8 = 0; break; case 77: StringCopy(&Var2, "PROPS_P1_H26_6", 16); iVar6 = 26; iVar7 = 6; iVar1 = 28; iVar8 = 0; break; case 78: StringCopy(&Var2, "PROPS_P1_H26_7", 16); iVar6 = 26; iVar7 = 7; iVar1 = 24; iVar8 = 0; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "PROPS_P1_H26_8", 16); iVar6 = 26; iVar7 = 8; iVar1 = 25; iVar8 = 0; break; case 80: StringCopy(&Var2, "PROPS_P1_H26_9", 16); iVar6 = 26; iVar7 = 9; iVar1 = 22; iVar8 = 0; break; case 81: StringCopy(&Var2, "PROPS_P1_H26_10", 16); iVar6 = 26; iVar7 = 10; iVar1 = 18; iVar8 = 0; break; case 82: StringCopy(&Var2, "PROPS_P1_H26_11", 16); iVar6 = 26; iVar7 = 11; iVar1 = 20; iVar8 = 0; break; case 83: StringCopy(&Var2, "PROPS_P1_H26_12", 16); iVar6 = 26; iVar7 = 12; iVar1 = 24; iVar8 = 0; break; case 84: StringCopy(&Var2, "PROPS_P1_H26_13", 16); iVar6 = 26; iVar7 = 13; iVar1 = 22; iVar8 = 0; break; case 85: StringCopy(&Var2, "PROPS_P1_H26_14", 16); iVar6 = 26; iVar7 = 14; iVar1 = 25; iVar8 = 0; break; case 86: StringCopy(&Var2, "PROPS_P1_H26_15", 16); iVar6 = 26; iVar7 = 15; iVar1 = 25; iVar8 = 0; break; case 87: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 27; iVar7 = 0; iVar8 = 0; break; default: func_163(iVar10, iParam0, 155, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_156(var uParam0, int iParam1, int iParam2, char* sParam3, int iParam4, int iParam5, int iParam6, bool bParam7, int iParam8, int iParam9, bool bParam10) { int iVar0; int iVar1; uParam0->f_6 = 0; *uParam0 = iParam9; uParam0->f_1 = (iParam2 % 32); uParam0->f_2 = (iParam2 / 32); uParam0->f_3 = iParam4; uParam0->f_4 = iParam5; uParam0->f_7 = iParam6; StringCopy(&(uParam0->f_8), sParam3, 16); uParam0->f_13 = iParam8; uParam0->f_12 = func_162(iParam8); if ((uParam0->f_2 >= 10 && uParam0->f_5 >= 0) && uParam0->f_5 < 3) { if (!bParam10) { } uParam0->f_2 = 0; } if (MISC::GET_HASH_KEY(sParam3) != MISC::GET_HASH_KEY("NO_LABEL")) { } if (bParam7) { MISC::SET_BIT(&(uParam0->f_6), 3); } if (bParam10) { MISC::SET_BIT(&(uParam0->f_6), 0); if (uParam0->f_5 >= 0 && uParam0->f_5 < 3) { MISC::SET_BIT(&(uParam0->f_6), 5); } MISC::SET_BIT(&(uParam0->f_6), 1); MISC::SET_BIT(&(uParam0->f_6), 2); MISC::SET_BIT(&(uParam0->f_6), 6); if (func_161(14)) { return; } if (iParam1 == 1) { if (FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(Global_2621444, joaat("REBREATHER"), 0)) { MISC::SET_BIT(&(uParam0->f_6), 7); } } if (iParam1 == 12) { if (!func_160(Global_2621444, 1, 1, 1, -1)) { MISC::CLEAR_BIT(&(uParam0->f_6), 2); } if (!func_160(Global_2621444, 2, 1, 1, -1)) { MISC::SET_BIT(&(uParam0->f_6), 4); } } else if (iParam1 == 13) { } else if (iParam1 == 14) { if (!func_160(Global_2621444, 1, 1, 1, -1)) { MISC::CLEAR_BIT(&(uParam0->f_6), 2); } if (!func_160(Global_2621444, 2, 1, 1, -1)) { MISC::SET_BIT(&(uParam0->f_6), 4); } } else { if (!func_160(Global_2621444, 1, 1, 1, -1)) { MISC::CLEAR_BIT(&(uParam0->f_6), 2); } if (!func_160(Global_2621444, 2, 1, 1, -1)) { MISC::SET_BIT(&(uParam0->f_6), 4); } } } else if (uParam0->f_5 >= 0 && uParam0->f_5 < 3) { MISC::SET_BIT(&(uParam0->f_6), 0); MISC::SET_BIT(&(uParam0->f_6), 5); if (func_151(iParam1, uParam0->f_5, uParam0->f_2, 0, uParam0->f_1, 0, 0)) { MISC::SET_BIT(&(uParam0->f_6), 1); } if (func_151(iParam1, uParam0->f_5, uParam0->f_2, 1, uParam0->f_1, 0, 0)) { MISC::SET_BIT(&(uParam0->f_6), 2); } if (!func_151(iParam1, uParam0->f_5, uParam0->f_2, 2, uParam0->f_1, 0, 0)) { MISC::SET_BIT(&(uParam0->f_6), 4); } } else { MISC::SET_BIT(&(uParam0->f_6), 0); if ((((((((((iParam1 == 11 || iParam1 == 4) || iParam1 == 6) || iParam1 == 1) || iParam1 == 14) || iParam1 == 2) || iParam1 == 8) || iParam1 == 9) || iParam1 == 10) || iParam1 == 7) || iParam1 == 12) { if (func_161(14)) { return; } iVar0 = func_149(func_159(iParam1, uParam0->f_2), Global_76644, 0); if (MISC::IS_BIT_SET(iVar0, uParam0->f_1)) { MISC::SET_BIT(&(uParam0->f_6), 1); } iVar0 = func_149(func_158(iParam1, uParam0->f_2), Global_76644, 0); if (MISC::IS_BIT_SET(iVar0, uParam0->f_1)) { MISC::SET_BIT(&(uParam0->f_6), 2); } if (func_157(iParam1, uParam0->f_2, &iVar1)) { iVar0 = func_149(iVar1, Global_76644, 0); if (!MISC::IS_BIT_SET(iVar0, uParam0->f_1)) { MISC::SET_BIT(&(uParam0->f_6), 4); } } } else { MISC::SET_BIT(&(uParam0->f_6), 1); MISC::SET_BIT(&(uParam0->f_6), 2); } } if (iParam1 == 14) { if (iParam4 == -1) { MISC::SET_BIT(&(uParam0->f_6), 1); MISC::SET_BIT(&(uParam0->f_6), 2); } } } bool func_157(int iParam0, int iParam1, var uParam2) { *uParam2 = 978; switch (iParam1) { case 0: switch (iParam0) { case 2: *uParam2 = 979; break; case 3: *uParam2 = 1429; break; case 4: *uParam2 = 995; break; case 6: *uParam2 = 1003; break; case 8: *uParam2 = 1430; break; case 9: *uParam2 = 1438; break; case 10: *uParam2 = 1440; break; case 1: *uParam2 = 1011; break; case 7: *uParam2 = 1441; break; case 11: *uParam2 = 987; break; case 14: *uParam2 = 1019; break; case 12: *uParam2 = 1030; break; } break; case 1: switch (iParam0) { case 2: *uParam2 = 980; break; case 4: *uParam2 = 996; break; case 6: *uParam2 = 1004; break; case 8: *uParam2 = 1431; break; case 9: *uParam2 = 1439; break; case 7: *uParam2 = 1442; break; case 11: *uParam2 = 988; break; case 14: *uParam2 = 1020; break; } break; case 2: switch (iParam0) { case 2: *uParam2 = 981; break; case 4: *uParam2 = 997; break; case 6: *uParam2 = 1005; break; case 8: *uParam2 = 1432; break; case 7: *uParam2 = 1443; break; case 11: *uParam2 = 989; break; case 14: *uParam2 = 1021; break; } break; case 3: switch (iParam0) { case 4: *uParam2 = 998; break; case 6: *uParam2 = 1006; break; case 8: *uParam2 = 1433; break; case 11: *uParam2 = 990; break; case 14: *uParam2 = 1022; break; } break; case 4: switch (iParam0) { case 4: *uParam2 = 999; break; case 6: *uParam2 = 1007; break; case 8: *uParam2 = 1434; break; case 11: *uParam2 = 991; break; case 14: *uParam2 = 1023; break; } break; case 5: switch (iParam0) { case 4: *uParam2 = 1000; break; case 6: *uParam2 = 1008; break; case 8: *uParam2 = 1435; break; case 11: *uParam2 = 992; break; case 14: *uParam2 = 1024; break; } break; case 6: switch (iParam0) { case 4: *uParam2 = 1001; break; case 6: *uParam2 = 1009; break; case 8: *uParam2 = 1436; break; case 11: *uParam2 = 993; break; case 14: *uParam2 = 1025; break; } break; case 7: switch (iParam0) { case 4: *uParam2 = 1002; break; case 6: *uParam2 = 1010; break; case 8: *uParam2 = 1437; break; case 11: *uParam2 = 994; break; case 14: *uParam2 = 1026; break; } break; case 8: switch (iParam0) { case 14: *uParam2 = 1027; break; } break; case 9: switch (iParam0) { case 14: *uParam2 = 1028; break; } break; case 10: switch (iParam0) { case 14: *uParam2 = 1029; break; } break; } return *uParam2 != 978; } int func_158(int iParam0, int iParam1) { switch (iParam1) { case 0: switch (iParam0) { case 2: return 927; break; case 3: return 1414; break; case 4: return 943; break; case 6: return 951; break; case 8: return 1415; break; case 9: return 1423; break; case 10: return 1425; break; case 1: return 959; break; case 7: return 1426; break; case 11: return 935; break; case 14: return 967; break; case 12: return 978; break; } break; case 1: switch (iParam0) { case 2: return 928; break; case 4: return 944; break; case 6: return 952; break; case 8: return 1416; break; case 9: return 1424; break; case 7: return 1427; break; case 11: return 936; break; case 14: return 968; break; } break; case 2: switch (iParam0) { case 2: return 929; break; case 4: return 945; break; case 6: return 953; break; case 8: return 1417; break; case 7: return 1428; break; case 11: return 937; break; case 14: return 969; break; } break; case 3: switch (iParam0) { case 4: return 946; break; case 6: return 954; break; case 8: return 1418; break; case 11: return 938; break; case 14: return 970; break; } break; case 4: switch (iParam0) { case 4: return 947; break; case 6: return 955; break; case 8: return 1419; break; case 11: return 939; break; case 14: return 971; break; } break; case 5: switch (iParam0) { case 4: return 948; break; case 6: return 956; break; case 8: return 1420; break; case 11: return 940; break; case 14: return 972; break; } break; case 6: switch (iParam0) { case 4: return 949; break; case 6: return 957; break; case 8: return 1421; break; case 11: return 941; break; case 14: return 973; break; } break; case 7: switch (iParam0) { case 4: return 950; break; case 6: return 958; break; case 8: return 1422; break; case 11: return 942; break; case 14: return 974; break; } break; case 8: switch (iParam0) { case 14: return 975; break; } break; case 9: switch (iParam0) { case 14: return 976; break; } break; case 10: switch (iParam0) { case 14: return 977; break; } break; } return 935; } int func_159(int iParam0, int iParam1) { switch (iParam1) { case 0: switch (iParam0) { case 2: return 875; break; case 3: return 1399; break; case 4: return 891; break; case 6: return 899; break; case 8: return 1400; break; case 9: return 1408; break; case 10: return 1410; break; case 1: return 907; break; case 7: return 1411; break; case 11: return 883; break; case 14: return 915; break; case 12: return 926; break; } break; case 1: switch (iParam0) { case 2: return 876; break; case 4: return 892; break; case 6: return 900; break; case 8: return 1401; break; case 9: return 1409; break; case 7: return 1412; break; case 11: return 884; break; case 14: return 916; break; } break; case 2: switch (iParam0) { case 2: return 877; break; case 4: return 893; break; case 6: return 901; break; case 8: return 1402; break; case 7: return 1413; break; case 11: return 885; break; case 14: return 917; break; } break; case 3: switch (iParam0) { case 4: return 894; break; case 6: return 902; break; case 8: return 1403; break; case 11: return 886; break; case 14: return 918; break; } break; case 4: switch (iParam0) { case 4: return 895; break; case 6: return 903; break; case 8: return 1404; break; case 11: return 887; break; case 14: return 919; break; } break; case 5: switch (iParam0) { case 4: return 896; break; case 6: return 904; break; case 8: return 1405; break; case 11: return 888; break; case 14: return 920; break; } break; case 6: switch (iParam0) { case 4: return 897; break; case 6: return 905; break; case 8: return 1406; break; case 11: return 889; break; case 14: return 921; break; } break; case 7: switch (iParam0) { case 4: return 898; break; case 6: return 906; break; case 8: return 1407; break; case 11: return 890; break; case 14: return 922; break; } break; case 8: switch (iParam0) { case 14: return 923; break; } break; case 9: switch (iParam0) { case 14: return 924; break; } break; case 10: switch (iParam0) { case 14: return 925; break; } break; } return 883; } int func_160(int iParam0, int iParam1, bool bParam2, bool bParam3, int iParam4) { int iVar0; int iVar1; int iVar2; int iVar3; iVar0 = Global_76644; if (iParam4 != -1) { iVar0 = iParam4; } if (func_150(iParam0, iParam1, &iVar2, &iVar1, bParam2, bParam3)) { iVar3 = func_149(iVar2, iVar0, 0); return MISC::IS_BIT_SET(iVar3, iVar1); } return 0; } bool func_161(int iParam0) { return Global_41631 == iParam0; } int func_162(int iParam0) { switch (iParam0) { case -1: return 0; break; case 0: return 0; break; case 1: return 1; break; case 2: return 2; break; case 3: return 3; break; case 4: return 4; break; case 5: return 5; break; case 6: return 6; break; case 7: return 7; break; case 8: return 8; break; case 9: return 0; break; case 10: return 1; break; case 11: return 0; break; case 12: return 0; break; case 13: return 0; break; } return 0; } void func_163(int iParam0, int iParam1, int iParam2, int iParam3) { int iVar0; int iVar1; struct<8> Var2; int iVar17; int iVar18; struct<10> Var19; int iVar36; int iVar37; int iVar38; struct<10> Var39; int iVar56; int iVar57; iVar0 = (iParam1 - iParam2); iVar0 = iVar0; if (iVar0 < 0) { return; } iVar1 = Global_76647[0 /*14*/].f_5; if (iParam0 == 12) { iVar17 = (iParam1 - iParam2); if (iVar17 >= 0) { iVar18 = FILES::_0xF3FBE2D50A6A8C28(iVar1, false); if (iVar18 > iVar17) { FILES::GET_SHOP_PED_QUERY_OUTFIT(iVar17, &Var2); Global_2621444 = Var2.f_1; Global_2621445 = Var2; func_156(&(Global_76647[0 /*14*/]), iParam0, iParam1, &(Var2.f_7), 0, 0, Var2.f_2, 0, -1, 2, 1); return; } } } else if (iParam0 == 13) { func_156(&(Global_76647[0 /*14*/]), iParam0, iParam1, "NO_LABEL", 0, 0, 0, 1, -1, 2, 1); } else if (iParam0 == 14) { FILES::INIT_SHOP_PED_PROP(&Var19); iVar37 = (iParam1 - iParam2); if (iVar37 >= 0) { iVar38 = FILES::_GET_NUM_PROPS_FROM_OUTFIT(iVar1, 7, -1, true, -1, -1); if (iVar38 > iVar37) { FILES::GET_SHOP_PED_QUERY_PROP(iVar37, &Var19); if (Var19.f_6 == 0) { iVar36 = 9; } else if (Var19.f_6 == 1) { iVar36 = 10; } else if (Var19.f_6 == 2) { iVar36 = 2; } else if (Var19.f_6 == 3) { iVar36 = 3; } else if (Var19.f_6 == 4) { iVar36 = 4; } else if (Var19.f_6 == 5) { iVar36 = 5; } else if (Var19.f_6 == 6) { iVar36 = 6; } else if (Var19.f_6 == 7) { iVar36 = 7; } else if (Var19.f_6 == 8) { iVar36 = 8; } else { iVar36 = -1; } Global_2621444 = Var19.f_1; Global_2621445 = Var19; func_156(&(Global_76647[0 /*14*/]), iParam0, iParam1, &(Var19.f_9), Var19.f_3, Var19.f_4, Var19.f_5, FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(Var19.f_1, joaat("OUTFIT_ONLY"), 0), iVar36, 2, Var19.f_1 != 0); return; } } } else { FILES::INIT_SHOP_PED_COMPONENT(&Var39); if (iParam3 != -1 && Global_76814) { FILES::GET_SHOP_PED_COMPONENT(iParam3, &Var39); Global_2621444 = Var39.f_1; Global_2621445 = Var39; func_156(&(Global_76647[0 /*14*/]), iParam0, iParam1, &(Var39.f_9), Var39.f_3, Var39.f_4, Var39.f_5, FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(Var39.f_1, joaat("OUTFIT_ONLY"), 0), -1, 2, Var39.f_1 != 0); return; } iVar56 = (iParam1 - iParam2); if (iVar56 >= 0) { iVar57 = FILES::_GET_NUM_PROPS_FROM_OUTFIT(iVar1, 7, -1, false, -1, func_112(iParam0)); if (iVar57 > iVar56) { FILES::GET_SHOP_PED_QUERY_COMPONENT(iVar56, &Var39); Global_2621444 = Var39.f_1; Global_2621445 = Var39; func_156(&(Global_76647[0 /*14*/]), iParam0, iParam1, &(Var39.f_9), Var39.f_3, Var39.f_4, Var39.f_5, FILES::DOES_SHOP_PED_APPAREL_HAVE_RESTRICTION_TAG(Var39.f_1, joaat("OUTFIT_ONLY"), 0), -1, 2, Var39.f_1 != 0); return; } } } } void func_164(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 13; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; default: func_163(iVar10, iParam0, 9, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_165(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 12; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "OUTFIT_P2_0", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 2: StringCopy(&Var2, "OUTFIT_P2_5", 16); iVar6 = 0; iVar7 = 0; break; case 3: StringCopy(&Var2, "OUTFIT_P2_6", 16); iVar6 = 0; iVar7 = 0; break; case 4: StringCopy(&Var2, "OUTFIT_P2_7", 16); iVar6 = 0; iVar7 = 0; break; case 5: StringCopy(&Var2, "OUTFIT_P2_8", 16); iVar6 = 0; iVar7 = 0; break; case 6: StringCopy(&Var2, "OUTFIT_P2_9", 16); iVar6 = 0; iVar7 = 0; break; case 7: StringCopy(&Var2, "OUTFIT_P2_10", 16); iVar6 = 0; iVar7 = 0; break; case 8: StringCopy(&Var2, "OUTFIT_P2_12", 16); iVar6 = 0; iVar7 = 0; break; case 9: StringCopy(&Var2, "OUTFIT_P2_13", 16); iVar6 = 0; iVar7 = 0; break; case 10: StringCopy(&Var2, "OUTFIT_P2_14", 16); iVar6 = 0; iVar7 = 0; break; case 11: StringCopy(&Var2, "OUTFIT_P2_15", 16); iVar6 = 0; iVar7 = 0; break; case 12: StringCopy(&Var2, "OUTFIT_P2_16", 16); iVar6 = 0; iVar7 = 0; break; case 13: StringCopy(&Var2, "OUTFIT_P2_17", 16); iVar6 = 0; iVar7 = 0; break; case 14: StringCopy(&Var2, "OUTFIT_P2_18", 16); iVar6 = 0; iVar7 = 0; iVar1 = 10000; break; case 15: StringCopy(&Var2, "OUTFIT_P2_19", 16); iVar6 = 0; iVar7 = 0; break; case 16: StringCopy(&Var2, "OUTFIT_P2_20", 16); iVar6 = 0; iVar7 = 0; break; case 17: StringCopy(&Var2, "OUTFIT_P2_21", 16); iVar6 = 0; iVar7 = 0; iVar1 = 105; break; case 18: StringCopy(&Var2, "OUTFIT_P2_22", 16); iVar6 = 0; iVar7 = 0; iVar1 = 105; break; case 19: StringCopy(&Var2, "OUTFIT_P2_23", 16); iVar6 = 0; iVar7 = 0; iVar1 = 105; break; case 20: StringCopy(&Var2, "OUTFIT_P2_24", 16); iVar6 = 0; iVar7 = 0; break; case 21: StringCopy(&Var2, "OUTFIT_P2_25", 16); iVar6 = 0; iVar7 = 0; break; case 22: StringCopy(&Var2, "OUTFIT_P2_26", 16); iVar6 = 0; iVar7 = 0; break; case 23: StringCopy(&Var2, "OUTFIT_P2_27", 16); iVar6 = 0; iVar7 = 0; break; case 24: StringCopy(&Var2, "OUTFIT_P2_28", 16); iVar6 = 0; iVar7 = 0; iVar1 = 119; break; case 25: StringCopy(&Var2, "OUTFIT_P2_29", 16); iVar6 = 0; iVar7 = 0; iVar1 = 99; break; case 26: StringCopy(&Var2, "OUTFIT_P2_30", 16); iVar6 = 0; iVar7 = 0; iVar1 = 129; break; case 27: StringCopy(&Var2, "OUTFIT_P2_44", 16); iVar6 = 0; iVar7 = 0; iVar1 = 125; break; case 28: StringCopy(&Var2, "OUTFIT_P2_45", 16); iVar6 = 0; iVar7 = 0; iVar1 = 120; break; case 29: StringCopy(&Var2, "OUTFIT_P2_46", 16); iVar6 = 0; iVar7 = 0; iVar1 = 139; break; case 30: StringCopy(&Var2, "OUTFIT_P2_47", 16); iVar6 = 0; iVar7 = 0; iVar1 = 149; break; case 31: StringCopy(&Var2, "OUTFIT_P2_48", 16); iVar6 = 0; iVar7 = 0; iVar1 = 145; break; case 32: StringCopy(&Var2, "OUTFIT_P2_49", 16); iVar6 = 0; iVar7 = 0; iVar1 = 140; break; case 33: StringCopy(&Var2, "OUTFIT_P2_50", 16); iVar6 = 0; iVar7 = 0; iVar1 = 135; break; case 34: StringCopy(&Var2, "OUTFIT_P2_31", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4900; break; case 35: StringCopy(&Var2, "OUTFIT_P2_32", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5900; break; case 36: StringCopy(&Var2, "OUTFIT_P2_33", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4500; break; case 37: StringCopy(&Var2, "OUTFIT_P2_34", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4900; break; case 38: StringCopy(&Var2, "OUTFIT_P2_35", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4500; break; case 39: StringCopy(&Var2, "OUTFIT_P2_36", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5900; break; case 40: StringCopy(&Var2, "OUTFIT_P2_37", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5500; break; case 41: StringCopy(&Var2, "OUTFIT_P2_38", 16); iVar6 = 0; iVar7 = 0; break; case 42: StringCopy(&Var2, "OUTFIT_P2_39", 16); iVar6 = 0; iVar7 = 0; break; case 43: StringCopy(&Var2, "OUTFIT_P2_40", 16); iVar6 = 0; iVar7 = 0; break; case 44: StringCopy(&Var2, "OUTFIT_P2_41", 16); iVar6 = 0; iVar7 = 0; break; case 45: StringCopy(&Var2, "OUTFIT_P2_42", 16); iVar6 = 0; iVar7 = 0; break; case 46: StringCopy(&Var2, "OUTFIT_P2_43", 16); iVar6 = 0; iVar7 = 0; break; case 47: StringCopy(&Var2, "OUTFIT_P2_12", 16); iVar6 = 0; iVar7 = 0; break; default: func_163(iVar10, iParam0, 48, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_166(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 11; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; default: func_163(iVar10, iParam0, 1, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_167(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 7; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; default: func_163(iVar10, iParam0, 1, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_168(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 1; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "BERD_P2_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "BERD_P2_1_0", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "BERD_P2_2_0", 16); iVar6 = 2; iVar7 = 0; break; case 3: StringCopy(&Var2, "BERD_P2_3_0", 16); iVar6 = 3; iVar7 = 0; break; case 4: StringCopy(&Var2, "BERD_P2_4_0", 16); iVar6 = 4; iVar7 = 0; break; case 5: StringCopy(&Var2, "BERD_P2_5_0", 16); iVar6 = 5; iVar7 = 0; break; default: func_163(iVar10, iParam0, 6, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_169(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 10; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 1; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 2; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 3; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 4; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 5; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; break; case 12: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 1; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 2; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 3; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 4; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 5; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 6; break; case 18: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 7; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 8; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 9; break; case 21: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; break; case 22: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; break; case 23: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 1; break; case 24: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 2; break; case 25: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 3; break; case 26: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 4; break; case 27: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 5; break; case 28: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 6; break; case 29: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; break; case 30: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 1; break; case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 2; break; case 32: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 3; break; default: func_163(iVar10, iParam0, 33, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_170(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 9; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 1; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 2; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 3; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 9: StringCopy(&Var2, "SPEC2_P0_08_0", 16); iVar6 = 6; iVar7 = 0; iVar1 = 125; break; case 10: StringCopy(&Var2, "SPEC2_P0_08_1", 16); iVar6 = 6; iVar7 = 1; iVar1 = 150; break; case 11: StringCopy(&Var2, "SPEC2_P0_08_2", 16); iVar6 = 6; iVar7 = 2; iVar1 = 175; break; case 12: StringCopy(&Var2, "SPEC2_P0_08_3", 16); iVar6 = 6; iVar7 = 3; iVar1 = 85; break; case 13: StringCopy(&Var2, "SPEC2_P0_08_4", 16); iVar6 = 6; iVar7 = 4; iVar1 = 150; break; case 14: StringCopy(&Var2, "SPEC2_P0_08_5", 16); iVar6 = 6; iVar7 = 5; iVar1 = 175; break; case 15: StringCopy(&Var2, "PROPS_P1_H8_0", 16); iVar6 = 7; iVar7 = 0; iVar1 = 270; break; case 16: StringCopy(&Var2, "PROPS_P1_H8_1", 16); iVar6 = 7; iVar7 = 1; iVar1 = 270; break; default: func_163(iVar10, iParam0, 17, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_171(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 8; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "SPEC_P2_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "SPEC_P2_0_1", 16); iVar6 = 0; iVar7 = 1; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 12: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; bVar0 = true; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 13; iVar7 = 0; bVar0 = true; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 14; iVar7 = 0; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 15; iVar7 = 0; bVar0 = true; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 16; iVar7 = 0; bVar0 = true; break; default: func_163(iVar10, iParam0, 18, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_172(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 5; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 1; bVar0 = true; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; default: func_163(iVar10, iParam0, 7, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_173(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 6; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "FEET_P2_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "FEET_P2_0_1", 16); iVar6 = 0; iVar7 = 1; iVar1 = 22; break; case 2: StringCopy(&Var2, "FEET_P2_0_2", 16); iVar6 = 0; iVar7 = 2; iVar1 = 45; break; case 3: StringCopy(&Var2, "FEET_P2_0_3", 16); iVar6 = 0; iVar7 = 3; iVar1 = 65; break; case 4: StringCopy(&Var2, "FEET_P2_0_4", 16); iVar6 = 0; iVar7 = 4; iVar1 = 58; break; case 5: StringCopy(&Var2, "FEET_P2_0_5", 16); iVar6 = 0; iVar7 = 5; iVar1 = 72; break; case 6: StringCopy(&Var2, "FEET_P2_0_6", 16); iVar6 = 0; iVar7 = 6; iVar1 = 68; break; case 7: StringCopy(&Var2, "FEET_P2_0_7", 16); iVar6 = 0; iVar7 = 7; iVar1 = 60; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 12: StringCopy(&Var2, "FEET_P2_5_0", 16); iVar6 = 5; iVar7 = 0; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 15: StringCopy(&Var2, "FEET_P2_8_0", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; break; case 16: StringCopy(&Var2, "FEET_P2_9_0", 16); iVar6 = 9; iVar7 = 0; break; case 17: StringCopy(&Var2, "FEET_P2_9_1", 16); iVar6 = 9; iVar7 = 1; iVar1 = 680; break; case 18: StringCopy(&Var2, "FEET_P2_9_2", 16); iVar6 = 9; iVar7 = 2; iVar1 = 650; break; case 19: StringCopy(&Var2, "FEET_P2_9_3", 16); iVar6 = 9; iVar7 = 3; iVar1 = 670; break; case 20: StringCopy(&Var2, "FEET_P2_9_4", 16); iVar6 = 9; iVar7 = 4; iVar1 = 700; break; case 21: StringCopy(&Var2, "FEET_P2_9_5", 16); iVar6 = 9; iVar7 = 5; iVar1 = 680; break; case 22: StringCopy(&Var2, "FEET_P2_9_6", 16); iVar6 = 9; iVar7 = 6; iVar1 = 720; break; case 23: StringCopy(&Var2, "FEET_P2_9_7", 16); iVar6 = 9; iVar7 = 7; iVar1 = 740; break; case 24: StringCopy(&Var2, "FEET_P2_9_8", 16); iVar6 = 9; iVar7 = 8; iVar1 = 760; break; case 25: StringCopy(&Var2, "FEET_P2_9_9", 16); iVar6 = 9; iVar7 = 9; iVar1 = 780; break; case 26: StringCopy(&Var2, "FEET_P2_9_10", 16); iVar6 = 9; iVar7 = 10; iVar1 = 750; break; case 27: StringCopy(&Var2, "FEET_P2_9_11", 16); iVar6 = 9; iVar7 = 11; iVar1 = 700; break; case 28: StringCopy(&Var2, "FEET_P2_10_0", 16); iVar6 = 10; iVar7 = 0; break; case 29: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; bVar0 = true; break; case 30: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; bVar0 = true; break; case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 13; iVar7 = 0; bVar0 = true; break; case 32: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 14; iVar7 = 0; bVar0 = true; break; case 33: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 15; iVar7 = 0; bVar0 = true; break; case 34: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 16; iVar7 = 0; break; case 35: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 0; break; case 36: StringCopy(&Var2, "FEET_P2_18_0", 16); iVar6 = 18; iVar7 = 0; iVar1 = 790; break; case 37: StringCopy(&Var2, "FEET_P2_18_1", 16); iVar6 = 18; iVar7 = 1; iVar1 = 750; break; case 38: StringCopy(&Var2, "FEET_P2_18_2", 16); iVar6 = 18; iVar7 = 2; iVar1 = 860; break; case 39: StringCopy(&Var2, "FEET_P2_18_3", 16); iVar6 = 18; iVar7 = 3; iVar1 = 750; break; case 40: StringCopy(&Var2, "FEET_P2_18_4", 16); iVar6 = 18; iVar7 = 4; iVar1 = 790; break; case 41: StringCopy(&Var2, "FEET_P2_18_5", 16); iVar6 = 18; iVar7 = 5; iVar1 = 840; break; case 42: StringCopy(&Var2, "FEET_P2_18_6", 16); iVar6 = 18; iVar7 = 6; iVar1 = 820; break; case 43: StringCopy(&Var2, "FEET_P2_18_7", 16); iVar6 = 18; iVar7 = 7; iVar1 = 800; break; case 44: StringCopy(&Var2, "FEET_P2_18_8", 16); iVar6 = 18; iVar7 = 8; iVar1 = 850; break; case 45: StringCopy(&Var2, "FEET_P2_18_9", 16); iVar6 = 18; iVar7 = 9; iVar1 = 870; break; case 46: StringCopy(&Var2, "FEET_P2_18_10", 16); iVar6 = 18; iVar7 = 10; iVar1 = 720; break; case 47: StringCopy(&Var2, "FEET_P2_18_11", 16); iVar6 = 18; iVar7 = 11; iVar1 = 740; break; case 48: StringCopy(&Var2, "FEET_P2_18_12", 16); iVar6 = 18; iVar7 = 12; iVar1 = 800; break; case 49: StringCopy(&Var2, "FEET_P2_18_13", 16); iVar6 = 18; iVar7 = 13; iVar1 = 750; break; case 50: StringCopy(&Var2, "FEET_P2_18_14", 16); iVar6 = 18; iVar7 = 14; iVar1 = 770; break; case 51: StringCopy(&Var2, "FEET_P2_18_15", 16); iVar6 = 18; iVar7 = 15; iVar1 = 860; break; case 52: StringCopy(&Var2, "FEET_P2_19_0", 16); iVar6 = 19; iVar7 = 0; iVar1 = 850; break; case 53: StringCopy(&Var2, "FEET_P2_19_1", 16); iVar6 = 19; iVar7 = 1; iVar1 = 800; break; case 54: StringCopy(&Var2, "FEET_P2_19_2", 16); iVar6 = 19; iVar7 = 2; iVar1 = 780; break; case 55: StringCopy(&Var2, "FEET_P2_19_3", 16); iVar6 = 19; iVar7 = 3; iVar1 = 890; break; case 56: StringCopy(&Var2, "FEET_P2_19_4", 16); iVar6 = 19; iVar7 = 4; iVar1 = 820; break; case 57: StringCopy(&Var2, "FEET_P2_19_5", 16); iVar6 = 19; iVar7 = 5; iVar1 = 840; break; case 58: StringCopy(&Var2, "FEET_P2_19_6", 16); iVar6 = 19; iVar7 = 6; iVar1 = 870; break; case 59: StringCopy(&Var2, "FEET_P2_19_7", 16); iVar6 = 19; iVar7 = 7; iVar1 = 930; break; case 60: StringCopy(&Var2, "FEET_P2_19_8", 16); iVar6 = 19; iVar7 = 8; iVar1 = 880; break; case 61: StringCopy(&Var2, "FEET_P2_19_9", 16); iVar6 = 19; iVar7 = 9; iVar1 = 900; break; case 62: StringCopy(&Var2, "FEET_P2_19_10", 16); iVar6 = 19; iVar7 = 10; iVar1 = 920; break; case 63: StringCopy(&Var2, "FEET_P2_19_11", 16); iVar6 = 19; iVar7 = 11; iVar1 = 970; break; case 64: StringCopy(&Var2, "FEET_P2_19_12", 16); iVar6 = 19; iVar7 = 12; iVar1 = 990; break; case 65: StringCopy(&Var2, "FEET_P2_19_13", 16); iVar6 = 19; iVar7 = 13; iVar1 = 960; break; case 66: StringCopy(&Var2, "FEET_P2_19_14", 16); iVar6 = 19; iVar7 = 14; iVar1 = 980; break; case 67: StringCopy(&Var2, "FEET_P2_19_15", 16); iVar6 = 19; iVar7 = 15; iVar1 = 950; break; case 68: StringCopy(&Var2, "FEET_P2_20_0", 16); iVar6 = 20; iVar7 = 0; iVar1 = 110; break; case 69: StringCopy(&Var2, "FEET_P2_20_1", 16); iVar6 = 20; iVar7 = 1; iVar1 = 115; break; case 70: StringCopy(&Var2, "FEET_P2_20_2", 16); iVar6 = 20; iVar7 = 2; iVar1 = 120; break; case 71: StringCopy(&Var2, "FEET_P2_20_3", 16); iVar6 = 20; iVar7 = 3; iVar1 = 110; break; case 72: StringCopy(&Var2, "FEET_P2_20_4", 16); iVar6 = 20; iVar7 = 4; iVar1 = 125; break; case 73: StringCopy(&Var2, "FEET_P2_20_5", 16); iVar6 = 20; iVar7 = 5; iVar1 = 128; break; case 74: StringCopy(&Var2, "FEET_P2_20_6", 16); iVar6 = 20; iVar7 = 6; iVar1 = 135; break; case 75: StringCopy(&Var2, "FEET_P2_20_7", 16); iVar6 = 20; iVar7 = 7; iVar1 = 130; break; case 76: StringCopy(&Var2, "FEET_P2_20_8", 16); iVar6 = 20; iVar7 = 8; iVar1 = 145; break; case 77: StringCopy(&Var2, "FEET_P2_20_9", 16); iVar6 = 20; iVar7 = 9; iVar1 = 110; break; case 78: StringCopy(&Var2, "FEET_P2_20_10", 16); iVar6 = 20; iVar7 = 10; iVar1 = 120; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "FEET_P2_20_11", 16); iVar6 = 20; iVar7 = 11; iVar1 = 150; break; case 80: StringCopy(&Var2, "FEET_P2_20_12", 16); iVar6 = 20; iVar7 = 12; iVar1 = 125; break; case 81: StringCopy(&Var2, "FEET_P2_20_13", 16); iVar6 = 20; iVar7 = 13; iVar1 = 120; break; case 82: StringCopy(&Var2, "FEET_P2_20_14", 16); iVar6 = 20; iVar7 = 14; iVar1 = 130; break; case 83: StringCopy(&Var2, "FEET_P2_20_15", 16); iVar6 = 20; iVar7 = 15; iVar1 = 110; break; default: func_163(iVar10, iParam0, 84, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_174(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 4; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "LEGS_P2_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "LEGS_P2_0_1", 16); iVar6 = 0; iVar7 = 1; iVar1 = 95; break; case 2: StringCopy(&Var2, "LEGS_P2_0_2", 16); iVar6 = 0; iVar7 = 2; iVar1 = 129; break; case 3: StringCopy(&Var2, "LEGS_P2_0_3", 16); iVar6 = 0; iVar7 = 3; iVar1 = 115; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 1; bVar0 = true; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 2; bVar0 = true; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 3; bVar0 = true; break; case 12: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 4; bVar0 = true; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 18: StringCopy(&Var2, "LEGS_P2_11_0", 16); iVar6 = 11; iVar7 = 0; break; case 19: StringCopy(&Var2, "LEGS_P2_11_1", 16); iVar6 = 11; iVar7 = 1; iVar1 = 750; break; case 20: StringCopy(&Var2, "LEGS_P2_11_2", 16); iVar6 = 11; iVar7 = 2; iVar1 = 650; break; case 21: StringCopy(&Var2, "LEGS_P2_11_3", 16); iVar6 = 11; iVar7 = 3; iVar1 = 850; break; case 22: StringCopy(&Var2, "LEGS_P2_11_4", 16); iVar6 = 11; iVar7 = 4; iVar1 = 850; break; case 23: StringCopy(&Var2, "LEGS_P2_11_5", 16); iVar6 = 11; iVar7 = 5; iVar1 = 750; break; case 24: StringCopy(&Var2, "LEGS_P2_11_6", 16); iVar6 = 11; iVar7 = 6; iVar1 = 690; break; case 25: StringCopy(&Var2, "LEGS_P2_11_7", 16); iVar6 = 11; iVar7 = 7; iVar1 = 820; break; case 26: StringCopy(&Var2, "LEGS_P2_11_8", 16); iVar6 = 11; iVar7 = 8; iVar1 = 650; break; case 27: StringCopy(&Var2, "LEGS_P2_11_9", 16); iVar6 = 11; iVar7 = 9; iVar1 = 690; break; case 28: StringCopy(&Var2, "LEGS_P2_11_10", 16); iVar6 = 11; iVar7 = 10; iVar1 = 690; break; case 29: StringCopy(&Var2, "LEGS_P2_11_11", 16); iVar6 = 11; iVar7 = 11; iVar1 = 820; break; case 30: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; bVar0 = true; break; case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 13; iVar7 = 0; bVar0 = true; break; case 32: StringCopy(&Var2, "LEGS_P2_14_0", 16); iVar6 = 14; iVar7 = 0; break; case 33: StringCopy(&Var2, "LEGS_P2_15_0", 16); iVar6 = 15; iVar7 = 0; break; case 34: StringCopy(&Var2, "LEGS_P2_16_0", 16); iVar6 = 16; iVar7 = 0; bVar0 = true; break; case 35: StringCopy(&Var2, "LEGS_P2_17_0", 16); iVar6 = 17; iVar7 = 0; iVar1 = 58; break; case 36: StringCopy(&Var2, "LEGS_P2_17_1", 16); iVar6 = 17; iVar7 = 1; iVar1 = 68; break; case 37: StringCopy(&Var2, "LEGS_P2_17_2", 16); iVar6 = 17; iVar7 = 2; iVar1 = 65; break; case 38: StringCopy(&Var2, "LEGS_P2_17_3", 16); iVar6 = 17; iVar7 = 3; iVar1 = 60; break; case 39: StringCopy(&Var2, "LEGS_P2_17_4", 16); iVar6 = 17; iVar7 = 4; iVar1 = 65; break; case 40: StringCopy(&Var2, "LEGS_P2_17_5", 16); iVar6 = 17; iVar7 = 5; iVar1 = 63; break; case 41: StringCopy(&Var2, "LEGS_P2_17_6", 16); iVar6 = 17; iVar7 = 6; iVar1 = 60; break; case 42: StringCopy(&Var2, "LEGS_P2_17_7", 16); iVar6 = 17; iVar7 = 7; iVar1 = 58; break; case 43: StringCopy(&Var2, "LEGS_P2_18_0", 16); iVar6 = 18; iVar7 = 0; break; case 44: StringCopy(&Var2, "LEGS_P2_18_1", 16); iVar6 = 18; iVar7 = 1; break; case 45: StringCopy(&Var2, "LEGS_P2_18_2", 16); iVar6 = 18; iVar7 = 2; iVar1 = 99; break; case 46: StringCopy(&Var2, "LEGS_P2_18_3", 16); iVar6 = 18; iVar7 = 3; iVar1 = 105; break; case 47: StringCopy(&Var2, "LEGS_P2_18_4", 16); iVar6 = 18; iVar7 = 4; iVar1 = 110; break; case 48: StringCopy(&Var2, "LEGS_P2_18_5", 16); iVar6 = 18; iVar7 = 5; iVar1 = 110; break; case 49: StringCopy(&Var2, "LEGS_P2_18_6", 16); iVar6 = 18; iVar7 = 6; iVar1 = 99; break; case 50: StringCopy(&Var2, "LEGS_P2_18_7", 16); iVar6 = 18; iVar7 = 7; iVar1 = 110; break; case 51: StringCopy(&Var2, "LEGS_P2_18_8", 16); iVar6 = 18; iVar7 = 8; iVar1 = 110; break; case 52: StringCopy(&Var2, "LEGS_P2_18_9", 16); iVar6 = 18; iVar7 = 9; iVar1 = 105; break; case 53: StringCopy(&Var2, "LEGS_P2_18_10", 16); iVar6 = 18; iVar7 = 10; iVar1 = 105; break; case 54: StringCopy(&Var2, "LEGS_P2_19_0", 16); iVar6 = 19; iVar7 = 0; iVar1 = 15; break; case 55: StringCopy(&Var2, "LEGS_P2_19_1", 16); iVar6 = 19; iVar7 = 1; iVar1 = 15; break; case 56: StringCopy(&Var2, "LEGS_P2_19_2", 16); iVar6 = 19; iVar7 = 2; iVar1 = 15; break; case 57: StringCopy(&Var2, "LEGS_P2_19_3", 16); iVar6 = 19; iVar7 = 3; iVar1 = 15; break; case 58: StringCopy(&Var2, "LEGS_P2_19_4", 16); iVar6 = 19; iVar7 = 4; iVar1 = 15; break; case 59: StringCopy(&Var2, "LEGS_P2_19_5", 16); iVar6 = 19; iVar7 = 5; iVar1 = 15; break; case 60: StringCopy(&Var2, "LEGS_P2_19_6", 16); iVar6 = 19; iVar7 = 6; iVar1 = 15; break; case 61: StringCopy(&Var2, "LEGS_P2_19_7", 16); iVar6 = 19; iVar7 = 7; iVar1 = 15; break; case 62: StringCopy(&Var2, "LEGS_P2_20_0", 16); iVar6 = 20; iVar7 = 0; iVar1 = 600; break; case 63: StringCopy(&Var2, "LEGS_P2_20_1", 16); iVar6 = 20; iVar7 = 1; iVar1 = 600; break; case 64: StringCopy(&Var2, "LEGS_P2_20_2", 16); iVar6 = 20; iVar7 = 2; iVar1 = 600; break; case 65: StringCopy(&Var2, "LEGS_P2_20_3", 16); iVar6 = 20; iVar7 = 3; iVar1 = 600; break; case 66: StringCopy(&Var2, "LEGS_P2_20_4", 16); iVar6 = 20; iVar7 = 4; iVar1 = 600; break; case 67: StringCopy(&Var2, "LEGS_P2_20_5", 16); iVar6 = 20; iVar7 = 5; iVar1 = 600; break; case 68: StringCopy(&Var2, "LEGS_P2_20_6", 16); iVar6 = 20; iVar7 = 6; iVar1 = 600; break; case 69: StringCopy(&Var2, "LEGS_P2_20_7", 16); iVar6 = 20; iVar7 = 7; iVar1 = 600; break; case 70: StringCopy(&Var2, "LEGS_P2_20_8", 16); iVar6 = 20; iVar7 = 8; iVar1 = 600; break; case 71: StringCopy(&Var2, "LEGS_P2_21_0", 16); iVar6 = 21; iVar7 = 0; iVar1 = 80; break; case 72: StringCopy(&Var2, "LEGS_P2_21_1", 16); iVar6 = 21; iVar7 = 1; iVar1 = 80; break; case 73: StringCopy(&Var2, "LEGS_P2_21_2", 16); iVar6 = 21; iVar7 = 2; iVar1 = 80; break; case 74: StringCopy(&Var2, "LEGS_P2_21_3", 16); iVar6 = 21; iVar7 = 3; iVar1 = 80; break; case 75: StringCopy(&Var2, "LEGS_P2_21_4", 16); iVar6 = 21; iVar7 = 4; iVar1 = 80; break; case 76: StringCopy(&Var2, "LEGS_P2_21_5", 16); iVar6 = 21; iVar7 = 5; iVar1 = 80; break; case 77: StringCopy(&Var2, "LEGS_P2_21_6", 16); iVar6 = 21; iVar7 = 6; iVar1 = 80; break; case 78: StringCopy(&Var2, "LEGS_P2_21_7", 16); iVar6 = 21; iVar7 = 7; iVar1 = 80; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "LEGS_P2_21_8", 16); iVar6 = 21; iVar7 = 8; iVar1 = 80; break; case 80: StringCopy(&Var2, "LEGS_P2_21_9", 16); iVar6 = 21; iVar7 = 9; iVar1 = 80; break; case 81: StringCopy(&Var2, "LEGS_P2_22_0", 16); iVar6 = 22; iVar7 = 0; break; case 82: StringCopy(&Var2, "LEGS_P2_22_1", 16); iVar6 = 22; iVar7 = 1; iVar1 = 12; break; case 83: StringCopy(&Var2, "LEGS_P2_22_2", 16); iVar6 = 22; iVar7 = 2; iVar1 = 12; break; case 84: StringCopy(&Var2, "LEGS_P2_22_3", 16); iVar6 = 22; iVar7 = 3; iVar1 = 22; break; case 85: StringCopy(&Var2, "LEGS_P2_22_4", 16); iVar6 = 22; iVar7 = 4; iVar1 = 18; break; case 86: StringCopy(&Var2, "LEGS_P2_22_5", 16); iVar6 = 22; iVar7 = 5; iVar1 = 20; break; case 87: StringCopy(&Var2, "LEGS_P2_22_6", 16); iVar6 = 22; iVar7 = 6; iVar1 = 30; break; case 88: StringCopy(&Var2, "LEGS_P2_22_7", 16); iVar6 = 22; iVar7 = 7; iVar1 = 30; break; case 89: StringCopy(&Var2, "LEGS_P2_22_8", 16); iVar6 = 22; iVar7 = 8; iVar1 = 30; break; case 90: StringCopy(&Var2, "LEGS_P2_22_9", 16); iVar6 = 22; iVar7 = 9; iVar1 = 30; break; case 91: StringCopy(&Var2, "LEGS_P2_23_0", 16); iVar6 = 23; iVar7 = 0; break; case 92: StringCopy(&Var2, "LEGS_P2_24_0", 16); iVar6 = 24; iVar7 = 0; break; case 93: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 25; iVar7 = 0; bVar0 = true; break; case 94: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 0; break; case 95: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 1; break; case 96: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 2; break; case 97: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 3; break; case 98: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 4; break; case 99: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 5; break; case 100: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 6; break; case 101: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 7; break; case 102: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 8; break; case 103: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 9; break; default: func_163(iVar10, iParam0, 104, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_175(int iParam0) { if (iParam0 < 136) { func_177(iParam0); } else { func_176(iParam0); } if (Global_76647[0 /*14*/].f_2 == -1) { func_163(3, iParam0, 242, -1); } } void func_176(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 3; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 136: StringCopy(&Var2, "TORSO_P2_21_0", 16); iVar6 = 21; iVar7 = 0; iVar1 = 32; break; case 137: StringCopy(&Var2, "TORSO_P2_21_1", 16); iVar6 = 21; iVar7 = 1; iVar1 = 39; break; case 138: StringCopy(&Var2, "TORSO_P2_21_2", 16); iVar6 = 21; iVar7 = 2; iVar1 = 40; break; case 139: StringCopy(&Var2, "TORSO_P2_21_3", 16); iVar6 = 21; iVar7 = 3; iVar1 = 42; break; case 140: StringCopy(&Var2, "TORSO_P2_21_4", 16); iVar6 = 21; iVar7 = 4; iVar1 = 45; break; case 141: StringCopy(&Var2, "TORSO_P2_21_5", 16); iVar6 = 21; iVar7 = 5; iVar1 = 48; break; case 142: StringCopy(&Var2, "TORSO_P2_21_6", 16); iVar6 = 21; iVar7 = 6; iVar1 = 52; break; case 143: StringCopy(&Var2, "TORSO_P2_21_7", 16); iVar6 = 21; iVar7 = 7; iVar1 = 55; break; case 144: StringCopy(&Var2, "TORSO_P2_22_0", 16); iVar6 = 22; iVar7 = 0; iVar1 = 390; break; case 145: StringCopy(&Var2, "TORSO_P2_22_1", 16); iVar6 = 22; iVar7 = 1; iVar1 = 390; break; case 146: StringCopy(&Var2, "TORSO_P2_22_2", 16); iVar6 = 22; iVar7 = 2; iVar1 = 560; break; case 147: StringCopy(&Var2, "TORSO_P2_22_3", 16); iVar6 = 22; iVar7 = 3; iVar1 = 390; break; case 148: StringCopy(&Var2, "TORSO_P2_22_4", 16); iVar6 = 22; iVar7 = 4; iVar1 = 390; break; case 149: StringCopy(&Var2, "TORSO_P2_22_5", 16); iVar6 = 22; iVar7 = 5; iVar1 = 390; break; case 150: StringCopy(&Var2, "TORSO_P2_22_6", 16); iVar6 = 22; iVar7 = 6; iVar1 = 560; break; case 151: StringCopy(&Var2, "TORSO_P2_22_7", 16); iVar6 = 22; iVar7 = 7; iVar1 = 390; break; case 152: StringCopy(&Var2, "TORSO_P2_22_8", 16); iVar6 = 22; iVar7 = 8; iVar1 = 390; break; case 153: StringCopy(&Var2, "TORSO_P2_22_9", 16); iVar6 = 22; iVar7 = 9; iVar1 = 390; break; case 154: StringCopy(&Var2, "TORSO_P2_22_10", 16); iVar6 = 22; iVar7 = 10; iVar1 = 390; break; case 155: StringCopy(&Var2, "TORSO_P2_22_11", 16); iVar6 = 22; iVar7 = 11; iVar1 = 3950; break; case 156: StringCopy(&Var2, "TORSO_P2_23_0", 16); iVar6 = 23; iVar7 = 0; iVar1 = 150; break; case 157: StringCopy(&Var2, "TORSO_P2_23_1", 16); iVar6 = 23; iVar7 = 1; break; case 158: StringCopy(&Var2, "TORSO_P2_23_2", 16); iVar6 = 23; iVar7 = 2; iVar1 = 150; break; case 159: StringCopy(&Var2, "TORSO_P2_23_3", 16); iVar6 = 23; iVar7 = 3; iVar1 = 150; break; case 160: StringCopy(&Var2, "TORSO_P2_23_4", 16); iVar6 = 23; iVar7 = 4; iVar1 = 160; break; case 161: StringCopy(&Var2, "TORSO_P2_23_5", 16); iVar6 = 23; iVar7 = 5; break; case 162: StringCopy(&Var2, "TORSO_P2_24_0", 16); iVar6 = 24; iVar7 = 0; iVar1 = 19; break; case 163: StringCopy(&Var2, "TORSO_P2_24_1", 16); iVar6 = 24; iVar7 = 1; iVar1 = 20; break; case 164: StringCopy(&Var2, "TORSO_P2_24_2", 16); iVar6 = 24; iVar7 = 2; iVar1 = 19; break; case 165: StringCopy(&Var2, "TORSO_P2_24_3", 16); iVar6 = 24; iVar7 = 3; iVar1 = 22; break; case 166: StringCopy(&Var2, "TORSO_P2_24_4", 16); iVar6 = 24; iVar7 = 4; iVar1 = 20; break; case 167: StringCopy(&Var2, "TORSO_P2_24_5", 16); iVar6 = 24; iVar7 = 5; iVar1 = 28; break; case 168: StringCopy(&Var2, "TORSO_P2_24_6", 16); iVar6 = 24; iVar7 = 6; iVar1 = 28; break; case 169: StringCopy(&Var2, "TORSO_P2_24_7", 16); iVar6 = 24; iVar7 = 7; iVar1 = 25; break; case 170: StringCopy(&Var2, "TORSO_P2_24_8", 16); iVar6 = 24; iVar7 = 8; iVar1 = 22; break; case 171: StringCopy(&Var2, "TORSO_P2_24_9", 16); iVar6 = 24; iVar7 = 9; iVar1 = 19; break; case 172: StringCopy(&Var2, "TORSO_P2_24_10", 16); iVar6 = 24; iVar7 = 10; iVar1 = 22; break; case 173: StringCopy(&Var2, "TORSO_P2_24_11", 16); iVar6 = 24; iVar7 = 11; iVar1 = 19; break; case 174: StringCopy(&Var2, "TORSO_P2_24_12", 16); iVar6 = 24; iVar7 = 12; iVar1 = 20; break; case 175: StringCopy(&Var2, "TORSO_P2_24_13", 16); iVar6 = 24; iVar7 = 13; iVar1 = 25; break; case 176: StringCopy(&Var2, "TORSO_P2_24_14", 16); iVar6 = 24; iVar7 = 14; iVar1 = 20; break; case 177: StringCopy(&Var2, "TORSO_P2_24_15", 16); iVar6 = 24; iVar7 = 15; iVar1 = 28; break; case 178: StringCopy(&Var2, "TORSO_P2_25_0", 16); iVar6 = 25; iVar7 = 0; iVar1 = 35; break; case 179: StringCopy(&Var2, "TORSO_P2_25_1", 16); iVar6 = 25; iVar7 = 1; iVar1 = 40; break; case 180: StringCopy(&Var2, "TORSO_P2_25_2", 16); iVar6 = 25; iVar7 = 2; iVar1 = 45; break; case 181: StringCopy(&Var2, "TORSO_P2_25_3", 16); iVar6 = 25; iVar7 = 3; iVar1 = 45; break; case 182: StringCopy(&Var2, "TORSO_P2_25_4", 16); iVar6 = 25; iVar7 = 4; iVar1 = 49; break; case 183: StringCopy(&Var2, "TORSO_P2_25_5", 16); iVar6 = 25; iVar7 = 5; iVar1 = 820; break; case 184: StringCopy(&Var2, "TORSO_P2_25_6", 16); iVar6 = 25; iVar7 = 6; iVar1 = 790; break; case 185: StringCopy(&Var2, "TORSO_P2_25_7", 16); iVar6 = 25; iVar7 = 7; iVar1 = 820; break; case 186: StringCopy(&Var2, "TORSO_P2_25_8", 16); iVar6 = 25; iVar7 = 8; iVar1 = 929; break; case 187: StringCopy(&Var2, "TORSO_P2_25_9", 16); iVar6 = 25; iVar7 = 9; iVar1 = 40; break; case 188: StringCopy(&Var2, "TORSO_P2_25_10", 16); iVar6 = 25; iVar7 = 10; iVar1 = 850; break; case 189: StringCopy(&Var2, "TORSO_P2_25_11", 16); iVar6 = 25; iVar7 = 11; iVar1 = 790; break; case 190: StringCopy(&Var2, "TORSO_P2_26_0", 16); iVar6 = 26; iVar7 = 0; break; case 191: StringCopy(&Var2, "TORSO_P2_26_1", 16); iVar6 = 26; iVar7 = 1; break; case 192: StringCopy(&Var2, "TORSO_P2_26_2", 16); iVar6 = 26; iVar7 = 2; break; case 193: StringCopy(&Var2, "TORSO_P2_26_3", 16); iVar6 = 26; iVar7 = 3; break; case 194: StringCopy(&Var2, "TORSO_P2_26_4", 16); iVar6 = 26; iVar7 = 4; break; case 195: StringCopy(&Var2, "TORSO_P2_26_5", 16); iVar6 = 26; iVar7 = 5; break; case 196: StringCopy(&Var2, "TORSO_P2_26_6", 16); iVar6 = 26; iVar7 = 6; break; case 197: StringCopy(&Var2, "TORSO_P2_26_7", 16); iVar6 = 26; iVar7 = 7; break; case 198: StringCopy(&Var2, "TORSO_P2_26_8", 16); iVar6 = 26; iVar7 = 8; break; case 199: StringCopy(&Var2, "TORSO_P2_26_9", 16); iVar6 = 26; iVar7 = 9; break; case 200: StringCopy(&Var2, "TORSO_P2_27_0", 16); iVar6 = 27; iVar7 = 0; iVar1 = 2200; break; case 201: StringCopy(&Var2, "TORSO_P2_27_1", 16); iVar6 = 27; iVar7 = 1; iVar1 = 2500; break; case 202: StringCopy(&Var2, "TORSO_P2_27_2", 16); iVar6 = 27; iVar7 = 2; iVar1 = 2500; break; case 203: StringCopy(&Var2, "TORSO_P2_27_3", 16); iVar6 = 27; iVar7 = 3; iVar1 = 2200; break; case 204: StringCopy(&Var2, "TORSO_P2_27_4", 16); iVar6 = 27; iVar7 = 4; iVar1 = 2500; break; case 205: StringCopy(&Var2, "TORSO_P2_27_5", 16); iVar6 = 27; iVar7 = 5; iVar1 = 2500; break; case 206: StringCopy(&Var2, "TORSO_P2_27_6", 16); iVar6 = 27; iVar7 = 6; iVar1 = 2200; break; case 207: StringCopy(&Var2, "TORSO_P2_28_0", 16); iVar6 = 28; iVar7 = 0; iVar1 = 1100; break; case 208: StringCopy(&Var2, "TORSO_P2_28_1", 16); iVar6 = 28; iVar7 = 1; iVar1 = 1200; break; case 209: StringCopy(&Var2, "TORSO_P2_28_2", 16); iVar6 = 28; iVar7 = 2; iVar1 = 1220; break; case 210: StringCopy(&Var2, "TORSO_P2_28_3", 16); iVar6 = 28; iVar7 = 3; iVar1 = 1250; break; case 211: StringCopy(&Var2, "TORSO_P2_28_4", 16); iVar6 = 28; iVar7 = 4; iVar1 = 1300; break; case 212: StringCopy(&Var2, "TORSO_P2_28_5", 16); iVar6 = 28; iVar7 = 5; iVar1 = 1360; break; case 213: StringCopy(&Var2, "TORSO_P2_28_6", 16); iVar6 = 28; iVar7 = 6; iVar1 = 35; break; case 214: StringCopy(&Var2, "TORSO_P2_28_7", 16); iVar6 = 28; iVar7 = 7; iVar1 = 38; break; case 215: StringCopy(&Var2, "TORSO_P2_28_8", 16); iVar6 = 28; iVar7 = 8; iVar1 = 40; break; case 216: StringCopy(&Var2, "TORSO_P2_28_9", 16); iVar6 = 28; iVar7 = 9; iVar1 = 42; break; case 217: StringCopy(&Var2, "TORSO_P2_28_10", 16); iVar6 = 28; iVar7 = 10; iVar1 = 50; break; case 218: StringCopy(&Var2, "TORSO_P2_28_11", 16); iVar6 = 28; iVar7 = 11; iVar1 = 45; break; case 219: StringCopy(&Var2, "TORSO_P2_28_12", 16); iVar6 = 28; iVar7 = 12; iVar1 = 45; break; case 220: StringCopy(&Var2, "TORSO_P2_28_13", 16); iVar6 = 28; iVar7 = 13; iVar1 = 44; break; case 221: StringCopy(&Var2, "TORSO_P2_28_14", 16); iVar6 = 28; iVar7 = 14; iVar1 = 46; break; case 222: StringCopy(&Var2, "TORSO_P2_28_15", 16); iVar6 = 28; iVar7 = 15; iVar1 = 52; break; case 223: StringCopy(&Var2, "TORSO_P2_29_0", 16); iVar6 = 29; iVar7 = 0; iVar1 = 3200; break; case 224: StringCopy(&Var2, "TORSO_P2_29_1", 16); iVar6 = 29; iVar7 = 1; iVar1 = 3200; break; case 225: StringCopy(&Var2, "TORSO_P2_29_2", 16); iVar6 = 29; iVar7 = 2; iVar1 = 2550; break; case 226: StringCopy(&Var2, "TORSO_P2_29_3", 16); iVar6 = 29; iVar7 = 3; iVar1 = 2750; break; case 227: StringCopy(&Var2, "TORSO_P2_29_4", 16); iVar6 = 29; iVar7 = 4; iVar1 = 2590; break; case 228: StringCopy(&Var2, "TORSO_P2_29_5", 16); iVar6 = 29; iVar7 = 5; iVar1 = 2750; break; case 229: StringCopy(&Var2, "TORSO_P2_29_6", 16); iVar6 = 29; iVar7 = 6; iVar1 = 2550; break; case 230: StringCopy(&Var2, "TORSO_P2_29_7", 16); iVar6 = 29; iVar7 = 7; iVar1 = 2590; break; case 231: StringCopy(&Var2, "TORSO_P2_29_8", 16); iVar6 = 29; iVar7 = 8; iVar1 = 2720; break; case 232: StringCopy(&Var2, "TORSO_P2_29_9", 16); iVar6 = 29; iVar7 = 9; iVar1 = 2750; break; case 233: StringCopy(&Var2, "TORSO_P2_30_0", 16); iVar6 = 30; iVar7 = 0; iVar1 = 3250; break; case 234: StringCopy(&Var2, "TORSO_P2_30_1", 16); iVar6 = 30; iVar7 = 1; iVar1 = 2950; break; case 235: StringCopy(&Var2, "TORSO_P2_30_2", 16); iVar6 = 30; iVar7 = 2; iVar1 = 3100; break; case 236: StringCopy(&Var2, "TORSO_P2_30_3", 16); iVar6 = 30; iVar7 = 3; iVar1 = 3150; break; case 237: StringCopy(&Var2, "TORSO_P2_30_4", 16); iVar6 = 30; iVar7 = 4; iVar1 = 3240; break; case 238: StringCopy(&Var2, "TORSO_P2_30_5", 16); iVar6 = 30; iVar7 = 5; iVar1 = 3350; break; case 239: StringCopy(&Var2, "TORSO_P2_30_6", 16); iVar6 = 30; iVar7 = 6; iVar1 = 3400; break; case 240: StringCopy(&Var2, "TORSO_P2_30_7", 16); iVar6 = 30; iVar7 = 7; iVar1 = 3280; break; case 241: StringCopy(&Var2, "TORSO_P2_31_0", 16); iVar6 = 31; iVar7 = 0; break; default: return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_177(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 3; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "TORSO_P2_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "TORSO_P2_0_1", 16); iVar6 = 0; iVar7 = 1; iVar1 = 25; break; case 2: StringCopy(&Var2, "TORSO_P2_0_2", 16); iVar6 = 0; iVar7 = 2; break; case 3: StringCopy(&Var2, "TORSO_P2_0_3", 16); iVar6 = 0; iVar7 = 3; iVar1 = 15; break; case 4: StringCopy(&Var2, "TORSO_P2_0_4", 16); iVar6 = 0; iVar7 = 4; iVar1 = 25; break; case 5: StringCopy(&Var2, "TORSO_P2_0_5", 16); iVar6 = 0; iVar7 = 5; iVar1 = 25; break; case 6: StringCopy(&Var2, "TORSO_P2_0_6", 16); iVar6 = 0; iVar7 = 6; iVar1 = 22; break; case 7: StringCopy(&Var2, "TORSO_P2_0_7", 16); iVar6 = 0; iVar7 = 7; iVar1 = 22; break; case 8: StringCopy(&Var2, "TORSO_P2_0_8", 16); iVar6 = 0; iVar7 = 8; iVar1 = 20; break; case 9: StringCopy(&Var2, "TORSO_P2_0_9", 16); iVar6 = 0; iVar7 = 9; iVar1 = 20; break; case 10: StringCopy(&Var2, "TORSO_P2_0_10", 16); iVar6 = 0; iVar7 = 10; iVar1 = 24; break; case 11: StringCopy(&Var2, "TORSO_P2_0_11", 16); iVar6 = 0; iVar7 = 11; iVar1 = 26; break; case 12: StringCopy(&Var2, "TORSO_P2_0_12", 16); iVar6 = 0; iVar7 = 12; iVar1 = 28; break; case 13: StringCopy(&Var2, "TORSO_P2_0_13", 16); iVar6 = 0; iVar7 = 13; iVar1 = 29; break; case 14: StringCopy(&Var2, "TORSO_P2_0_14", 16); iVar6 = 0; iVar7 = 14; iVar1 = 22; break; case 15: StringCopy(&Var2, "TORSO_P2_0_15", 16); iVar6 = 0; iVar7 = 15; iVar1 = 20; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 18: StringCopy(&Var2, "TORSO_P2_3_0", 16); iVar6 = 3; iVar7 = 0; iVar1 = 35; break; case 19: StringCopy(&Var2, "TORSO_P2_3_1", 16); iVar6 = 3; iVar7 = 1; iVar1 = 22; break; case 20: StringCopy(&Var2, "TORSO_P2_3_2", 16); iVar6 = 3; iVar7 = 2; iVar1 = 25; break; case 21: StringCopy(&Var2, "TORSO_P2_3_3", 16); iVar6 = 3; iVar7 = 3; iVar1 = 38; break; case 22: StringCopy(&Var2, "TORSO_P2_3_4", 16); iVar6 = 3; iVar7 = 4; iVar1 = 40; break; case 23: StringCopy(&Var2, "TORSO_P2_3_5", 16); iVar6 = 3; iVar7 = 5; iVar1 = 40; break; case 24: StringCopy(&Var2, "TORSO_P2_3_6", 16); iVar6 = 3; iVar7 = 6; iVar1 = 40; break; case 25: StringCopy(&Var2, "TORSO_P2_3_7", 16); iVar6 = 3; iVar7 = 7; iVar1 = 40; break; case 26: StringCopy(&Var2, "TORSO_P2_3_8", 16); iVar6 = 3; iVar7 = 8; iVar1 = 40; break; case 27: StringCopy(&Var2, "TORSO_P2_4_0", 16); iVar6 = 4; iVar7 = 0; break; case 28: StringCopy(&Var2, "TORSO_P2_4_1", 16); iVar6 = 4; iVar7 = 1; iVar1 = 500; break; case 29: StringCopy(&Var2, "TORSO_P2_4_2", 16); iVar6 = 4; iVar7 = 2; iVar1 = 560; break; case 30: StringCopy(&Var2, "TORSO_P2_4_3", 16); iVar6 = 4; iVar7 = 3; iVar1 = 600; break; case 31: StringCopy(&Var2, "TORSO_P2_4_4tu", 16); iVar6 = 4; iVar7 = 4; iVar1 = 650; break; case 32: StringCopy(&Var2, "TORSO_P2_4_5tu", 16); iVar6 = 4; iVar7 = 5; iVar1 = 500; break; case 33: StringCopy(&Var2, "TORSO_P2_4_6tu", 16); iVar6 = 4; iVar7 = 6; iVar1 = 560; break; case 34: StringCopy(&Var2, "TORSO_P2_4_7", 16); iVar6 = 4; iVar7 = 7; iVar1 = 500; break; case 35: StringCopy(&Var2, "TORSO_P2_4_8", 16); iVar6 = 4; iVar7 = 8; iVar1 = 650; break; case 36: StringCopy(&Var2, "TORSO_P2_4_9", 16); iVar6 = 4; iVar7 = 9; iVar1 = 540; break; case 37: StringCopy(&Var2, "TORSO_P2_4_10", 16); iVar6 = 4; iVar7 = 10; iVar1 = 690; break; case 38: StringCopy(&Var2, "TORSO_P2_4_11", 16); iVar6 = 4; iVar7 = 11; iVar1 = 560; break; case 39: StringCopy(&Var2, "TORSO_P2_4_12", 16); iVar6 = 4; iVar7 = 12; iVar1 = 590; break; case 40: StringCopy(&Var2, "TORSO_P2_4_13", 16); iVar6 = 4; iVar7 = 13; iVar1 = 690; break; case 41: StringCopy(&Var2, "TORSO_P2_4_14", 16); iVar6 = 4; iVar7 = 14; iVar1 = 540; break; case 42: StringCopy(&Var2, "TORSO_P2_4_15", 16); iVar6 = 4; iVar7 = 15; iVar1 = 500; break; case 43: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 44: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 1; bVar0 = true; break; case 45: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 2; bVar0 = true; break; case 46: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 3; bVar0 = true; break; case 47: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 4; bVar0 = true; break; case 48: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 5; bVar0 = true; break; case 49: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 50: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 51: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; break; case 52: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 53: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 54: StringCopy(&Var2, "TORSO_P2_11_0", 16); iVar6 = 11; iVar7 = 0; break; case 55: StringCopy(&Var2, "TORSO_P2_11_1", 16); iVar6 = 11; iVar7 = 1; break; case 56: StringCopy(&Var2, "TORSO_P2_11_2", 16); iVar6 = 11; iVar7 = 2; iVar1 = 25; break; case 57: StringCopy(&Var2, "TORSO_P2_11_3", 16); iVar6 = 11; iVar7 = 3; iVar1 = 27; break; case 58: StringCopy(&Var2, "TORSO_P2_11_4", 16); iVar6 = 11; iVar7 = 4; iVar1 = 22; break; case 59: StringCopy(&Var2, "TORSO_P2_11_5", 16); iVar6 = 11; iVar7 = 5; iVar1 = 350; break; case 60: StringCopy(&Var2, "TORSO_P2_11_6", 16); iVar6 = 11; iVar7 = 6; iVar1 = 27; break; case 61: StringCopy(&Var2, "TORSO_P2_11_7", 16); iVar6 = 11; iVar7 = 7; iVar1 = 370; break; case 62: StringCopy(&Var2, "TORSO_P2_11_8", 16); iVar6 = 11; iVar7 = 8; iVar1 = 25; break; case 63: StringCopy(&Var2, "TORSO_P2_11_9", 16); iVar6 = 11; iVar7 = 9; iVar1 = 22; break; case 64: StringCopy(&Var2, "TORSO_P2_11_10", 16); iVar6 = 11; iVar7 = 10; iVar1 = 25; break; case 65: StringCopy(&Var2, "TORSO_P2_11_11", 16); iVar6 = 11; iVar7 = 11; break; case 66: StringCopy(&Var2, "TORSO_P2_11_12", 16); iVar6 = 11; iVar7 = 12; iVar1 = 22; break; case 67: StringCopy(&Var2, "TORSO_P2_11_13", 16); iVar6 = 11; iVar7 = 13; iVar1 = 27; break; case 68: StringCopy(&Var2, "TORSO_P2_11_14", 16); iVar6 = 11; iVar7 = 14; iVar1 = 25; break; case 69: StringCopy(&Var2, "TORSO_P2_11_15", 16); iVar6 = 11; iVar7 = 15; iVar1 = 27; break; case 70: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; bVar0 = true; iVar9 = 1; break; case 71: StringCopy(&Var2, "TORSO_P2_13_0", 16); iVar6 = 13; iVar7 = 0; break; case 72: StringCopy(&Var2, "TORSO_P2_13_1", 16); iVar6 = 13; iVar7 = 1; iVar1 = 39; break; case 73: StringCopy(&Var2, "TORSO_P2_13_2", 16); iVar6 = 13; iVar7 = 2; iVar1 = 42; break; case 74: StringCopy(&Var2, "TORSO_P2_13_3", 16); iVar6 = 13; iVar7 = 3; iVar1 = 49; break; case 75: StringCopy(&Var2, "TORSO_P2_13_4", 16); iVar6 = 13; iVar7 = 4; iVar1 = 35; break; case 76: StringCopy(&Var2, "TORSO_P2_13_5", 16); iVar6 = 13; iVar7 = 5; iVar1 = 50; break; case 77: StringCopy(&Var2, "TORSO_P2_13_6", 16); iVar6 = 13; iVar7 = 6; iVar1 = 50; break; case 78: StringCopy(&Var2, "TORSO_P2_13_7", 16); iVar6 = 13; iVar7 = 7; iVar1 = 50; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "TORSO_P2_14_0", 16); iVar6 = 14; iVar7 = 0; break; case 80: StringCopy(&Var2, "TORSO_P2_14_1", 16); iVar6 = 14; iVar7 = 1; iVar1 = 88; break; case 81: StringCopy(&Var2, "TORSO_P2_14_2", 16); iVar6 = 14; iVar7 = 2; iVar1 = 60; break; case 82: StringCopy(&Var2, "TORSO_P2_14_3", 16); iVar6 = 14; iVar7 = 3; iVar1 = 80; break; case 83: StringCopy(&Var2, "TORSO_P2_14_4", 16); iVar6 = 14; iVar7 = 4; iVar1 = 70; break; case 84: StringCopy(&Var2, "TORSO_P2_14_5", 16); iVar6 = 14; iVar7 = 5; iVar1 = 80; break; case 85: StringCopy(&Var2, "TORSO_P2_14_6", 16); iVar6 = 14; iVar7 = 6; iVar1 = 70; break; case 86: StringCopy(&Var2, "TORSO_P2_14_7", 16); iVar6 = 14; iVar7 = 7; iVar1 = 90; break; case 87: StringCopy(&Var2, "TORSO_P2_14_8", 16); iVar6 = 14; iVar7 = 8; iVar1 = 95; break; case 88: StringCopy(&Var2, "TORSO_P2_14_9", 16); iVar6 = 14; iVar7 = 9; iVar1 = 105; break; case 89: StringCopy(&Var2, "TORSO_P2_14_10", 16); iVar6 = 14; iVar7 = 10; iVar1 = 95; break; case 90: StringCopy(&Var2, "TORSO_P2_14_11", 16); iVar6 = 14; iVar7 = 11; iVar1 = 110; break; case 91: StringCopy(&Var2, "TORSO_P2_14_12", 16); iVar6 = 14; iVar7 = 12; iVar1 = 98; break; case 92: StringCopy(&Var2, "TORSO_P2_14_13", 16); iVar6 = 14; iVar7 = 13; iVar1 = 88; break; case 93: StringCopy(&Var2, "TORSO_P2_14_14", 16); iVar6 = 14; iVar7 = 14; iVar1 = 98; break; case 94: StringCopy(&Var2, "TORSO_P2_14_15", 16); iVar6 = 14; iVar7 = 15; iVar1 = 110; break; case 95: StringCopy(&Var2, "TORSO_P2_15_0", 16); iVar6 = 15; iVar7 = 0; bVar0 = true; break; case 96: StringCopy(&Var2, "TORSO_P2_16_0", 16); iVar6 = 16; iVar7 = 0; break; case 97: StringCopy(&Var2, "TORSO_P2_17_0", 16); iVar6 = 17; iVar7 = 0; bVar0 = true; break; case 98: StringCopy(&Var2, "TORSO_P2_18_0", 16); iVar6 = 18; iVar7 = 0; break; case 99: StringCopy(&Var2, "TORSO_P2_18_1", 16); iVar6 = 18; iVar7 = 1; iVar1 = 520; break; case 100: StringCopy(&Var2, "TORSO_P2_18_2", 16); iVar6 = 18; iVar7 = 2; iVar1 = 490; break; case 101: StringCopy(&Var2, "TORSO_P2_18_3", 16); iVar6 = 18; iVar7 = 3; iVar1 = 450; break; case 102: StringCopy(&Var2, "TORSO_P2_18_4", 16); iVar6 = 18; iVar7 = 4; iVar1 = 420; break; case 103: StringCopy(&Var2, "TORSO_P2_18_5", 16); iVar6 = 18; iVar7 = 5; iVar1 = 420; break; case 104: StringCopy(&Var2, "TORSO_P2_19_0", 16); iVar6 = 19; iVar7 = 0; iVar1 = 85; break; case 105: StringCopy(&Var2, "TORSO_P2_19_1", 16); iVar6 = 19; iVar7 = 1; iVar1 = 85; break; case 106: StringCopy(&Var2, "TORSO_P2_19_2", 16); iVar6 = 19; iVar7 = 2; iVar1 = 75; break; case 107: StringCopy(&Var2, "TORSO_P2_19_3", 16); iVar6 = 19; iVar7 = 3; iVar1 = 68; break; case 108: StringCopy(&Var2, "TORSO_P2_19_4", 16); iVar6 = 19; iVar7 = 4; iVar1 = 68; break; case 109: StringCopy(&Var2, "TORSO_P2_19_5", 16); iVar6 = 19; iVar7 = 5; iVar1 = 78; break; case 110: StringCopy(&Var2, "TORSO_P2_19_6", 16); iVar6 = 19; iVar7 = 6; iVar1 = 85; break; case 111: StringCopy(&Var2, "TORSO_P2_19_7", 16); iVar6 = 19; iVar7 = 7; iVar1 = 68; break; case 112: StringCopy(&Var2, "TORSO_P2_19_8", 16); iVar6 = 19; iVar7 = 8; iVar1 = 75; break; case 113: StringCopy(&Var2, "TORSO_P2_19_9", 16); iVar6 = 19; iVar7 = 9; iVar1 = 75; break; case 114: StringCopy(&Var2, "TORSO_P2_19_10", 16); iVar6 = 19; iVar7 = 10; iVar1 = 78; break; case 115: StringCopy(&Var2, "TORSO_P2_19_11", 16); iVar6 = 19; iVar7 = 11; iVar1 = 75; break; case 116: StringCopy(&Var2, "TORSO_P2_19_12", 16); iVar6 = 19; iVar7 = 12; iVar1 = 75; break; case 117: StringCopy(&Var2, "TORSO_P2_19_13", 16); iVar6 = 19; iVar7 = 13; iVar1 = 75; break; case 118: StringCopy(&Var2, "TORSO_P2_19_14", 16); iVar6 = 19; iVar7 = 14; iVar1 = 78; break; case 119: StringCopy(&Var2, "TORSO_P2_19_15", 16); iVar6 = 19; iVar7 = 15; iVar1 = 78; break; case 120: StringCopy(&Var2, "TORSO_P2_20_0", 16); iVar6 = 20; iVar7 = 0; iVar1 = 40; break; case 121: StringCopy(&Var2, "TORSO_P2_20_1", 16); iVar6 = 20; iVar7 = 1; iVar1 = 32; break; case 122: StringCopy(&Var2, "TORSO_P2_20_2", 16); iVar6 = 20; iVar7 = 2; iVar1 = 32; break; case 123: StringCopy(&Var2, "TORSO_P2_20_3", 16); iVar6 = 20; iVar7 = 3; iVar1 = 32; break; case 124: StringCopy(&Var2, "TORSO_P2_20_4", 16); iVar6 = 20; iVar7 = 4; break; case 125: StringCopy(&Var2, "TORSO_P2_20_5", 16); iVar6 = 20; iVar7 = 5; iVar1 = 38; break; case 126: StringCopy(&Var2, "TORSO_P2_20_6", 16); iVar6 = 20; iVar7 = 6; iVar1 = 35; break; case 127: StringCopy(&Var2, "TORSO_P2_20_7", 16); iVar6 = 20; iVar7 = 7; iVar1 = 38; break; case 128: StringCopy(&Var2, "TORSO_P2_20_8", 16); iVar6 = 20; iVar7 = 8; iVar1 = 29; break; case 129: StringCopy(&Var2, "TORSO_P2_20_9", 16); iVar6 = 20; iVar7 = 9; iVar1 = 32; break; case 130: StringCopy(&Var2, "TORSO_P2_20_10", 16); iVar6 = 20; iVar7 = 10; iVar1 = 29; break; case 131: StringCopy(&Var2, "TORSO_P2_20_11", 16); iVar6 = 20; iVar7 = 11; iVar1 = 35; break; case 132: StringCopy(&Var2, "TORSO_P2_20_12", 16); iVar6 = 20; iVar7 = 12; iVar1 = 32; break; case 133: StringCopy(&Var2, "TORSO_P2_20_13", 16); iVar6 = 20; iVar7 = 13; iVar1 = 35; break; case 134: StringCopy(&Var2, "TORSO_P2_20_14", 16); iVar6 = 20; iVar7 = 14; iVar1 = 32; break; case 135: StringCopy(&Var2, "TORSO_P2_20_15", 16); iVar6 = 20; iVar7 = 15; iVar1 = 40; break; default: return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_178(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 2; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "HAIR_P2_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "HAIR_P2_0_1", 16); iVar6 = 0; iVar7 = 1; break; case 2: StringCopy(&Var2, "HAIR_P2_1_0", 16); iVar6 = 1; iVar7 = 0; break; case 3: StringCopy(&Var2, "HAIR_P2_2_0", 16); iVar6 = 2; iVar7 = 0; break; case 4: StringCopy(&Var2, "HAIR_P2_3_0", 16); iVar6 = 3; iVar7 = 0; break; case 5: StringCopy(&Var2, "HAIR_P2_4_0", 16); iVar6 = 4; iVar7 = 0; break; case 6: StringCopy(&Var2, "HAIR_P2_5_0", 16); iVar6 = 5; iVar7 = 0; break; case 7: StringCopy(&Var2, "HAIR_P2_6_0", 16); iVar6 = 6; iVar7 = 0; break; case 8: StringCopy(&Var2, "HAIR_P2_7_0", 16); iVar6 = 7; iVar7 = 0; break; default: func_163(iVar10, iParam0, 9, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_179(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 0; Global_76647[0 /*14*/].f_5 = 2; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 1; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 2; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 3; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 4; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 5; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 6; break; default: func_163(iVar10, iParam0, 7, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_180(int iParam0, int iParam1) { switch (iParam0) { case 0: func_198(iParam1); break; case 2: func_197(iParam1); break; case 3: func_193(iParam1); break; case 4: func_192(iParam1); break; case 6: func_191(iParam1); break; case 5: func_190(iParam1); break; case 8: func_189(iParam1); break; case 9: func_188(iParam1); break; case 10: func_187(iParam1); break; case 1: func_186(iParam1); break; case 7: func_185(iParam1); break; case 11: func_184(iParam1); break; case 12: func_183(iParam1); break; case 13: func_182(iParam1); break; case 14: func_181(iParam1); break; } } void func_181(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 14; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 1; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 2; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 3; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 4; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 5; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 6; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 7; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 8; break; case 158: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; iVar8 = 2; break; case 159: StringCopy(&Var2, "PROPS_P1_EA1_0", 16); iVar6 = 1; iVar7 = 0; iVar1 = 4590; iVar8 = 2; break; case 160: StringCopy(&Var2, "PROPS_P1_EA1_1", 16); iVar6 = 1; iVar7 = 1; iVar1 = 4100; iVar8 = 2; break; case 161: StringCopy(&Var2, "PROPS_P1_EA1_2", 16); iVar6 = 1; iVar7 = 2; iVar1 = 3850; iVar8 = 2; break; case 162: StringCopy(&Var2, "PROPS_P1_EA1_3", 16); iVar6 = 1; iVar7 = 3; iVar1 = 1850; iVar8 = 2; break; case 163: StringCopy(&Var2, "PROPS_P1_EA1_4", 16); iVar6 = 1; iVar7 = 4; iVar1 = 5250; iVar8 = 2; break; case 164: StringCopy(&Var2, "PROPS_P1_EA1_5", 16); iVar6 = 1; iVar7 = 5; iVar1 = 2700; iVar8 = 2; break; case 165: StringCopy(&Var2, "PROPS_P1_EA1_6", 16); iVar6 = 1; iVar7 = 6; iVar1 = 3100; iVar8 = 2; break; case 166: StringCopy(&Var2, "PROPS_P1_EA1_7", 16); iVar6 = 1; iVar7 = 7; iVar1 = 5050; iVar8 = 2; break; case 167: StringCopy(&Var2, "PROPS_P1_EA2_0", 16); iVar6 = 2; iVar7 = 0; iVar1 = 2500; iVar8 = 2; break; case 168: StringCopy(&Var2, "PROPS_P1_EA2_1", 16); iVar6 = 2; iVar7 = 1; iVar1 = 1950; iVar8 = 2; break; case 169: StringCopy(&Var2, "PROPS_P1_EA2_2", 16); iVar6 = 2; iVar7 = 2; iVar1 = 3900; iVar8 = 2; break; case 170: StringCopy(&Var2, "PROPS_P1_EA2_3", 16); iVar6 = 2; iVar7 = 3; iVar1 = 3550; iVar8 = 2; break; case 171: StringCopy(&Var2, "PROPS_P1_EA2_4", 16); iVar6 = 2; iVar7 = 4; iVar1 = 4500; iVar8 = 2; break; case 172: StringCopy(&Var2, "PROPS_P1_EA2_5", 16); iVar6 = 2; iVar7 = 5; iVar1 = 2700; iVar8 = 2; break; case 173: StringCopy(&Var2, "PROPS_P1_EA2_6", 16); iVar6 = 2; iVar7 = 6; iVar1 = 3100; iVar8 = 2; break; case 174: StringCopy(&Var2, "PROPS_P1_EA2_7", 16); iVar6 = 2; iVar7 = 7; iVar1 = 2950; iVar8 = 2; break; case 82: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; iVar8 = 10; break; case 83: StringCopy(&Var2, "PROPS_P1_E1_0", 16); iVar6 = 1; iVar7 = 0; iVar1 = 75; iVar8 = 10; break; case 84: StringCopy(&Var2, "PROPS_P1_E1_1", 16); iVar6 = 1; iVar7 = 1; iVar1 = 75; iVar8 = 10; break; case 85: StringCopy(&Var2, "PROPS_P1_E1_2", 16); iVar6 = 1; iVar7 = 2; iVar1 = 75; iVar8 = 10; break; case 86: StringCopy(&Var2, "PROPS_P1_E1_3", 16); iVar6 = 1; iVar7 = 3; iVar1 = 75; iVar8 = 10; break; case 87: StringCopy(&Var2, "PROPS_P1_E1_4", 16); iVar6 = 1; iVar7 = 4; iVar1 = 75; iVar8 = 10; break; case 88: StringCopy(&Var2, "PROPS_P1_E1_5", 16); iVar6 = 1; iVar7 = 5; iVar1 = 75; iVar8 = 10; break; case 89: StringCopy(&Var2, "PROPS_P1_E1_6", 16); iVar6 = 1; iVar7 = 6; iVar1 = 75; iVar8 = 10; break; case 90: StringCopy(&Var2, "PROPS_P1_E1_7", 16); iVar6 = 1; iVar7 = 7; iVar1 = 75; iVar8 = 10; break; case 91: StringCopy(&Var2, "PROPS_P1_E1_8", 16); iVar6 = 1; iVar7 = 8; iVar1 = 75; iVar8 = 10; break; case 92: StringCopy(&Var2, "PROPS_P1_E1_9", 16); iVar6 = 1; iVar7 = 9; iVar1 = 75; iVar8 = 10; break; case 93: StringCopy(&Var2, "PROPS_P1_E2", 16); iVar6 = 2; iVar7 = 0; iVar8 = 10; break; case 94: StringCopy(&Var2, "PROPS_P1_E3", 16); iVar6 = 3; iVar7 = 0; iVar1 = 110; iVar8 = 10; break; case 95: StringCopy(&Var2, "PROPS_P1_E4_0", 16); iVar6 = 4; iVar7 = 0; iVar1 = 120; iVar8 = 10; break; case 96: StringCopy(&Var2, "PROPS_P1_E4_1", 16); iVar6 = 4; iVar7 = 1; iVar1 = 128; iVar8 = 10; break; case 97: StringCopy(&Var2, "PROPS_P1_E4_2", 16); iVar6 = 4; iVar7 = 2; iVar1 = 130; iVar8 = 10; break; case 98: StringCopy(&Var2, "PROPS_P1_E4_3", 16); iVar6 = 4; iVar7 = 3; iVar1 = 140; iVar8 = 10; break; case 99: StringCopy(&Var2, "PROPS_P1_E4_4", 16); iVar6 = 4; iVar7 = 4; iVar1 = 145; iVar8 = 10; break; case 100: StringCopy(&Var2, "PROPS_P1_E4_5", 16); iVar6 = 4; iVar7 = 5; iVar1 = 135; iVar8 = 10; break; case 101: StringCopy(&Var2, "PROPS_P1_E4_6", 16); iVar6 = 4; iVar7 = 6; iVar1 = 138; iVar8 = 10; break; case 102: StringCopy(&Var2, "PROPS_P1_E5_0", 16); iVar6 = 5; iVar7 = 0; iVar1 = 110; iVar8 = 10; break; case 103: StringCopy(&Var2, "PROPS_P1_E5_1", 16); iVar6 = 5; iVar7 = 1; iVar1 = 112; iVar8 = 10; break; case 104: StringCopy(&Var2, "PROPS_P1_E5_2", 16); iVar6 = 5; iVar7 = 2; iVar1 = 115; iVar8 = 10; break; case 105: StringCopy(&Var2, "PROPS_P1_E5_3", 16); iVar6 = 5; iVar7 = 3; iVar1 = 118; iVar8 = 10; break; case 106: StringCopy(&Var2, "PROPS_P1_E5_4", 16); iVar6 = 5; iVar7 = 4; iVar1 = 120; iVar8 = 10; break; case 107: StringCopy(&Var2, "PROPS_P1_E5_5", 16); iVar6 = 5; iVar7 = 5; iVar1 = 125; iVar8 = 10; break; case 108: StringCopy(&Var2, "PROPS_P1_E5_6", 16); iVar6 = 5; iVar7 = 6; iVar1 = 128; iVar8 = 10; break; case 109: StringCopy(&Var2, "PROPS_P1_E5_7", 16); iVar6 = 5; iVar7 = 7; iVar1 = 138; iVar8 = 10; break; case 110: StringCopy(&Var2, "PROPS_P1_E5_8", 16); iVar6 = 5; iVar7 = 8; iVar1 = 140; iVar8 = 10; break; case 111: StringCopy(&Var2, "PROPS_P1_E5_9", 16); iVar6 = 5; iVar7 = 9; iVar1 = 155; iVar8 = 10; break; case 112: StringCopy(&Var2, "PROPS_P1_E6_0", 16); iVar6 = 6; iVar7 = 0; iVar1 = 55; iVar8 = 10; break; case 113: StringCopy(&Var2, "PROPS_P1_E6_1", 16); iVar6 = 6; iVar7 = 1; iVar1 = 55; iVar8 = 10; break; case 114: StringCopy(&Var2, "PROPS_P1_E6_2", 16); iVar6 = 6; iVar7 = 2; iVar1 = 58; iVar8 = 10; break; case 115: StringCopy(&Var2, "PROPS_P1_E6_3", 16); iVar6 = 6; iVar7 = 3; iVar1 = 58; iVar8 = 10; break; case 116: StringCopy(&Var2, "PROPS_P1_E6_4", 16); iVar6 = 6; iVar7 = 4; iVar1 = 60; iVar8 = 10; break; case 117: StringCopy(&Var2, "PROPS_P1_E6_5", 16); iVar6 = 6; iVar7 = 5; iVar1 = 62; iVar8 = 10; break; case 118: StringCopy(&Var2, "PROPS_P1_E6_6", 16); iVar6 = 6; iVar7 = 6; iVar1 = 65; iVar8 = 10; break; case 119: StringCopy(&Var2, "PROPS_P1_E6_7", 16); iVar6 = 6; iVar7 = 7; iVar1 = 68; iVar8 = 10; break; case 120: StringCopy(&Var2, "PROPS_P1_E6_8", 16); iVar6 = 6; iVar7 = 8; iVar1 = 68; iVar8 = 10; break; case 121: StringCopy(&Var2, "PROPS_P1_E6_9", 16); iVar6 = 6; iVar7 = 9; iVar1 = 72; iVar8 = 10; break; case 122: StringCopy(&Var2, "PROPS_P1_E7_0", 16); iVar6 = 7; iVar7 = 0; iVar1 = 145; iVar8 = 10; break; case 123: StringCopy(&Var2, "PROPS_P1_E7_1", 16); iVar6 = 7; iVar7 = 1; iVar1 = 149; iVar8 = 10; break; case 124: StringCopy(&Var2, "PROPS_P1_E7_2", 16); iVar6 = 7; iVar7 = 2; iVar1 = 139; iVar8 = 10; break; case 125: StringCopy(&Var2, "PROPS_P1_E7_3", 16); iVar6 = 7; iVar7 = 3; iVar1 = 149; iVar8 = 10; break; case 126: StringCopy(&Var2, "PROPS_P1_E7_4", 16); iVar6 = 7; iVar7 = 4; iVar1 = 135; iVar8 = 10; break; case 127: StringCopy(&Var2, "PROPS_P1_E7_5", 16); iVar6 = 7; iVar7 = 5; iVar1 = 138; iVar8 = 10; break; case 128: StringCopy(&Var2, "PROPS_P1_E7_6", 16); iVar6 = 7; iVar7 = 6; iVar1 = 140; iVar8 = 10; break; case 129: StringCopy(&Var2, "PROPS_P1_E7_7", 16); iVar6 = 7; iVar7 = 7; iVar1 = 145; iVar8 = 10; break; case 130: StringCopy(&Var2, "PROPS_P1_E7_8", 16); iVar6 = 7; iVar7 = 8; iVar1 = 159; iVar8 = 10; break; case 131: StringCopy(&Var2, "PROPS_P1_E7_9", 16); iVar6 = 7; iVar7 = 9; iVar1 = 155; iVar8 = 10; break; case 132: StringCopy(&Var2, "PROPS_P1_E8_0", 16); iVar6 = 8; iVar7 = 0; iVar1 = 198; iVar8 = 10; break; case 133: StringCopy(&Var2, "PROPS_P1_E8_1", 16); iVar6 = 8; iVar7 = 1; iVar1 = 210; iVar8 = 10; break; case 134: StringCopy(&Var2, "PROPS_P1_E8_2", 16); iVar6 = 8; iVar7 = 2; iVar1 = 185; iVar8 = 10; break; case 135: StringCopy(&Var2, "PROPS_P1_E8_3", 16); iVar6 = 8; iVar7 = 3; iVar1 = 220; iVar8 = 10; break; case 136: StringCopy(&Var2, "PROPS_P1_E8_4", 16); iVar6 = 8; iVar7 = 4; iVar1 = 190; iVar8 = 10; break; case 137: StringCopy(&Var2, "PROPS_P1_E8_5", 16); iVar6 = 8; iVar7 = 5; iVar1 = 200; iVar8 = 10; break; case 138: StringCopy(&Var2, "PROPS_P1_E8_6", 16); iVar6 = 8; iVar7 = 6; iVar1 = 208; iVar8 = 10; break; case 139: StringCopy(&Var2, "PROPS_P1_E8_7", 16); iVar6 = 8; iVar7 = 7; iVar1 = 210; iVar8 = 10; break; case 140: StringCopy(&Var2, "PROPS_P1_E9_0", 16); iVar6 = 9; iVar7 = 0; iVar1 = 165; iVar8 = 10; break; case 141: StringCopy(&Var2, "PROPS_P1_E9_1", 16); iVar6 = 9; iVar7 = 1; iVar1 = 185; iVar8 = 10; break; case 142: StringCopy(&Var2, "PROPS_P1_E9_2", 16); iVar6 = 9; iVar7 = 2; iVar1 = 190; iVar8 = 10; break; case 143: StringCopy(&Var2, "PROPS_P1_E9_3", 16); iVar6 = 9; iVar7 = 3; iVar1 = 178; iVar8 = 10; break; case 144: StringCopy(&Var2, "PROPS_P1_E9_4", 16); iVar6 = 9; iVar7 = 4; iVar1 = 180; iVar8 = 10; break; case 145: StringCopy(&Var2, "PROPS_P1_E9_5", 16); iVar6 = 9; iVar7 = 5; iVar1 = 168; iVar8 = 10; break; case 146: StringCopy(&Var2, "PROPS_P1_E9_6", 16); iVar6 = 9; iVar7 = 6; iVar1 = 170; iVar8 = 10; break; case 147: StringCopy(&Var2, "PROPS_P1_E9_7", 16); iVar6 = 9; iVar7 = 7; iVar1 = 175; iVar8 = 10; break; case 148: StringCopy(&Var2, "PROPS_P1_E9_8", 16); iVar6 = 9; iVar7 = 8; iVar1 = 170; iVar8 = 10; break; case 149: StringCopy(&Var2, "PROPS_P1_E9_9", 16); iVar6 = 9; iVar7 = 9; iVar1 = 178; iVar8 = 10; break; case 150: StringCopy(&Var2, "PROPS_P1_E10_0", 16); iVar6 = 10; iVar7 = 0; iVar1 = 140; iVar8 = 10; break; case 151: StringCopy(&Var2, "PROPS_P1_E10_1", 16); iVar6 = 10; iVar7 = 1; iVar1 = 145; iVar8 = 10; break; case 152: StringCopy(&Var2, "PROPS_P1_E10_2", 16); iVar6 = 10; iVar7 = 2; iVar1 = 150; iVar8 = 10; break; case 153: StringCopy(&Var2, "PROPS_P1_E10_3", 16); iVar6 = 10; iVar7 = 3; iVar1 = 165; iVar8 = 10; break; case 154: StringCopy(&Var2, "PROPS_P1_E10_4", 16); iVar6 = 10; iVar7 = 4; iVar1 = 168; iVar8 = 10; break; case 155: StringCopy(&Var2, "PROPS_P1_E10_5", 16); iVar6 = 10; iVar7 = 5; iVar1 = 178; iVar8 = 10; break; case 156: StringCopy(&Var2, "PROPS_P1_E10_6", 16); iVar6 = 10; iVar7 = 6; iVar1 = 160; iVar8 = 10; break; case 157: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; iVar1 = 100; iVar8 = 10; break; case 10: StringCopy(&Var2, "PROPS_P1_H0_0", 16); iVar6 = 0; iVar7 = 0; iVar1 = 320; iVar8 = 0; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 12: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 13: StringCopy(&Var2, "PROPS_P1_H3_0", 16); iVar6 = 3; iVar7 = 0; iVar8 = 0; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; iVar8 = 0; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; iVar8 = 0; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 1; iVar8 = 0; break; case 18: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 2; iVar8 = 0; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 3; iVar8 = 0; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 4; iVar8 = 0; break; case 21: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 5; iVar8 = 0; break; case 22: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 6; iVar8 = 0; break; case 23: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 7; iVar8 = 0; break; case 24: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 8; iVar8 = 0; break; case 25: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 26: StringCopy(&Var2, "PROPS_P1_H8_0", 16); iVar6 = 8; iVar7 = 0; iVar1 = 270; iVar8 = 0; break; case 27: StringCopy(&Var2, "PROPS_P1_H8_1", 16); iVar6 = 8; iVar7 = 1; iVar1 = 270; iVar8 = 0; break; case 28: StringCopy(&Var2, "PROPS_P1_H9_0", 16); iVar6 = 9; iVar7 = 0; iVar1 = 200; iVar8 = 0; break; case 29: StringCopy(&Var2, "PROPS_P1_H9_1", 16); iVar6 = 9; iVar7 = 1; iVar1 = 200; iVar8 = 0; break; case 30: StringCopy(&Var2, "PROPS_P1_H10_0", 16); iVar6 = 10; iVar7 = 0; iVar1 = 350; iVar8 = 0; break; case 31: StringCopy(&Var2, "PROPS_P1_H10_1", 16); iVar6 = 10; iVar7 = 1; iVar1 = 350; iVar8 = 0; break; case 32: StringCopy(&Var2, "PROPS_P1_H11_0", 16); iVar6 = 11; iVar7 = 0; iVar1 = 450; iVar8 = 0; break; case 33: StringCopy(&Var2, "PROPS_P1_H12_0", 16); iVar6 = 12; iVar7 = 0; iVar1 = 500; iVar8 = 0; break; case 34: StringCopy(&Var2, "PROPS_P1_H12_1", 16); iVar6 = 12; iVar7 = 1; iVar1 = 500; iVar8 = 0; break; case 35: StringCopy(&Var2, "PROPS_P1_H13_0", 16); iVar6 = 13; iVar7 = 0; iVar1 = 50; iVar8 = 0; break; case 36: StringCopy(&Var2, "PROPS_P1_H13_1", 16); iVar6 = 13; iVar7 = 1; iVar1 = 50; iVar8 = 0; break; case 37: StringCopy(&Var2, "PROPS_P1_H14_0", 16); iVar6 = 14; iVar7 = 0; iVar1 = 99; iVar8 = 0; break; case 38: StringCopy(&Var2, "PROPS_P1_H14_1", 16); iVar6 = 14; iVar7 = 1; iVar1 = 99; iVar8 = 0; break; case 39: StringCopy(&Var2, "PROPS_P1_H14_2", 16); iVar6 = 14; iVar7 = 2; iVar1 = 99; iVar8 = 0; break; case 40: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 15; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 41: StringCopy(&Var2, "PROPS_P1_H19_0", 16); iVar6 = 16; iVar7 = 0; iVar8 = 0; break; case 42: StringCopy(&Var2, "PROPS_P1_H19_1", 16); iVar6 = 16; iVar7 = 1; iVar8 = 0; break; case 43: StringCopy(&Var2, "PROPS_P1_H19_2", 16); iVar6 = 16; iVar7 = 2; iVar8 = 0; break; case 44: StringCopy(&Var2, "PROPS_P1_H19_3", 16); iVar6 = 16; iVar7 = 3; iVar8 = 0; break; case 45: StringCopy(&Var2, "PROPS_P1_H19_4", 16); iVar6 = 16; iVar7 = 4; iVar8 = 0; break; case 46: StringCopy(&Var2, "PROPS_P1_H19_5", 16); iVar6 = 16; iVar7 = 5; iVar8 = 0; break; case 47: StringCopy(&Var2, "PROPS_P1_H19_6", 16); iVar6 = 16; iVar7 = 6; iVar8 = 0; break; case 48: StringCopy(&Var2, "PROPS_P1_H19_7", 16); iVar6 = 16; iVar7 = 7; iVar8 = 0; break; case 49: StringCopy(&Var2, "PROPS_P1_H19_8", 16); iVar6 = 16; iVar7 = 8; iVar8 = 0; break; case 50: StringCopy(&Var2, "PROPS_P1_H19_9", 16); iVar6 = 16; iVar7 = 9; iVar8 = 0; break; case 51: StringCopy(&Var2, "PROPS_P1_H19_10", 16); iVar6 = 16; iVar7 = 10; iVar8 = 0; break; case 52: StringCopy(&Var2, "PROPS_P1_H19_11", 16); iVar6 = 16; iVar7 = 11; iVar8 = 0; break; case 53: StringCopy(&Var2, "PROPS_P1_H19_12", 16); iVar6 = 16; iVar7 = 12; iVar8 = 0; break; case 54: StringCopy(&Var2, "PROPS_P1_H19_13", 16); iVar6 = 16; iVar7 = 13; iVar8 = 0; break; case 55: StringCopy(&Var2, "PROPS_P1_H19_14", 16); iVar6 = 16; iVar7 = 14; iVar8 = 0; break; case 56: StringCopy(&Var2, "PROPS_P1_H19_15", 16); iVar6 = 16; iVar7 = 15; iVar8 = 0; break; case 57: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 0; iVar8 = 0; break; case 58: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 1; iVar8 = 0; break; case 59: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 2; iVar8 = 0; break; case 60: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 3; iVar8 = 0; break; case 61: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 4; iVar8 = 0; break; case 62: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 5; iVar8 = 0; break; case 63: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 18; iVar7 = 0; iVar8 = 0; break; case 64: StringCopy(&Var2, "PROPS_P1_H19_0", 16); iVar6 = 19; iVar7 = 0; iVar1 = 30; iVar8 = 0; break; case 65: StringCopy(&Var2, "PROPS_P1_H19_1", 16); iVar6 = 19; iVar7 = 1; iVar1 = 30; iVar8 = 0; break; case 66: StringCopy(&Var2, "PROPS_P1_H19_2", 16); iVar6 = 19; iVar7 = 2; iVar1 = 32; iVar8 = 0; break; case 67: StringCopy(&Var2, "PROPS_P1_H19_3", 16); iVar6 = 19; iVar7 = 3; iVar1 = 35; iVar8 = 0; break; case 68: StringCopy(&Var2, "PROPS_P1_H19_4", 16); iVar6 = 19; iVar7 = 4; iVar1 = 38; iVar8 = 0; break; case 69: StringCopy(&Var2, "PROPS_P1_H19_5", 16); iVar6 = 19; iVar7 = 5; iVar1 = 42; iVar8 = 0; break; case 70: StringCopy(&Var2, "PROPS_P1_H19_6", 16); iVar6 = 19; iVar7 = 6; iVar1 = 42; iVar8 = 0; break; case 71: StringCopy(&Var2, "PROPS_P1_H19_7", 16); iVar6 = 19; iVar7 = 7; iVar1 = 40; iVar8 = 0; break; case 72: StringCopy(&Var2, "PROPS_P1_H19_8", 16); iVar6 = 19; iVar7 = 8; iVar1 = 45; iVar8 = 0; break; case 73: StringCopy(&Var2, "PROPS_P1_H19_9", 16); iVar6 = 19; iVar7 = 9; iVar1 = 48; iVar8 = 0; break; case 74: StringCopy(&Var2, "PROPS_P1_H19_10", 16); iVar6 = 19; iVar7 = 10; iVar1 = 25; iVar8 = 0; break; case 75: StringCopy(&Var2, "PROPS_P1_H19_11", 16); iVar6 = 19; iVar7 = 11; iVar1 = 25; iVar8 = 0; break; case 76: StringCopy(&Var2, "PROPS_P1_H19_12", 16); iVar6 = 19; iVar7 = 12; iVar1 = 28; iVar8 = 0; break; case 77: StringCopy(&Var2, "PROPS_P1_H19_13", 16); iVar6 = 19; iVar7 = 13; iVar1 = 28; iVar8 = 0; break; case 78: StringCopy(&Var2, "PROPS_P1_H19_14", 16); iVar6 = 19; iVar7 = 14; iVar1 = 30; iVar8 = 0; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "PROPS_P1_H19_15", 16); iVar6 = 19; iVar7 = 15; iVar1 = 35; iVar8 = 0; break; case 80: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 20; iVar7 = 0; iVar8 = 0; break; case 81: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 21; iVar7 = 0; iVar8 = 0; break; default: func_163(iVar10, iParam0, 175, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_182(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 13; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; default: func_163(iVar10, iParam0, 9, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_183(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 12; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "OUTFIT_P1_0", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 1: StringCopy(&Var2, "OUTFIT_P1_2", 16); iVar6 = 0; iVar7 = 0; break; case 2: StringCopy(&Var2, "OUTFIT_P1_4", 16); iVar6 = 0; iVar7 = 0; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 4: StringCopy(&Var2, "OUTFIT_P1_7", 16); iVar6 = 0; iVar7 = 0; break; case 5: StringCopy(&Var2, "OUTFIT_P1_10", 16); iVar6 = 0; iVar7 = 0; break; case 6: StringCopy(&Var2, "OUTFIT_P1_11", 16); iVar6 = 0; iVar7 = 0; break; case 7: StringCopy(&Var2, "OUTFIT_P1_12", 16); iVar6 = 0; iVar7 = 0; break; case 8: StringCopy(&Var2, "OUTFIT_P1_13", 16); iVar6 = 0; iVar7 = 0; break; case 9: StringCopy(&Var2, "OUTFIT_P1_15", 16); iVar6 = 0; iVar7 = 0; break; case 10: StringCopy(&Var2, "OUTFIT_P1_16", 16); iVar6 = 0; iVar7 = 0; break; case 11: StringCopy(&Var2, "OUTFIT_P1_17", 16); iVar6 = 0; iVar7 = 0; iVar1 = 10000; break; case 12: StringCopy(&Var2, "OUTFIT_P1_18", 16); iVar6 = 0; iVar7 = 0; break; case 13: StringCopy(&Var2, "OUTFIT_P1_19", 16); iVar6 = 0; iVar7 = 0; iVar1 = 105; break; case 14: StringCopy(&Var2, "OUTFIT_P1_20", 16); iVar6 = 0; iVar7 = 0; iVar1 = 105; break; case 15: StringCopy(&Var2, "OUTFIT_P1_21", 16); iVar6 = 0; iVar7 = 0; iVar1 = 105; break; case 16: StringCopy(&Var2, "OUTFIT_P1_22", 16); iVar6 = 0; iVar7 = 0; break; case 17: StringCopy(&Var2, "OUTFIT_P1_23", 16); iVar6 = 0; iVar7 = 0; break; case 18: StringCopy(&Var2, "OUTFIT_P1_24", 16); iVar6 = 0; iVar7 = 0; break; case 19: StringCopy(&Var2, "OUTFIT_P1_25", 16); iVar6 = 0; iVar7 = 0; break; case 20: StringCopy(&Var2, "OUTFIT_P1_26", 16); iVar6 = 0; iVar7 = 0; break; case 21: StringCopy(&Var2, "OUTFIT_P1_27", 16); iVar6 = 0; iVar7 = 0; break; case 22: StringCopy(&Var2, "OUTFIT_P1_28", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4000; break; case 23: StringCopy(&Var2, "OUTFIT_P1_29", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4500; break; case 24: StringCopy(&Var2, "OUTFIT_P1_30", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4500; break; case 25: StringCopy(&Var2, "OUTFIT_P1_31", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4650; break; case 26: StringCopy(&Var2, "OUTFIT_P1_32", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4900; break; case 27: StringCopy(&Var2, "OUTFIT_P1_33", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5000; break; case 28: StringCopy(&Var2, "OUTFIT_P1_34", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4750; break; case 29: StringCopy(&Var2, "OUTFIT_P1_35", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4750; break; case 30: StringCopy(&Var2, "OUTFIT_P1_36", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5200; break; case 31: StringCopy(&Var2, "OUTFIT_P1_37", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5200; break; case 32: StringCopy(&Var2, "OUTFIT_P1_38", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5500; break; case 33: StringCopy(&Var2, "OUTFIT_P1_39", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5900; break; case 34: StringCopy(&Var2, "OUTFIT_P1_40", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5900; break; case 35: StringCopy(&Var2, "OUTFIT_P1_41", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5900; break; case 36: StringCopy(&Var2, "OUTFIT_P1_42", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5900; break; case 37: StringCopy(&Var2, "OUTFIT_P1_43", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5900; break; case 38: StringCopy(&Var2, "OUTFIT_P1_47", 16); iVar6 = 0; iVar7 = 0; iVar1 = 3000; break; case 39: StringCopy(&Var2, "OUTFIT_P1_48", 16); iVar6 = 0; iVar7 = 0; iVar1 = 3000; break; case 40: StringCopy(&Var2, "OUTFIT_P1_49", 16); iVar6 = 0; iVar7 = 0; iVar1 = 3000; break; case 41: StringCopy(&Var2, "OUTFIT_P1_10", 16); iVar6 = 0; iVar7 = 0; break; case 42: StringCopy(&Var2, "OUTFIT_P1_50", 16); iVar6 = 0; iVar7 = 0; break; case 43: StringCopy(&Var2, "OUTFIT_P1_51", 16); iVar6 = 0; iVar7 = 0; break; case 44: StringCopy(&Var2, "OUTFIT_P1_52", 16); iVar6 = 0; iVar7 = 0; break; case 45: StringCopy(&Var2, "OUTFIT_P1_53", 16); iVar6 = 0; iVar7 = 0; break; case 46: StringCopy(&Var2, "OUTFIT_P1_54", 16); iVar6 = 0; iVar7 = 0; break; default: func_163(iVar10, iParam0, 47, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_184(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 11; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 1; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 2; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 3; break; case 5: StringCopy(&Var2, "JBIB_P1_1_0", 16); iVar6 = 2; iVar7 = 0; break; case 6: StringCopy(&Var2, "JBIB_P1_1_1", 16); iVar6 = 2; iVar7 = 1; break; case 7: StringCopy(&Var2, "JBIB_P1_1_2", 16); iVar6 = 2; iVar7 = 2; break; case 8: StringCopy(&Var2, "JBIB_P1_1_3", 16); iVar6 = 2; iVar7 = 3; break; case 9: StringCopy(&Var2, "JBIB_P1_3_0", 16); iVar6 = 3; iVar7 = 0; break; case 10: StringCopy(&Var2, "JBIB_P1_3_1", 16); iVar6 = 3; iVar7 = 1; break; case 11: StringCopy(&Var2, "JBIB_P1_3_2", 16); iVar6 = 3; iVar7 = 2; break; case 12: StringCopy(&Var2, "JBIB_P1_3_3", 16); iVar6 = 3; iVar7 = 3; break; case 13: StringCopy(&Var2, "JBIB_P1_3_4", 16); iVar6 = 3; iVar7 = 4; break; case 14: StringCopy(&Var2, "JBIB_P1_3_5", 16); iVar6 = 3; iVar7 = 5; break; case 15: StringCopy(&Var2, "JBIB_P1_3_6", 16); iVar6 = 3; iVar7 = 6; break; case 16: StringCopy(&Var2, "JBIB_P1_3_7", 16); iVar6 = 3; iVar7 = 7; break; case 17: StringCopy(&Var2, "JBIB_P1_3_8", 16); iVar6 = 3; iVar7 = 8; break; case 18: StringCopy(&Var2, "JBIB_P1_3_9", 16); iVar6 = 3; iVar7 = 9; break; case 19: StringCopy(&Var2, "JBIB_P1_3_10", 16); iVar6 = 3; iVar7 = 10; break; case 20: StringCopy(&Var2, "JBIB_P1_3_11", 16); iVar6 = 3; iVar7 = 11; break; case 21: StringCopy(&Var2, "JBIB_P1_3_12", 16); iVar6 = 3; iVar7 = 12; break; case 22: StringCopy(&Var2, "JBIB_P1_3_13", 16); iVar6 = 3; iVar7 = 13; break; case 23: StringCopy(&Var2, "JBIB_P1_3_14", 16); iVar6 = 3; iVar7 = 14; break; case 24: StringCopy(&Var2, "JBIB_P1_3_15", 16); iVar6 = 3; iVar7 = 15; break; case 25: StringCopy(&Var2, "JBIB_P1_3_0", 16); iVar6 = 4; iVar7 = 0; break; case 26: StringCopy(&Var2, "JBIB_P1_3_1", 16); iVar6 = 4; iVar7 = 1; break; case 27: StringCopy(&Var2, "JBIB_P1_3_2", 16); iVar6 = 4; iVar7 = 2; break; case 28: StringCopy(&Var2, "JBIB_P1_3_3", 16); iVar6 = 4; iVar7 = 3; break; case 29: StringCopy(&Var2, "JBIB_P1_3_4", 16); iVar6 = 4; iVar7 = 4; break; case 30: StringCopy(&Var2, "JBIB_P1_3_5", 16); iVar6 = 4; iVar7 = 5; break; case 31: StringCopy(&Var2, "JBIB_P1_3_6", 16); iVar6 = 4; iVar7 = 6; break; case 32: StringCopy(&Var2, "JBIB_P1_3_7", 16); iVar6 = 4; iVar7 = 7; break; case 33: StringCopy(&Var2, "JBIB_P1_3_8", 16); iVar6 = 4; iVar7 = 8; break; case 34: StringCopy(&Var2, "JBIB_P1_3_9", 16); iVar6 = 4; iVar7 = 9; break; case 35: StringCopy(&Var2, "JBIB_P1_3_10", 16); iVar6 = 4; iVar7 = 10; break; case 36: StringCopy(&Var2, "JBIB_P1_3_11", 16); iVar6 = 4; iVar7 = 11; break; case 37: StringCopy(&Var2, "JBIB_P1_3_12", 16); iVar6 = 4; iVar7 = 12; break; case 38: StringCopy(&Var2, "JBIB_P1_3_13", 16); iVar6 = 4; iVar7 = 13; break; case 39: StringCopy(&Var2, "JBIB_P1_3_14", 16); iVar6 = 4; iVar7 = 14; break; case 40: StringCopy(&Var2, "JBIB_P1_3_15", 16); iVar6 = 4; iVar7 = 15; break; case 41: StringCopy(&Var2, "JBIB_P1_5_0", 16); iVar6 = 5; iVar7 = 0; break; case 42: StringCopy(&Var2, "JBIB_P1_6_0", 16); iVar6 = 6; iVar7 = 0; break; case 43: StringCopy(&Var2, "JBIB_P1_6_1", 16); iVar6 = 6; iVar7 = 1; break; case 44: StringCopy(&Var2, "JBIB_P1_7_0", 16); iVar6 = 7; iVar7 = 0; break; case 45: StringCopy(&Var2, "JBIB_P1_8_0", 16); iVar6 = 8; iVar7 = 0; break; case 46: StringCopy(&Var2, "JBIB_P1_9_0", 16); iVar6 = 9; iVar7 = 0; break; case 47: StringCopy(&Var2, "JBIB_P1_10_0", 16); iVar6 = 10; iVar7 = 0; break; case 48: StringCopy(&Var2, "JBIB_P1_10_1", 16); iVar6 = 10; iVar7 = 1; iVar1 = 48; break; case 49: StringCopy(&Var2, "JBIB_P1_10_2", 16); iVar6 = 10; iVar7 = 2; iVar1 = 35; break; case 50: StringCopy(&Var2, "JBIB_P1_10_3", 16); iVar6 = 10; iVar7 = 3; iVar1 = 32; break; case 51: StringCopy(&Var2, "JBIB_P1_10_4", 16); iVar6 = 10; iVar7 = 4; iVar1 = 35; break; case 52: StringCopy(&Var2, "JBIB_P1_10_5", 16); iVar6 = 10; iVar7 = 5; iVar1 = 48; break; case 53: StringCopy(&Var2, "JBIB_P1_10_6", 16); iVar6 = 10; iVar7 = 6; iVar1 = 52; break; case 54: StringCopy(&Var2, "JBIB_P1_10_7", 16); iVar6 = 10; iVar7 = 7; iVar1 = 38; break; case 55: StringCopy(&Var2, "JBIB_P1_10_8", 16); iVar6 = 10; iVar7 = 8; iVar1 = 42; break; case 56: StringCopy(&Var2, "JBIB_P1_10_9", 16); iVar6 = 10; iVar7 = 9; iVar1 = 38; break; case 57: StringCopy(&Var2, "JBIB_P1_10_10", 16); iVar6 = 10; iVar7 = 10; iVar1 = 35; break; case 58: StringCopy(&Var2, "JBIB_P1_10_11", 16); iVar6 = 10; iVar7 = 11; iVar1 = 48; break; case 59: StringCopy(&Var2, "JBIB_P1_10_12", 16); iVar6 = 10; iVar7 = 12; iVar1 = 42; break; case 60: StringCopy(&Var2, "JBIB_P1_10_13", 16); iVar6 = 10; iVar7 = 13; iVar1 = 45; break; case 61: StringCopy(&Var2, "JBIB_P1_10_14", 16); iVar6 = 10; iVar7 = 14; iVar1 = 45; break; case 62: StringCopy(&Var2, "JBIB_P1_10_15", 16); iVar6 = 10; iVar7 = 15; iVar1 = 49; break; default: func_163(iVar10, iParam0, 63, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_185(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 7; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; default: func_163(iVar10, iParam0, 1, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_186(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 1; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "BERD_P1_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "BERD_P1_1_0", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "BERD_P1_2_0", 16); iVar6 = 2; iVar7 = 0; break; case 3: StringCopy(&Var2, "BERD_P1_3_0", 16); iVar6 = 3; iVar7 = 0; break; case 4: StringCopy(&Var2, "BERD_P1_4_0", 16); iVar6 = 4; iVar7 = 0; break; default: func_163(iVar10, iParam0, 5, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_187(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 10; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 1; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 2; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 3; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 4; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 5; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 1; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 2; break; case 12: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 3; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 4; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 5; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 6; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 1; break; case 18: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 2; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 3; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 4; break; case 21: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 5; break; case 22: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 6; break; case 23: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 7; break; case 24: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 8; break; case 25: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 9; break; case 26: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 10; break; case 27: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 11; break; case 28: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 12; break; case 29: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 13; break; case 30: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 14; break; case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 15; break; case 32: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; break; case 33: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 1; break; case 34: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 2; break; case 35: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 3; break; case 36: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 4; break; case 37: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 5; break; case 38: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 6; break; case 39: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; break; case 40: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 1; break; case 41: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 2; break; case 42: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 3; break; case 43: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 4; break; case 44: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 5; break; case 45: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 6; break; case 46: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 7; break; case 47: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; break; case 48: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 1; break; case 49: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 2; break; case 50: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 3; break; case 51: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; break; case 52: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; break; default: func_163(iVar10, iParam0, 53, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_188(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 9; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "SPEC2_P0_08_0", 16); iVar6 = 5; iVar7 = 0; iVar1 = 125; break; case 6: StringCopy(&Var2, "SPEC2_P0_08_1", 16); iVar6 = 5; iVar7 = 1; iVar1 = 150; break; case 7: StringCopy(&Var2, "SPEC2_P0_08_2", 16); iVar6 = 5; iVar7 = 2; iVar1 = 175; break; case 8: StringCopy(&Var2, "SPEC2_P0_08_3", 16); iVar6 = 5; iVar7 = 3; iVar1 = 85; break; case 9: StringCopy(&Var2, "SPEC2_P0_08_4", 16); iVar6 = 5; iVar7 = 4; iVar1 = 150; break; case 10: StringCopy(&Var2, "SPEC2_P0_08_5", 16); iVar6 = 5; iVar7 = 5; iVar1 = 175; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; break; default: func_163(iVar10, iParam0, 12, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_189(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 8; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; break; case 9: StringCopy(&Var2, "SPEC_P1_9_0", 16); iVar6 = 9; iVar7 = 0; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 11: StringCopy(&Var2, "SPEC_P1_11_0", 16); iVar6 = 11; iVar7 = 0; iVar1 = 195; break; case 12: StringCopy(&Var2, "SPEC_P1_11_1", 16); iVar6 = 11; iVar7 = 1; iVar1 = 195; break; case 13: StringCopy(&Var2, "SPEC_P1_11_2", 16); iVar6 = 11; iVar7 = 2; iVar1 = 195; break; case 14: StringCopy(&Var2, "SPEC_P1_11_3", 16); iVar6 = 11; iVar7 = 3; iVar1 = 250; break; case 15: StringCopy(&Var2, "SPEC_P1_11_4", 16); iVar6 = 11; iVar7 = 4; iVar1 = 250; break; case 16: StringCopy(&Var2, "SPEC_P1_11_5", 16); iVar6 = 11; iVar7 = 5; iVar1 = 250; break; case 17: StringCopy(&Var2, "SPEC_P1_11_6", 16); iVar6 = 11; iVar7 = 6; iVar1 = 195; break; case 18: StringCopy(&Var2, "SPEC_P1_11_7", 16); iVar6 = 11; iVar7 = 7; iVar1 = 250; break; case 19: StringCopy(&Var2, "SPEC_P1_11_8", 16); iVar6 = 11; iVar7 = 8; iVar1 = 250; break; case 20: StringCopy(&Var2, "SPEC_P1_11_9", 16); iVar6 = 11; iVar7 = 9; iVar1 = 250; break; case 21: StringCopy(&Var2, "SPEC_P1_11_10", 16); iVar6 = 11; iVar7 = 10; iVar1 = 250; break; case 22: StringCopy(&Var2, "SPEC_P1_11_11", 16); iVar6 = 11; iVar7 = 11; iVar1 = 195; break; case 23: StringCopy(&Var2, "SPEC_P1_11_12", 16); iVar6 = 11; iVar7 = 12; iVar1 = 250; break; case 24: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; bVar0 = true; break; case 25: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 13; iVar7 = 0; bVar0 = true; break; case 26: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 14; iVar7 = 0; break; case 27: StringCopy(&Var2, "SPEC_P1_15_0", 16); iVar6 = 15; iVar7 = 0; break; case 28: StringCopy(&Var2, "SPEC_P1_15_1", 16); iVar6 = 15; iVar7 = 1; break; case 29: StringCopy(&Var2, "SPEC_P1_15_2", 16); iVar6 = 15; iVar7 = 2; break; case 30: StringCopy(&Var2, "SPEC_P1_15_3", 16); iVar6 = 15; iVar7 = 3; break; case 31: StringCopy(&Var2, "SPEC_P1_15_4", 16); iVar6 = 15; iVar7 = 4; break; case 32: StringCopy(&Var2, "SPEC_P1_15_5", 16); iVar6 = 15; iVar7 = 5; break; case 33: StringCopy(&Var2, "SPEC_P1_15_6", 16); iVar6 = 15; iVar7 = 6; break; case 34: StringCopy(&Var2, "SPEC_P1_15_7", 16); iVar6 = 15; iVar7 = 7; break; case 35: StringCopy(&Var2, "SPEC_P1_15_8", 16); iVar6 = 15; iVar7 = 8; break; case 36: StringCopy(&Var2, "SPEC_P1_15_9", 16); iVar6 = 15; iVar7 = 9; break; case 37: StringCopy(&Var2, "SPEC_P1_15_10", 16); iVar6 = 15; iVar7 = 10; break; case 38: StringCopy(&Var2, "SPEC_P1_15_11", 16); iVar6 = 15; iVar7 = 11; break; case 39: StringCopy(&Var2, "SPEC_P1_15_12", 16); iVar6 = 15; iVar7 = 12; break; case 40: StringCopy(&Var2, "SPEC_P1_15_13", 16); iVar6 = 15; iVar7 = 13; break; case 41: StringCopy(&Var2, "SPEC_P1_15_14", 16); iVar6 = 15; iVar7 = 14; break; case 42: StringCopy(&Var2, "SPEC_P1_15_15", 16); iVar6 = 15; iVar7 = 15; break; case 43: StringCopy(&Var2, "SPEC_P1_15_0", 16); iVar6 = 16; iVar7 = 0; break; case 44: StringCopy(&Var2, "SPEC_P1_15_1", 16); iVar6 = 16; iVar7 = 1; break; case 45: StringCopy(&Var2, "SPEC_P1_15_2", 16); iVar6 = 16; iVar7 = 2; break; case 46: StringCopy(&Var2, "SPEC_P1_15_3", 16); iVar6 = 16; iVar7 = 3; break; case 47: StringCopy(&Var2, "SPEC_P1_15_4", 16); iVar6 = 16; iVar7 = 4; break; case 48: StringCopy(&Var2, "SPEC_P1_15_5", 16); iVar6 = 16; iVar7 = 5; break; case 49: StringCopy(&Var2, "SPEC_P1_15_6", 16); iVar6 = 16; iVar7 = 6; break; case 50: StringCopy(&Var2, "SPEC_P1_15_7", 16); iVar6 = 16; iVar7 = 7; break; case 51: StringCopy(&Var2, "SPEC_P1_15_8", 16); iVar6 = 16; iVar7 = 8; break; case 52: StringCopy(&Var2, "SPEC_P1_15_9", 16); iVar6 = 16; iVar7 = 9; break; case 53: StringCopy(&Var2, "SPEC_P1_15_10", 16); iVar6 = 16; iVar7 = 10; break; case 54: StringCopy(&Var2, "SPEC_P1_15_11", 16); iVar6 = 16; iVar7 = 11; break; case 55: StringCopy(&Var2, "SPEC_P1_15_12", 16); iVar6 = 16; iVar7 = 12; break; case 56: StringCopy(&Var2, "SPEC_P1_15_13", 16); iVar6 = 16; iVar7 = 13; break; case 57: StringCopy(&Var2, "SPEC_P1_15_14", 16); iVar6 = 16; iVar7 = 14; break; case 58: StringCopy(&Var2, "SPEC_P1_15_15", 16); iVar6 = 16; iVar7 = 15; break; case 59: StringCopy(&Var2, "SPEC_P1_15_0", 16); iVar6 = 17; iVar7 = 0; break; case 60: StringCopy(&Var2, "SPEC_P1_15_1", 16); iVar6 = 17; iVar7 = 1; break; case 61: StringCopy(&Var2, "SPEC_P1_15_2", 16); iVar6 = 17; iVar7 = 2; break; case 62: StringCopy(&Var2, "SPEC_P1_15_3", 16); iVar6 = 17; iVar7 = 3; break; case 63: StringCopy(&Var2, "SPEC_P1_15_4", 16); iVar6 = 17; iVar7 = 4; break; case 64: StringCopy(&Var2, "SPEC_P1_15_5", 16); iVar6 = 17; iVar7 = 5; break; case 65: StringCopy(&Var2, "SPEC_P1_15_6", 16); iVar6 = 17; iVar7 = 6; break; case 66: StringCopy(&Var2, "SPEC_P1_15_7", 16); iVar6 = 17; iVar7 = 7; break; case 67: StringCopy(&Var2, "SPEC_P1_15_8", 16); iVar6 = 17; iVar7 = 8; break; case 68: StringCopy(&Var2, "SPEC_P1_15_9", 16); iVar6 = 17; iVar7 = 9; break; case 69: StringCopy(&Var2, "SPEC_P1_15_10", 16); iVar6 = 17; iVar7 = 10; break; case 70: StringCopy(&Var2, "SPEC_P1_15_11", 16); iVar6 = 17; iVar7 = 11; break; case 71: StringCopy(&Var2, "SPEC_P1_15_12", 16); iVar6 = 17; iVar7 = 12; break; case 72: StringCopy(&Var2, "SPEC_P1_15_13", 16); iVar6 = 17; iVar7 = 13; break; case 73: StringCopy(&Var2, "SPEC_P1_15_14", 16); iVar6 = 17; iVar7 = 14; break; case 74: StringCopy(&Var2, "SPEC_P1_15_15", 16); iVar6 = 17; iVar7 = 15; break; case 75: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 18; iVar7 = 0; break; case 76: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 19; iVar7 = 0; break; default: func_163(iVar10, iParam0, 77, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_190(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 5; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 1; bVar0 = true; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; default: func_163(iVar10, iParam0, 7, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_191(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 6; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "FEET_P1_00_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "FEET_P1_00_1", 16); iVar6 = 0; iVar7 = 1; iVar1 = 80; break; case 2: StringCopy(&Var2, "FEET_P1_00_2", 16); iVar6 = 0; iVar7 = 2; iVar1 = 80; break; case 3: StringCopy(&Var2, "FEET_P1_00_3", 16); iVar6 = 0; iVar7 = 3; iVar1 = 89; break; case 4: StringCopy(&Var2, "FEET_P1_00_4", 16); iVar6 = 0; iVar7 = 4; iVar1 = 45; break; case 5: StringCopy(&Var2, "FEET_P1_00_5", 16); iVar6 = 0; iVar7 = 5; iVar1 = 35; break; case 6: StringCopy(&Var2, "FEET_P1_00_6", 16); iVar6 = 0; iVar7 = 6; iVar1 = 89; break; case 7: StringCopy(&Var2, "FEET_P1_00_7", 16); iVar6 = 0; iVar7 = 7; iVar1 = 95; break; case 8: StringCopy(&Var2, "FEET_P1_00_8", 16); iVar6 = 0; iVar7 = 8; iVar1 = 115; break; case 9: StringCopy(&Var2, "FEET_P1_00_9", 16); iVar6 = 0; iVar7 = 9; iVar1 = 40; break; case 10: StringCopy(&Var2, "FEET_P1_00_10", 16); iVar6 = 0; iVar7 = 10; iVar1 = 145; break; case 11: StringCopy(&Var2, "FEET_P1_00_11", 16); iVar6 = 0; iVar7 = 11; iVar1 = 145; break; case 12: StringCopy(&Var2, "FEET_P1_01_0", 16); iVar6 = 1; iVar7 = 0; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 1; bVar0 = true; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; break; case 18: StringCopy(&Var2, "FEET_P1_06_0", 16); iVar6 = 6; iVar7 = 0; break; case 19: StringCopy(&Var2, "FEET_P1_06_1", 16); iVar6 = 6; iVar7 = 1; iVar1 = 180; break; case 20: StringCopy(&Var2, "FEET_P1_06_2", 16); iVar6 = 6; iVar7 = 2; iVar1 = 80; break; case 21: StringCopy(&Var2, "FEET_P1_06_3", 16); iVar6 = 6; iVar7 = 3; iVar1 = 200; break; case 22: StringCopy(&Var2, "FEET_P1_06_4", 16); iVar6 = 6; iVar7 = 4; iVar1 = 220; break; case 23: StringCopy(&Var2, "FEET_P1_06_5", 16); iVar6 = 6; iVar7 = 5; iVar1 = 235; break; case 24: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 25: StringCopy(&Var2, "FEET_P1_08_0", 16); iVar6 = 8; iVar7 = 0; iVar1 = 870; break; case 26: StringCopy(&Var2, "FEET_P1_08_1", 16); iVar6 = 8; iVar7 = 1; iVar1 = 870; break; case 27: StringCopy(&Var2, "FEET_P1_08_2", 16); iVar6 = 8; iVar7 = 2; iVar1 = 870; break; case 28: StringCopy(&Var2, "FEET_P1_08_3", 16); iVar6 = 8; iVar7 = 3; iVar1 = 1275; break; case 29: StringCopy(&Var2, "FEET_P1_08_4", 16); iVar6 = 8; iVar7 = 4; iVar1 = 1275; break; case 30: StringCopy(&Var2, "FEET_P1_08_5", 16); iVar6 = 8; iVar7 = 5; iVar1 = 1275; break; case 31: StringCopy(&Var2, "FEET_P1_08_6", 16); iVar6 = 8; iVar7 = 6; iVar1 = 1275; break; case 32: StringCopy(&Var2, "FEET_P1_08_7", 16); iVar6 = 8; iVar7 = 7; iVar1 = 1275; break; case 33: StringCopy(&Var2, "FEET_P1_08_8", 16); iVar6 = 8; iVar7 = 8; iVar1 = 1275; break; case 34: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 35: StringCopy(&Var2, "FEET_P1_10_0", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 36: StringCopy(&Var2, "FEET_P1_11_0", 16); iVar6 = 11; iVar7 = 0; break; case 37: StringCopy(&Var2, "FEET_P1_11_1", 16); iVar6 = 11; iVar7 = 1; iVar1 = 50; break; case 38: StringCopy(&Var2, "FEET_P1_11_2", 16); iVar6 = 11; iVar7 = 2; iVar1 = 50; break; case 39: StringCopy(&Var2, "FEET_P1_11_3", 16); iVar6 = 11; iVar7 = 3; iVar1 = 50; break; case 40: StringCopy(&Var2, "FEET_P1_11_4", 16); iVar6 = 11; iVar7 = 4; iVar1 = 50; break; case 41: StringCopy(&Var2, "FEET_P1_11_5", 16); iVar6 = 11; iVar7 = 5; iVar1 = 50; break; case 42: StringCopy(&Var2, "FEET_P1_11_6", 16); iVar6 = 11; iVar7 = 6; iVar1 = 50; break; case 43: StringCopy(&Var2, "FEET_P1_11_7", 16); iVar6 = 11; iVar7 = 7; iVar1 = 50; break; case 44: StringCopy(&Var2, "FEET_P1_11_8", 16); iVar6 = 11; iVar7 = 8; iVar1 = 50; break; case 45: StringCopy(&Var2, "FEET_P1_11_9", 16); iVar6 = 11; iVar7 = 9; iVar1 = 50; break; case 46: StringCopy(&Var2, "FEET_P1_11_10", 16); iVar6 = 11; iVar7 = 10; iVar1 = 50; break; case 47: StringCopy(&Var2, "FEET_P1_11_11", 16); iVar6 = 11; iVar7 = 11; iVar1 = 50; break; case 48: StringCopy(&Var2, "FEET_P1_11_12", 16); iVar6 = 11; iVar7 = 12; iVar1 = 50; break; case 49: StringCopy(&Var2, "FEET_P1_11_13", 16); iVar6 = 11; iVar7 = 13; iVar1 = 50; break; case 50: StringCopy(&Var2, "FEET_P1_11_14", 16); iVar6 = 11; iVar7 = 14; iVar1 = 50; break; case 51: StringCopy(&Var2, "FEET_P1_11_15", 16); iVar6 = 11; iVar7 = 15; iVar1 = 50; break; case 52: StringCopy(&Var2, "FEET_P1_12_0", 16); iVar6 = 12; iVar7 = 0; break; case 53: StringCopy(&Var2, "FEET_P1_12_1", 16); iVar6 = 12; iVar7 = 1; iVar1 = 25; break; case 54: StringCopy(&Var2, "FEET_P1_12_2", 16); iVar6 = 12; iVar7 = 2; iVar1 = 20; break; case 55: StringCopy(&Var2, "FEET_P1_12_3", 16); iVar6 = 12; iVar7 = 3; iVar1 = 24; break; case 56: StringCopy(&Var2, "FEET_P1_12_4", 16); iVar6 = 12; iVar7 = 4; iVar1 = 25; break; case 57: StringCopy(&Var2, "FEET_P1_12_5", 16); iVar6 = 12; iVar7 = 5; iVar1 = 27; break; case 58: StringCopy(&Var2, "FEET_P1_12_6", 16); iVar6 = 12; iVar7 = 6; iVar1 = 29; break; case 59: StringCopy(&Var2, "FEET_P1_12_7", 16); iVar6 = 12; iVar7 = 7; iVar1 = 27; break; case 60: StringCopy(&Var2, "FEET_P1_12_8", 16); iVar6 = 12; iVar7 = 8; iVar1 = 25; break; case 61: StringCopy(&Var2, "FEET_P1_12_9", 16); iVar6 = 12; iVar7 = 9; iVar1 = 30; break; case 62: StringCopy(&Var2, "FEET_P1_12_10", 16); iVar6 = 12; iVar7 = 10; iVar1 = 28; break; case 63: StringCopy(&Var2, "FEET_P1_12_11", 16); iVar6 = 12; iVar7 = 11; iVar1 = 30; break; case 64: StringCopy(&Var2, "FEET_P1_13_0", 16); iVar6 = 13; iVar7 = 0; bVar0 = true; break; case 65: StringCopy(&Var2, "FEET_P1_14_0", 16); iVar6 = 14; iVar7 = 0; iVar1 = 155; break; case 66: StringCopy(&Var2, "FEET_P1_14_1", 16); iVar6 = 14; iVar7 = 1; iVar1 = 155; break; case 67: StringCopy(&Var2, "FEET_P1_14_2", 16); iVar6 = 14; iVar7 = 2; iVar1 = 165; break; case 68: StringCopy(&Var2, "FEET_P1_14_3", 16); iVar6 = 14; iVar7 = 3; iVar1 = 170; break; case 69: StringCopy(&Var2, "FEET_P1_14_4", 16); iVar6 = 14; iVar7 = 4; iVar1 = 160; break; case 70: StringCopy(&Var2, "FEET_P1_14_5", 16); iVar6 = 14; iVar7 = 5; iVar1 = 165; break; case 71: StringCopy(&Var2, "FEET_P1_14_6", 16); iVar6 = 14; iVar7 = 6; iVar1 = 170; break; case 72: StringCopy(&Var2, "FEET_P1_14_7", 16); iVar6 = 14; iVar7 = 7; iVar1 = 160; break; case 73: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 15; iVar7 = 0; break; case 74: StringCopy(&Var2, "FEET_P1_16_0", 16); iVar6 = 16; iVar7 = 0; iVar1 = 720; break; case 75: StringCopy(&Var2, "FEET_P1_16_1", 16); iVar6 = 16; iVar7 = 1; iVar1 = 680; break; case 76: StringCopy(&Var2, "FEET_P1_16_2", 16); iVar6 = 16; iVar7 = 2; iVar1 = 650; break; case 77: StringCopy(&Var2, "FEET_P1_16_3", 16); iVar6 = 16; iVar7 = 3; iVar1 = 670; break; case 78: StringCopy(&Var2, "FEET_P1_16_4", 16); iVar6 = 16; iVar7 = 4; iVar1 = 700; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "FEET_P1_16_5", 16); iVar6 = 16; iVar7 = 5; iVar1 = 680; break; case 80: StringCopy(&Var2, "FEET_P1_16_6", 16); iVar6 = 16; iVar7 = 6; iVar1 = 720; break; case 81: StringCopy(&Var2, "FEET_P1_16_7", 16); iVar6 = 16; iVar7 = 7; iVar1 = 740; break; case 82: StringCopy(&Var2, "FEET_P1_16_8", 16); iVar6 = 16; iVar7 = 8; iVar1 = 760; break; case 83: StringCopy(&Var2, "FEET_P1_16_9", 16); iVar6 = 16; iVar7 = 9; iVar1 = 780; break; case 84: StringCopy(&Var2, "FEET_P1_16_10", 16); iVar6 = 16; iVar7 = 10; iVar1 = 750; break; case 85: StringCopy(&Var2, "FEET_P1_16_11", 16); iVar6 = 16; iVar7 = 11; iVar1 = 700; break; case 86: StringCopy(&Var2, "FEET_P1_17_0", 16); iVar6 = 17; iVar7 = 0; iVar1 = 790; break; case 87: StringCopy(&Var2, "FEET_P1_17_1", 16); iVar6 = 17; iVar7 = 1; iVar1 = 750; break; case 88: StringCopy(&Var2, "FEET_P1_17_2", 16); iVar6 = 17; iVar7 = 2; iVar1 = 860; break; case 89: StringCopy(&Var2, "FEET_P1_17_3", 16); iVar6 = 17; iVar7 = 3; iVar1 = 750; break; case 90: StringCopy(&Var2, "FEET_P1_17_4", 16); iVar6 = 17; iVar7 = 4; iVar1 = 790; break; case 91: StringCopy(&Var2, "FEET_P1_17_5", 16); iVar6 = 17; iVar7 = 5; iVar1 = 840; break; case 92: StringCopy(&Var2, "FEET_P1_17_6", 16); iVar6 = 17; iVar7 = 6; iVar1 = 820; break; case 93: StringCopy(&Var2, "FEET_P1_17_7", 16); iVar6 = 17; iVar7 = 7; iVar1 = 800; break; case 94: StringCopy(&Var2, "FEET_P1_17_8", 16); iVar6 = 17; iVar7 = 8; iVar1 = 850; break; case 95: StringCopy(&Var2, "FEET_P1_17_9", 16); iVar6 = 17; iVar7 = 9; iVar1 = 870; break; case 96: StringCopy(&Var2, "FEET_P1_17_10", 16); iVar6 = 17; iVar7 = 10; iVar1 = 720; break; case 97: StringCopy(&Var2, "FEET_P1_17_11", 16); iVar6 = 17; iVar7 = 11; iVar1 = 740; break; case 98: StringCopy(&Var2, "FEET_P1_17_12", 16); iVar6 = 17; iVar7 = 12; iVar1 = 800; break; case 99: StringCopy(&Var2, "FEET_P1_17_13", 16); iVar6 = 17; iVar7 = 13; iVar1 = 750; break; case 100: StringCopy(&Var2, "FEET_P1_17_14", 16); iVar6 = 17; iVar7 = 14; iVar1 = 770; break; case 101: StringCopy(&Var2, "FEET_P1_17_15", 16); iVar6 = 17; iVar7 = 15; iVar1 = 860; break; case 102: StringCopy(&Var2, "FEET_P1_18_0", 16); iVar6 = 18; iVar7 = 0; iVar1 = 850; break; case 103: StringCopy(&Var2, "FEET_P1_18_1", 16); iVar6 = 18; iVar7 = 1; iVar1 = 800; break; case 104: StringCopy(&Var2, "FEET_P1_18_2", 16); iVar6 = 18; iVar7 = 2; iVar1 = 780; break; case 105: StringCopy(&Var2, "FEET_P1_18_3", 16); iVar6 = 18; iVar7 = 3; iVar1 = 890; break; case 106: StringCopy(&Var2, "FEET_P1_18_4", 16); iVar6 = 18; iVar7 = 4; iVar1 = 820; break; case 107: StringCopy(&Var2, "FEET_P1_18_5", 16); iVar6 = 18; iVar7 = 5; iVar1 = 840; break; case 108: StringCopy(&Var2, "FEET_P1_18_6", 16); iVar6 = 18; iVar7 = 6; iVar1 = 870; break; case 109: StringCopy(&Var2, "FEET_P1_18_7", 16); iVar6 = 18; iVar7 = 7; iVar1 = 930; break; case 110: StringCopy(&Var2, "FEET_P1_18_8", 16); iVar6 = 18; iVar7 = 8; iVar1 = 880; break; case 111: StringCopy(&Var2, "FEET_P1_18_9", 16); iVar6 = 18; iVar7 = 9; iVar1 = 900; break; case 112: StringCopy(&Var2, "FEET_P1_18_10", 16); iVar6 = 18; iVar7 = 10; iVar1 = 920; break; case 113: StringCopy(&Var2, "FEET_P1_18_11", 16); iVar6 = 18; iVar7 = 11; iVar1 = 970; break; case 114: StringCopy(&Var2, "FEET_P1_18_12", 16); iVar6 = 18; iVar7 = 12; iVar1 = 990; break; case 115: StringCopy(&Var2, "FEET_P1_18_13", 16); iVar6 = 18; iVar7 = 13; iVar1 = 960; break; case 116: StringCopy(&Var2, "FEET_P1_18_14", 16); iVar6 = 18; iVar7 = 14; iVar1 = 980; break; case 117: StringCopy(&Var2, "FEET_P1_18_15", 16); iVar6 = 18; iVar7 = 15; iVar1 = 950; break; case 118: StringCopy(&Var2, "FEET_P1_19_0", 16); iVar6 = 19; iVar7 = 0; iVar1 = 110; break; case 119: StringCopy(&Var2, "FEET_P1_19_1", 16); iVar6 = 19; iVar7 = 1; iVar1 = 115; break; case 120: StringCopy(&Var2, "FEET_P1_19_2", 16); iVar6 = 19; iVar7 = 2; iVar1 = 120; break; case 121: StringCopy(&Var2, "FEET_P1_19_3", 16); iVar6 = 19; iVar7 = 3; iVar1 = 110; break; case 122: StringCopy(&Var2, "FEET_P1_19_4", 16); iVar6 = 19; iVar7 = 4; iVar1 = 125; break; case 123: StringCopy(&Var2, "FEET_P1_19_5", 16); iVar6 = 19; iVar7 = 5; iVar1 = 128; break; case 124: StringCopy(&Var2, "FEET_P1_19_6", 16); iVar6 = 19; iVar7 = 6; iVar1 = 135; break; case 125: StringCopy(&Var2, "FEET_P1_19_7", 16); iVar6 = 19; iVar7 = 7; iVar1 = 130; break; case 126: StringCopy(&Var2, "FEET_P1_19_8", 16); iVar6 = 19; iVar7 = 8; iVar1 = 145; break; case 127: StringCopy(&Var2, "FEET_P1_19_9", 16); iVar6 = 19; iVar7 = 9; iVar1 = 110; break; case 128: StringCopy(&Var2, "FEET_P1_19_10", 16); iVar6 = 19; iVar7 = 10; iVar1 = 120; break; case 129: StringCopy(&Var2, "FEET_P1_19_11", 16); iVar6 = 19; iVar7 = 11; iVar1 = 150; break; case 130: StringCopy(&Var2, "FEET_P1_19_12", 16); iVar6 = 19; iVar7 = 12; iVar1 = 125; break; case 131: StringCopy(&Var2, "FEET_P1_19_13", 16); iVar6 = 19; iVar7 = 13; iVar1 = 120; break; case 132: StringCopy(&Var2, "FEET_P1_19_14", 16); iVar6 = 19; iVar7 = 14; iVar1 = 130; break; case 133: StringCopy(&Var2, "FEET_P1_19_15", 16); iVar6 = 19; iVar7 = 15; iVar1 = 110; break; default: func_163(iVar10, iParam0, 134, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_192(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 4; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "LEGS_P1_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "LEGS_P1_0_1", 16); iVar6 = 0; iVar7 = 1; iVar1 = 32; break; case 2: StringCopy(&Var2, "LEGS_P1_0_2", 16); iVar6 = 0; iVar7 = 2; iVar1 = 38; break; case 3: StringCopy(&Var2, "LEGS_P1_0_3", 16); iVar6 = 0; iVar7 = 3; iVar1 = 44; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 1; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 2; bVar0 = true; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 3; bVar0 = true; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 4; bVar0 = true; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 5; bVar0 = true; break; case 10: StringCopy(&Var2, "LEGS_P1_2_0", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 12: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 14: StringCopy(&Var2, "LEGS_P1_6_0", 16); iVar6 = 6; iVar7 = 0; break; case 15: StringCopy(&Var2, "LEGS_P1_6_1", 16); iVar6 = 6; iVar7 = 1; iVar1 = 690; break; case 16: StringCopy(&Var2, "LEGS_P1_6_2", 16); iVar6 = 6; iVar7 = 2; iVar1 = 720; break; case 17: StringCopy(&Var2, "LEGS_P1_6_3", 16); iVar6 = 6; iVar7 = 3; iVar1 = 850; break; case 18: StringCopy(&Var2, "LEGS_P1_6_4", 16); iVar6 = 6; iVar7 = 4; iVar1 = 850; break; case 19: StringCopy(&Var2, "LEGS_P1_6_5", 16); iVar6 = 6; iVar7 = 5; iVar1 = 740; break; case 20: StringCopy(&Var2, "LEGS_P1_6_6", 16); iVar6 = 6; iVar7 = 6; iVar1 = 750; break; case 21: StringCopy(&Var2, "LEGS_P1_6_7", 16); iVar6 = 6; iVar7 = 7; iVar1 = 790; break; case 22: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 23: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 1; bVar0 = true; break; case 24: StringCopy(&Var2, "LEGS_P1_8_0", 16); iVar6 = 8; iVar7 = 0; break; case 25: StringCopy(&Var2, "LEGS_P1_8_1", 16); iVar6 = 8; iVar7 = 1; iVar1 = 145; break; case 26: StringCopy(&Var2, "LEGS_P1_8_2", 16); iVar6 = 8; iVar7 = 2; iVar1 = 140; break; case 27: StringCopy(&Var2, "LEGS_P1_8_3", 16); iVar6 = 8; iVar7 = 3; iVar1 = 148; break; case 28: StringCopy(&Var2, "LEGS_P1_8_4", 16); iVar6 = 8; iVar7 = 4; iVar1 = 150; break; case 29: StringCopy(&Var2, "LEGS_P1_8_5", 16); iVar6 = 8; iVar7 = 5; iVar1 = 154; break; case 30: StringCopy(&Var2, "LEGS_P1_8_6", 16); iVar6 = 8; iVar7 = 6; iVar1 = 158; break; case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 32: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 33: StringCopy(&Var2, "LEGS_P1_11_0", 16); iVar6 = 11; iVar7 = 0; iVar1 = 820; break; case 34: StringCopy(&Var2, "LEGS_P1_11_1", 16); iVar6 = 11; iVar7 = 1; iVar1 = 820; break; case 35: StringCopy(&Var2, "LEGS_P1_11_2", 16); iVar6 = 11; iVar7 = 2; iVar1 = 850; break; case 36: StringCopy(&Var2, "LEGS_P1_11_3", 16); iVar6 = 11; iVar7 = 3; iVar1 = 850; break; case 37: StringCopy(&Var2, "LEGS_P1_11_4", 16); iVar6 = 11; iVar7 = 4; iVar1 = 920; break; case 38: StringCopy(&Var2, "LEGS_P1_11_5", 16); iVar6 = 11; iVar7 = 5; iVar1 = 950; break; case 39: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; break; case 40: StringCopy(&Var2, "LEGS_P1_13_0", 16); iVar6 = 13; iVar7 = 0; break; case 41: StringCopy(&Var2, "LEGS_P1_13_1", 16); iVar6 = 13; iVar7 = 1; iVar1 = 45; break; case 42: StringCopy(&Var2, "LEGS_P1_13_2", 16); iVar6 = 13; iVar7 = 2; iVar1 = 48; break; case 43: StringCopy(&Var2, "LEGS_P1_13_3", 16); iVar6 = 13; iVar7 = 3; iVar1 = 45; break; case 44: StringCopy(&Var2, "LEGS_P1_13_4", 16); iVar6 = 13; iVar7 = 4; iVar1 = 48; break; case 45: StringCopy(&Var2, "LEGS_P1_13_5", 16); iVar6 = 13; iVar7 = 5; iVar1 = 52; break; case 46: StringCopy(&Var2, "LEGS_P1_13_6", 16); iVar6 = 13; iVar7 = 6; iVar1 = 55; break; case 47: StringCopy(&Var2, "LEGS_P1_13_7", 16); iVar6 = 13; iVar7 = 7; iVar1 = 58; break; case 48: StringCopy(&Var2, "LEGS_P1_13_8", 16); iVar6 = 13; iVar7 = 8; iVar1 = 60; break; case 49: StringCopy(&Var2, "LEGS_P1_13_9", 16); iVar6 = 13; iVar7 = 9; iVar1 = 58; break; case 50: StringCopy(&Var2, "LEGS_P1_13_10", 16); iVar6 = 13; iVar7 = 10; iVar1 = 62; break; case 51: StringCopy(&Var2, "LEGS_P1_13_11", 16); iVar6 = 13; iVar7 = 11; iVar1 = 65; break; case 52: StringCopy(&Var2, "LEGS_P1_14_0", 16); iVar6 = 14; iVar7 = 0; break; case 53: StringCopy(&Var2, "LEGS_P1_15_0", 16); iVar6 = 15; iVar7 = 0; break; case 54: StringCopy(&Var2, "LEGS_P1_15_1", 16); iVar6 = 15; iVar7 = 1; break; case 55: StringCopy(&Var2, "LEGS_P1_15_2", 16); iVar6 = 15; iVar7 = 2; break; case 56: StringCopy(&Var2, "LEGS_P1_15_3", 16); iVar6 = 15; iVar7 = 3; break; case 57: StringCopy(&Var2, "LEGS_P1_15_4", 16); iVar6 = 15; iVar7 = 4; break; case 58: StringCopy(&Var2, "LEGS_P1_15_5", 16); iVar6 = 15; iVar7 = 5; break; case 59: StringCopy(&Var2, "LEGS_P1_15_6", 16); iVar6 = 15; iVar7 = 6; break; case 60: StringCopy(&Var2, "LEGS_P1_15_7", 16); iVar6 = 15; iVar7 = 7; break; case 61: StringCopy(&Var2, "LEGS_P1_15_8", 16); iVar6 = 15; iVar7 = 8; break; case 62: StringCopy(&Var2, "LEGS_P1_15_9", 16); iVar6 = 15; iVar7 = 9; break; case 63: StringCopy(&Var2, "LEGS_P1_15_10", 16); iVar6 = 15; iVar7 = 10; break; case 64: StringCopy(&Var2, "LEGS_P1_15_11", 16); iVar6 = 15; iVar7 = 11; break; case 65: StringCopy(&Var2, "LEGS_P1_15_12", 16); iVar6 = 15; iVar7 = 12; break; case 66: StringCopy(&Var2, "LEGS_P1_15_13", 16); iVar6 = 15; iVar7 = 13; break; case 67: StringCopy(&Var2, "LEGS_P1_15_14", 16); iVar6 = 15; iVar7 = 14; break; case 68: StringCopy(&Var2, "LEGS_P1_15_15", 16); iVar6 = 15; iVar7 = 15; break; case 69: StringCopy(&Var2, "LEGS_P1_16_0", 16); iVar6 = 16; iVar7 = 0; bVar0 = true; break; case 70: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 16; iVar7 = 1; bVar0 = true; break; case 71: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 0; bVar0 = true; break; case 72: StringCopy(&Var2, "LEGS_P1_18_0", 16); iVar6 = 18; iVar7 = 0; break; case 73: StringCopy(&Var2, "LEGS_P1_18_1", 16); iVar6 = 18; iVar7 = 1; iVar1 = 160; break; case 74: StringCopy(&Var2, "LEGS_P1_18_2", 16); iVar6 = 18; iVar7 = 2; iVar1 = 180; break; case 75: StringCopy(&Var2, "LEGS_P1_18_3", 16); iVar6 = 18; iVar7 = 3; iVar1 = 180; break; case 76: StringCopy(&Var2, "LEGS_P1_18_4", 16); iVar6 = 18; iVar7 = 4; break; case 77: StringCopy(&Var2, "LEGS_P1_18_5", 16); iVar6 = 18; iVar7 = 5; break; case 78: StringCopy(&Var2, "LEGS_P1_19_0", 16); iVar6 = 19; iVar7 = 0; bVar0 = true; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "LEGS_P1_20_0", 16); iVar6 = 20; iVar7 = 0; iVar1 = 118; break; case 80: StringCopy(&Var2, "LEGS_P1_20_1", 16); iVar6 = 20; iVar7 = 1; iVar1 = 120; break; case 81: StringCopy(&Var2, "LEGS_P1_20_2", 16); iVar6 = 20; iVar7 = 2; iVar1 = 128; break; case 82: StringCopy(&Var2, "LEGS_P1_20_3", 16); iVar6 = 20; iVar7 = 3; iVar1 = 128; break; case 83: StringCopy(&Var2, "LEGS_P1_20_4", 16); iVar6 = 20; iVar7 = 4; iVar1 = 130; break; case 84: StringCopy(&Var2, "LEGS_P1_20_5", 16); iVar6 = 20; iVar7 = 5; iVar1 = 145; break; case 85: StringCopy(&Var2, "LEGS_P1_20_6", 16); iVar6 = 20; iVar7 = 6; iVar1 = 138; break; case 86: StringCopy(&Var2, "LEGS_P1_20_7", 16); iVar6 = 20; iVar7 = 7; iVar1 = 132; break; case 87: StringCopy(&Var2, "LEGS_P1_20_8", 16); iVar6 = 20; iVar7 = 8; iVar1 = 148; break; case 88: StringCopy(&Var2, "LEGS_P1_21_0", 16); iVar6 = 21; iVar7 = 0; iVar1 = 118; break; case 89: StringCopy(&Var2, "LEGS_P1_21_1", 16); iVar6 = 21; iVar7 = 1; iVar1 = 118; break; case 90: StringCopy(&Var2, "LEGS_P1_21_2", 16); iVar6 = 21; iVar7 = 2; iVar1 = 118; break; case 91: StringCopy(&Var2, "LEGS_P1_21_3", 16); iVar6 = 21; iVar7 = 3; iVar1 = 129; break; case 92: StringCopy(&Var2, "LEGS_P1_21_4", 16); iVar6 = 21; iVar7 = 4; iVar1 = 135; break; case 93: StringCopy(&Var2, "LEGS_P1_21_5", 16); iVar6 = 21; iVar7 = 5; iVar1 = 135; break; case 94: StringCopy(&Var2, "LEGS_P1_21_6", 16); iVar6 = 21; iVar7 = 6; iVar1 = 118; break; case 95: StringCopy(&Var2, "LEGS_P1_21_7", 16); iVar6 = 21; iVar7 = 7; iVar1 = 118; break; case 96: StringCopy(&Var2, "LEGS_P1_21_8", 16); iVar6 = 21; iVar7 = 8; iVar1 = 118; break; case 97: StringCopy(&Var2, "LEGS_P1_22_0", 16); iVar6 = 22; iVar7 = 0; iVar1 = 55; break; case 98: StringCopy(&Var2, "LEGS_P1_22_1", 16); iVar6 = 22; iVar7 = 1; iVar1 = 55; break; case 99: StringCopy(&Var2, "LEGS_P1_22_2", 16); iVar6 = 22; iVar7 = 2; iVar1 = 59; break; case 100: StringCopy(&Var2, "LEGS_P1_22_3", 16); iVar6 = 22; iVar7 = 3; iVar1 = 59; break; case 101: StringCopy(&Var2, "LEGS_P1_22_4", 16); iVar6 = 22; iVar7 = 4; iVar1 = 65; break; case 102: StringCopy(&Var2, "LEGS_P1_22_5", 16); iVar6 = 22; iVar7 = 5; iVar1 = 65; break; case 103: StringCopy(&Var2, "LEGS_P1_22_6", 16); iVar6 = 22; iVar7 = 6; iVar1 = 69; break; case 104: StringCopy(&Var2, "LEGS_P1_22_7", 16); iVar6 = 22; iVar7 = 7; iVar1 = 69; break; case 105: StringCopy(&Var2, "LEGS_P1_22_8", 16); iVar6 = 22; iVar7 = 8; iVar1 = 75; break; case 106: StringCopy(&Var2, "LEGS_P1_22_9", 16); iVar6 = 22; iVar7 = 9; iVar1 = 75; break; case 107: StringCopy(&Var2, "LEGS_P1_22_10", 16); iVar6 = 22; iVar7 = 10; iVar1 = 65; break; case 108: StringCopy(&Var2, "LEGS_P1_22_11", 16); iVar6 = 22; iVar7 = 11; iVar1 = 65; break; case 109: StringCopy(&Var2, "LEGS_P1_22_12", 16); iVar6 = 22; iVar7 = 12; iVar1 = 65; break; case 110: StringCopy(&Var2, "LEGS_P1_22_13", 16); iVar6 = 22; iVar7 = 13; iVar1 = 65; break; case 111: StringCopy(&Var2, "LEGS_P1_23_0", 16); iVar6 = 23; iVar7 = 0; iVar1 = 38; break; case 112: StringCopy(&Var2, "LEGS_P1_23_1", 16); iVar6 = 23; iVar7 = 1; iVar1 = 38; break; case 113: StringCopy(&Var2, "LEGS_P1_23_2", 16); iVar6 = 23; iVar7 = 2; iVar1 = 28; break; case 114: StringCopy(&Var2, "LEGS_P1_23_3", 16); iVar6 = 23; iVar7 = 3; iVar1 = 34; break; case 115: StringCopy(&Var2, "LEGS_P1_23_4", 16); iVar6 = 23; iVar7 = 4; iVar1 = 36; break; case 116: StringCopy(&Var2, "LEGS_P1_23_5", 16); iVar6 = 23; iVar7 = 5; iVar1 = 32; break; default: func_163(iVar10, iParam0, 117, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_193(int iParam0) { if (iParam0 < 107) { func_196(iParam0); } else if (iParam0 < 227) { func_195(iParam0); } else { func_194(iParam0); } if (Global_76647[0 /*14*/].f_2 == -1) { func_163(3, iParam0, 318, -1); } } void func_194(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 3; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 227: StringCopy(&Var2, "TORSO_P1_18_0", 16); iVar6 = 23; iVar7 = 0; iVar9 = 3; break; case 228: StringCopy(&Var2, "TORSO_P1_18_1", 16); iVar6 = 23; iVar7 = 1; iVar9 = 3; break; case 229: StringCopy(&Var2, "TORSO_P1_18_2", 16); iVar6 = 23; iVar7 = 2; iVar9 = 3; break; case 230: StringCopy(&Var2, "TORSO_P1_18_3", 16); iVar6 = 23; iVar7 = 3; iVar9 = 3; break; case 231: StringCopy(&Var2, "TORSO_P1_18_4", 16); iVar6 = 23; iVar7 = 4; iVar9 = 3; break; case 232: StringCopy(&Var2, "TORSO_P1_18_5", 16); iVar6 = 23; iVar7 = 5; iVar9 = 3; break; case 233: StringCopy(&Var2, "TORSO_P1_18_6", 16); iVar6 = 23; iVar7 = 6; iVar9 = 3; break; case 234: StringCopy(&Var2, "TORSO_P1_18_7", 16); iVar6 = 23; iVar7 = 7; iVar9 = 3; break; case 235: StringCopy(&Var2, "TORSO_P1_18_8", 16); iVar6 = 23; iVar7 = 8; iVar9 = 3; break; case 236: StringCopy(&Var2, "TORSO_P1_18_9", 16); iVar6 = 23; iVar7 = 9; iVar9 = 3; break; case 237: StringCopy(&Var2, "TORSO_P1_18_10", 16); iVar6 = 23; iVar7 = 10; iVar9 = 3; break; case 238: StringCopy(&Var2, "TORSO_P1_18_11", 16); iVar6 = 23; iVar7 = 11; iVar9 = 3; break; case 239: StringCopy(&Var2, "TORSO_P1_18_12", 16); iVar6 = 23; iVar7 = 12; iVar9 = 3; break; case 240: StringCopy(&Var2, "TORSO_P1_18_13", 16); iVar6 = 23; iVar7 = 13; iVar9 = 3; break; case 241: StringCopy(&Var2, "TORSO_P1_18_14", 16); iVar6 = 23; iVar7 = 14; iVar9 = 3; break; case 242: StringCopy(&Var2, "TORSO_P1_18_15", 16); iVar6 = 23; iVar7 = 15; iVar9 = 3; break; case 243: StringCopy(&Var2, "TORSO_P1_24_0", 16); iVar6 = 24; iVar7 = 0; iVar1 = 2200; iVar9 = 3; break; case 244: StringCopy(&Var2, "TORSO_P1_24_1", 16); iVar6 = 24; iVar7 = 1; iVar1 = 2200; iVar9 = 3; break; case 245: StringCopy(&Var2, "TORSO_P1_24_2", 16); iVar6 = 24; iVar7 = 2; iVar1 = 2200; iVar9 = 3; break; case 246: StringCopy(&Var2, "TORSO_P1_24_3", 16); iVar6 = 24; iVar7 = 3; iVar1 = 2200; iVar9 = 3; break; case 247: StringCopy(&Var2, "TORSO_P1_24_4", 16); iVar6 = 24; iVar7 = 4; iVar1 = 2200; iVar9 = 3; break; case 248: StringCopy(&Var2, "TORSO_P1_24_5", 16); iVar6 = 24; iVar7 = 5; iVar1 = 2200; iVar9 = 3; break; case 249: StringCopy(&Var2, "TORSO_P1_24_6", 16); iVar6 = 24; iVar7 = 6; iVar1 = 2200; iVar9 = 3; break; case 250: StringCopy(&Var2, "TORSO_P1_24_7", 16); iVar6 = 24; iVar7 = 7; iVar1 = 2200; iVar9 = 3; break; case 251: StringCopy(&Var2, "TORSO_P1_24_8", 16); iVar6 = 24; iVar7 = 8; iVar1 = 2200; iVar9 = 3; break; case 252: StringCopy(&Var2, "TORSO_P1_24_9", 16); iVar6 = 24; iVar7 = 9; iVar1 = 2200; iVar9 = 3; break; case 253: StringCopy(&Var2, "TORSO_P1_24_10", 16); iVar6 = 24; iVar7 = 10; iVar1 = 2200; iVar9 = 3; break; case 254: StringCopy(&Var2, "TORSO_P1_24_11", 16); iVar6 = 24; iVar7 = 11; iVar1 = 2200; iVar9 = 3; break; case 255: StringCopy(&Var2, "TORSO_P1_24_12", 16); iVar6 = 24; iVar7 = 12; iVar1 = 2200; iVar9 = 3; break; case 256: StringCopy(&Var2, "TORSO_P1_24_13", 16); iVar6 = 24; iVar7 = 13; iVar1 = 2200; iVar9 = 3; break; case 257: StringCopy(&Var2, "TORSO_P1_24_14", 16); iVar6 = 24; iVar7 = 14; iVar1 = 2200; iVar9 = 3; break; case 258: StringCopy(&Var2, "TORSO_P1_24_15", 16); iVar6 = 24; iVar7 = 15; iVar1 = 2200; iVar9 = 3; break; case 259: StringCopy(&Var2, "TORSO_P1_25_0", 16); iVar6 = 25; iVar7 = 0; bVar0 = true; iVar9 = 3; break; case 260: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 0; iVar9 = 1; break; case 261: StringCopy(&Var2, "TORSO_P1_27_0", 16); iVar6 = 27; iVar7 = 0; iVar1 = 150; break; case 262: StringCopy(&Var2, "TORSO_P1_27_1", 16); iVar6 = 27; iVar7 = 1; iVar1 = 160; break; case 263: StringCopy(&Var2, "TORSO_P1_27_2", 16); iVar6 = 27; iVar7 = 2; iVar1 = 150; break; case 264: StringCopy(&Var2, "TORSO_P1_27_3", 16); iVar6 = 27; iVar7 = 3; iVar1 = 150; break; case 265: StringCopy(&Var2, "TORSO_P1_27_4", 16); iVar6 = 27; iVar7 = 4; iVar1 = 160; break; case 266: StringCopy(&Var2, "TORSO_P1_27_5", 16); iVar6 = 27; iVar7 = 5; iVar1 = 160; break; case 267: StringCopy(&Var2, "TORSO_P1_28_0", 16); iVar6 = 28; iVar7 = 0; iVar1 = 88; break; case 268: StringCopy(&Var2, "TORSO_P1_28_1", 16); iVar6 = 28; iVar7 = 1; iVar1 = 60; break; case 269: StringCopy(&Var2, "TORSO_P1_28_2", 16); iVar6 = 28; iVar7 = 2; iVar1 = 70; break; case 270: StringCopy(&Var2, "TORSO_P1_28_3", 16); iVar6 = 28; iVar7 = 3; iVar1 = 80; break; case 271: StringCopy(&Var2, "TORSO_P1_28_4", 16); iVar6 = 28; iVar7 = 4; iVar1 = 90; break; case 272: StringCopy(&Var2, "TORSO_P1_28_5", 16); iVar6 = 28; iVar7 = 5; iVar1 = 80; break; case 273: StringCopy(&Var2, "TORSO_P1_28_6", 16); iVar6 = 28; iVar7 = 6; iVar1 = 70; break; case 274: StringCopy(&Var2, "TORSO_P1_28_7", 16); iVar6 = 28; iVar7 = 7; iVar1 = 95; break; case 275: StringCopy(&Var2, "TORSO_P1_28_8", 16); iVar6 = 28; iVar7 = 8; iVar1 = 105; break; case 276: StringCopy(&Var2, "TORSO_P1_28_9", 16); iVar6 = 28; iVar7 = 9; iVar1 = 95; break; case 277: StringCopy(&Var2, "TORSO_P1_28_10", 16); iVar6 = 28; iVar7 = 10; iVar1 = 110; break; case 278: StringCopy(&Var2, "TORSO_P1_28_11", 16); iVar6 = 28; iVar7 = 11; iVar1 = 98; break; case 279: StringCopy(&Var2, "TORSO_P1_28_12", 16); iVar6 = 28; iVar7 = 12; iVar1 = 88; break; case 280: StringCopy(&Var2, "TORSO_P1_28_13", 16); iVar6 = 28; iVar7 = 13; iVar1 = 98; break; case 281: StringCopy(&Var2, "TORSO_P1_28_14", 16); iVar6 = 28; iVar7 = 14; iVar1 = 110; break; case 282: StringCopy(&Var2, "TORSO_P1_28_15", 16); iVar6 = 28; iVar7 = 15; iVar1 = 98; break; case 283: StringCopy(&Var2, "TORSO_P1_29_0", 16); iVar6 = 29; iVar7 = 0; iVar1 = 250; break; case 284: StringCopy(&Var2, "TORSO_P1_29_1", 16); iVar6 = 29; iVar7 = 1; iVar1 = 270; break; case 285: StringCopy(&Var2, "TORSO_P1_29_2", 16); iVar6 = 29; iVar7 = 2; iVar1 = 280; break; case 286: StringCopy(&Var2, "TORSO_P1_29_3", 16); iVar6 = 29; iVar7 = 3; iVar1 = 275; break; case 287: StringCopy(&Var2, "TORSO_P1_29_4", 16); iVar6 = 29; iVar7 = 4; iVar1 = 290; break; case 288: StringCopy(&Var2, "TORSO_P1_29_5", 16); iVar6 = 29; iVar7 = 5; iVar1 = 35; break; case 289: StringCopy(&Var2, "TORSO_P1_29_6", 16); iVar6 = 29; iVar7 = 6; iVar1 = 35; break; case 290: StringCopy(&Var2, "TORSO_P1_29_7", 16); iVar6 = 29; iVar7 = 7; iVar1 = 35; break; case 291: StringCopy(&Var2, "TORSO_P1_29_8", 16); iVar6 = 29; iVar7 = 8; iVar1 = 295; break; case 292: StringCopy(&Var2, "TORSO_P1_29_9", 16); iVar6 = 29; iVar7 = 9; iVar1 = 35; break; case 293: StringCopy(&Var2, "TORSO_P1_29_10", 16); iVar6 = 29; iVar7 = 10; iVar1 = 35; break; case 294: StringCopy(&Var2, "TORSO_P1_29_11", 16); iVar6 = 29; iVar7 = 11; iVar1 = 35; break; case 295: StringCopy(&Var2, "TORSO_P1_29_12", 16); iVar6 = 29; iVar7 = 12; break; case 296: StringCopy(&Var2, "TORSO_P1_30_0", 16); iVar6 = 30; iVar7 = 0; iVar1 = 1750; break; case 297: StringCopy(&Var2, "TORSO_P1_30_1", 16); iVar6 = 30; iVar7 = 1; iVar1 = 1920; break; case 298: StringCopy(&Var2, "TORSO_P1_30_2", 16); iVar6 = 30; iVar7 = 2; iVar1 = 1890; break; case 299: StringCopy(&Var2, "TORSO_P1_30_3", 16); iVar6 = 30; iVar7 = 3; iVar1 = 1850; break; case 300: StringCopy(&Var2, "TORSO_P1_30_4", 16); iVar6 = 30; iVar7 = 4; iVar1 = 1750; break; case 301: StringCopy(&Var2, "TORSO_P1_30_5", 16); iVar6 = 30; iVar7 = 5; iVar1 = 1990; break; case 302: StringCopy(&Var2, "TORSO_P1_30_6", 16); iVar6 = 30; iVar7 = 6; iVar1 = 1820; break; case 303: StringCopy(&Var2, "TORSO_P1_30_7", 16); iVar6 = 30; iVar7 = 7; iVar1 = 1990; break; case 304: StringCopy(&Var2, "TORSO_P1_30_8", 16); iVar6 = 30; iVar7 = 8; iVar1 = 1920; break; case 305: StringCopy(&Var2, "TORSO_P1_30_9", 16); iVar6 = 30; iVar7 = 9; iVar1 = 1850; break; case 306: StringCopy(&Var2, "TORSO_P1_30_10", 16); iVar6 = 30; iVar7 = 10; iVar1 = 1990; break; case 307: StringCopy(&Var2, "TORSO_P1_30_11", 16); iVar6 = 30; iVar7 = 11; iVar1 = 1790; break; case 308: StringCopy(&Var2, "TORSO_P1_30_12", 16); iVar6 = 30; iVar7 = 12; iVar1 = 1790; break; case 309: StringCopy(&Var2, "TORSO_P1_31_0", 16); iVar6 = 31; iVar7 = 0; iVar1 = 69; break; case 310: StringCopy(&Var2, "TORSO_P1_31_1", 16); iVar6 = 31; iVar7 = 1; iVar1 = 75; break; case 311: StringCopy(&Var2, "TORSO_P1_31_2", 16); iVar6 = 31; iVar7 = 2; iVar1 = 75; break; case 312: StringCopy(&Var2, "TORSO_P1_31_3", 16); iVar6 = 31; iVar7 = 3; iVar1 = 79; break; case 313: StringCopy(&Var2, "TORSO_P1_31_4", 16); iVar6 = 31; iVar7 = 4; iVar1 = 79; break; case 314: StringCopy(&Var2, "TORSO_P1_31_5", 16); iVar6 = 31; iVar7 = 5; iVar1 = 89; break; case 315: StringCopy(&Var2, "TORSO_P1_31_6", 16); iVar6 = 31; iVar7 = 6; iVar1 = 85; break; case 316: StringCopy(&Var2, "TORSO_P1_31_7", 16); iVar6 = 31; iVar7 = 7; iVar1 = 85; break; case 317: StringCopy(&Var2, "TORSO_P1_31_8", 16); iVar6 = 31; iVar7 = 8; break; default: return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_195(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 3; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 107: StringCopy(&Var2, "TORSO_P1_12_0", 16); iVar6 = 12; iVar7 = 0; iVar1 = 195; break; case 108: StringCopy(&Var2, "TORSO_P1_12_1", 16); iVar6 = 12; iVar7 = 1; iVar1 = 420; break; case 109: StringCopy(&Var2, "TORSO_P1_12_2", 16); iVar6 = 12; iVar7 = 2; iVar1 = 390; break; case 110: StringCopy(&Var2, "TORSO_P1_12_3", 16); iVar6 = 12; iVar7 = 3; iVar1 = 450; break; case 111: StringCopy(&Var2, "TORSO_P1_12_4", 16); iVar6 = 12; iVar7 = 4; iVar1 = 400; break; case 112: StringCopy(&Var2, "TORSO_P1_12_5", 16); iVar6 = 12; iVar7 = 5; iVar1 = 390; break; case 113: StringCopy(&Var2, "TORSO_P1_12_6", 16); iVar6 = 12; iVar7 = 6; iVar1 = 570; break; case 114: StringCopy(&Var2, "TORSO_P1_12_7", 16); iVar6 = 12; iVar7 = 7; iVar1 = 390; break; case 115: StringCopy(&Var2, "TORSO_P1_12_8", 16); iVar6 = 12; iVar7 = 8; iVar1 = 470; break; case 116: StringCopy(&Var2, "TORSO_P1_12_9", 16); iVar6 = 12; iVar7 = 9; iVar1 = 390; break; case 117: StringCopy(&Var2, "TORSO_P1_12_10", 16); iVar6 = 12; iVar7 = 10; iVar1 = 520; break; case 118: StringCopy(&Var2, "TORSO_P1_12_11", 16); iVar6 = 12; iVar7 = 11; iVar1 = 490; break; case 119: StringCopy(&Var2, "TORSO_P1_12_12", 16); iVar6 = 12; iVar7 = 12; iVar1 = 490; break; case 120: StringCopy(&Var2, "TORSO_P1_12_13", 16); iVar6 = 12; iVar7 = 13; iVar1 = 590; break; case 121: StringCopy(&Var2, "TORSO_P1_12_14", 16); iVar6 = 12; iVar7 = 14; iVar1 = 560; break; case 122: StringCopy(&Var2, "TORSO_P1_12_15", 16); iVar6 = 12; iVar7 = 15; iVar1 = 520; break; case 123: StringCopy(&Var2, "TORSO_P1_13_0", 16); iVar6 = 13; iVar7 = 0; break; case 124: StringCopy(&Var2, "TORSO_P1_13_1", 16); iVar6 = 13; iVar7 = 1; break; case 125: StringCopy(&Var2, "TORSO_P1_13_2", 16); iVar6 = 13; iVar7 = 2; break; case 126: StringCopy(&Var2, "TORSO_P1_13_3", 16); iVar6 = 13; iVar7 = 3; iVar1 = 90; break; case 127: StringCopy(&Var2, "TORSO_P1_13_4", 16); iVar6 = 13; iVar7 = 4; iVar1 = 85; break; case 128: StringCopy(&Var2, "TORSO_P1_13_5", 16); iVar6 = 13; iVar7 = 5; iVar1 = 45; break; case 129: StringCopy(&Var2, "TORSO_P1_13_6", 16); iVar6 = 13; iVar7 = 6; iVar1 = 90; break; case 130: StringCopy(&Var2, "TORSO_P1_13_7", 16); iVar6 = 13; iVar7 = 7; iVar1 = 47; break; case 131: StringCopy(&Var2, "TORSO_P1_13_8", 16); iVar6 = 13; iVar7 = 8; iVar1 = 45; break; case 132: StringCopy(&Var2, "TORSO_P1_13_9", 16); iVar6 = 13; iVar7 = 9; iVar1 = 48; break; case 133: StringCopy(&Var2, "TORSO_P1_13_10", 16); iVar6 = 13; iVar7 = 10; iVar1 = 45; break; case 134: StringCopy(&Var2, "TORSO_P1_13_11", 16); iVar6 = 13; iVar7 = 11; iVar1 = 85; break; case 135: StringCopy(&Var2, "TORSO_P1_13_12", 16); iVar6 = 13; iVar7 = 12; iVar1 = 45; break; case 136: StringCopy(&Var2, "TORSO_P1_13_13", 16); iVar6 = 13; iVar7 = 13; iVar1 = 47; break; case 137: StringCopy(&Var2, "TORSO_P1_13_14", 16); iVar6 = 13; iVar7 = 14; iVar1 = 45; break; case 138: StringCopy(&Var2, "TORSO_P1_13_15", 16); iVar6 = 13; iVar7 = 15; iVar1 = 48; break; case 139: StringCopy(&Var2, "TORSO_P1_14_0", 16); iVar6 = 14; iVar7 = 0; iVar1 = 290; break; case 140: StringCopy(&Var2, "TORSO_P1_14_1", 16); iVar6 = 14; iVar7 = 1; iVar1 = 290; break; case 141: StringCopy(&Var2, "TORSO_P1_14_2", 16); iVar6 = 14; iVar7 = 2; iVar1 = 290; break; case 142: StringCopy(&Var2, "TORSO_P1_14_3", 16); iVar6 = 14; iVar7 = 3; iVar1 = 290; break; case 143: StringCopy(&Var2, "TORSO_P1_14_4", 16); iVar6 = 14; iVar7 = 4; iVar1 = 290; break; case 144: StringCopy(&Var2, "TORSO_P1_14_5", 16); iVar6 = 14; iVar7 = 5; iVar1 = 290; break; case 145: StringCopy(&Var2, "TORSO_P1_14_6", 16); iVar6 = 14; iVar7 = 6; iVar1 = 65; break; case 146: StringCopy(&Var2, "TORSO_P1_14_7", 16); iVar6 = 14; iVar7 = 7; iVar1 = 65; break; case 147: StringCopy(&Var2, "TORSO_P1_15_0", 16); iVar6 = 15; iVar7 = 0; iVar1 = 200; break; case 148: StringCopy(&Var2, "TORSO_P1_15_1", 16); iVar6 = 15; iVar7 = 1; iVar1 = 220; break; case 149: StringCopy(&Var2, "TORSO_P1_15_2", 16); iVar6 = 15; iVar7 = 2; iVar1 = 220; break; case 150: StringCopy(&Var2, "TORSO_P1_15_3", 16); iVar6 = 15; iVar7 = 3; iVar1 = 240; break; case 151: StringCopy(&Var2, "TORSO_P1_15_4", 16); iVar6 = 15; iVar7 = 4; break; case 152: StringCopy(&Var2, "TORSO_P1_15_5", 16); iVar6 = 15; iVar7 = 5; iVar1 = 250; break; case 153: StringCopy(&Var2, "TORSO_P1_15_6", 16); iVar6 = 15; iVar7 = 6; iVar1 = 260; break; case 154: StringCopy(&Var2, "TORSO_P1_15_7", 16); iVar6 = 15; iVar7 = 7; iVar1 = 40; break; case 155: StringCopy(&Var2, "TORSO_P1_15_8", 16); iVar6 = 15; iVar7 = 8; iVar1 = 50; break; case 156: StringCopy(&Var2, "TORSO_P1_15_9", 16); iVar6 = 15; iVar7 = 9; iVar1 = 45; break; case 157: StringCopy(&Var2, "TORSO_P1_15_10", 16); iVar6 = 15; iVar7 = 10; iVar1 = 40; break; case 158: StringCopy(&Var2, "TORSO_P1_15_11", 16); iVar6 = 15; iVar7 = 11; iVar1 = 55; break; case 159: StringCopy(&Var2, "TORSO_P1_16_0", 16); iVar6 = 16; iVar7 = 0; break; case 160: StringCopy(&Var2, "TORSO_P1_17_0", 16); iVar6 = 17; iVar7 = 0; iVar1 = 40; break; case 161: StringCopy(&Var2, "TORSO_P1_17_1", 16); iVar6 = 17; iVar7 = 1; iVar1 = 50; break; case 162: StringCopy(&Var2, "TORSO_P1_17_2", 16); iVar6 = 17; iVar7 = 2; break; case 163: StringCopy(&Var2, "TORSO_P1_17_3", 16); iVar6 = 17; iVar7 = 3; iVar1 = 50; break; case 164: StringCopy(&Var2, "TORSO_P1_17_4", 16); iVar6 = 17; iVar7 = 4; iVar1 = 50; break; case 165: StringCopy(&Var2, "TORSO_P1_17_5", 16); iVar6 = 17; iVar7 = 5; iVar1 = 50; break; case 166: StringCopy(&Var2, "TORSO_P1_17_6", 16); iVar6 = 17; iVar7 = 6; iVar1 = 50; break; case 167: StringCopy(&Var2, "TORSO_P1_17_7", 16); iVar6 = 17; iVar7 = 7; iVar1 = 50; break; case 168: StringCopy(&Var2, "TORSO_P1_17_8", 16); iVar6 = 17; iVar7 = 8; iVar1 = 50; break; case 169: StringCopy(&Var2, "TORSO_P1_17_9", 16); iVar6 = 17; iVar7 = 9; iVar1 = 50; break; case 170: StringCopy(&Var2, "TORSO_P1_17_10", 16); iVar6 = 17; iVar7 = 10; iVar1 = 50; break; case 171: StringCopy(&Var2, "TORSO_P1_17_11", 16); iVar6 = 17; iVar7 = 11; iVar1 = 50; break; case 172: StringCopy(&Var2, "TORSO_P1_17_12", 16); iVar6 = 17; iVar7 = 12; iVar1 = 50; break; case 173: StringCopy(&Var2, "TORSO_P1_17_13", 16); iVar6 = 17; iVar7 = 13; iVar1 = 50; break; case 174: StringCopy(&Var2, "TORSO_P1_17_14", 16); iVar6 = 17; iVar7 = 14; iVar1 = 50; break; case 175: StringCopy(&Var2, "TORSO_P1_17_15", 16); iVar6 = 17; iVar7 = 15; iVar1 = 50; break; case 176: StringCopy(&Var2, "TORSO_P1_18_0", 16); iVar6 = 18; iVar7 = 0; iVar9 = 3; break; case 177: StringCopy(&Var2, "TORSO_P1_18_1", 16); iVar6 = 18; iVar7 = 1; iVar9 = 3; break; case 178: StringCopy(&Var2, "TORSO_P1_18_2", 16); iVar6 = 18; iVar7 = 2; iVar9 = 3; break; case 179: StringCopy(&Var2, "TORSO_P1_18_3", 16); iVar6 = 18; iVar7 = 3; iVar9 = 3; break; case 180: StringCopy(&Var2, "TORSO_P1_18_4", 16); iVar6 = 18; iVar7 = 4; iVar9 = 3; break; case 181: StringCopy(&Var2, "TORSO_P1_18_5", 16); iVar6 = 18; iVar7 = 5; iVar9 = 3; break; case 182: StringCopy(&Var2, "TORSO_P1_18_6", 16); iVar6 = 18; iVar7 = 6; iVar9 = 3; break; case 183: StringCopy(&Var2, "TORSO_P1_18_7", 16); iVar6 = 18; iVar7 = 7; iVar9 = 3; break; case 184: StringCopy(&Var2, "TORSO_P1_18_8", 16); iVar6 = 18; iVar7 = 8; iVar9 = 3; break; case 185: StringCopy(&Var2, "TORSO_P1_18_9", 16); iVar6 = 18; iVar7 = 9; iVar9 = 3; break; case 186: StringCopy(&Var2, "TORSO_P1_18_10", 16); iVar6 = 18; iVar7 = 10; iVar9 = 3; break; case 187: StringCopy(&Var2, "TORSO_P1_18_11", 16); iVar6 = 18; iVar7 = 11; iVar9 = 3; break; case 188: StringCopy(&Var2, "TORSO_P1_18_12", 16); iVar6 = 18; iVar7 = 12; iVar9 = 3; break; case 189: StringCopy(&Var2, "TORSO_P1_18_13", 16); iVar6 = 18; iVar7 = 13; iVar9 = 3; break; case 190: StringCopy(&Var2, "TORSO_P1_18_14", 16); iVar6 = 18; iVar7 = 14; iVar9 = 3; break; case 191: StringCopy(&Var2, "TORSO_P1_18_15", 16); iVar6 = 18; iVar7 = 15; iVar9 = 3; break; case 192: StringCopy(&Var2, "TORSO_P1_19_0", 16); iVar6 = 19; iVar7 = 0; iVar1 = 480; iVar9 = 3; break; case 193: StringCopy(&Var2, "TORSO_P1_19_1", 16); iVar6 = 19; iVar7 = 1; iVar1 = 440; iVar9 = 3; break; case 194: StringCopy(&Var2, "TORSO_P1_19_2", 16); iVar6 = 19; iVar7 = 2; iVar1 = 440; iVar9 = 3; break; case 195: StringCopy(&Var2, "TORSO_P1_19_3", 16); iVar6 = 19; iVar7 = 3; iVar1 = 520; iVar9 = 3; break; case 196: StringCopy(&Var2, "TORSO_P1_19_4", 16); iVar6 = 19; iVar7 = 4; iVar1 = 440; iVar9 = 3; break; case 197: StringCopy(&Var2, "TORSO_P1_19_5", 16); iVar6 = 19; iVar7 = 5; iVar1 = 440; iVar9 = 3; break; case 198: StringCopy(&Var2, "TORSO_P1_19_6", 16); iVar6 = 19; iVar7 = 6; iVar1 = 480; iVar9 = 3; break; case 199: StringCopy(&Var2, "TORSO_P1_19_7", 16); iVar6 = 19; iVar7 = 7; iVar1 = 480; iVar9 = 3; break; case 200: StringCopy(&Var2, "TORSO_P1_19_8", 16); iVar6 = 19; iVar7 = 8; iVar1 = 480; iVar9 = 3; break; case 201: StringCopy(&Var2, "TORSO_P1_19_9", 16); iVar6 = 19; iVar7 = 9; iVar1 = 480; iVar9 = 3; break; case 202: StringCopy(&Var2, "TORSO_P1_19_10", 16); iVar6 = 19; iVar7 = 10; iVar1 = 480; iVar9 = 3; break; case 203: StringCopy(&Var2, "TORSO_P1_19_11", 16); iVar6 = 19; iVar7 = 11; iVar1 = 480; iVar9 = 3; break; case 204: StringCopy(&Var2, "TORSO_P1_19_12", 16); iVar6 = 19; iVar7 = 12; iVar1 = 520; iVar9 = 3; break; case 205: StringCopy(&Var2, "TORSO_P1_19_13", 16); iVar6 = 19; iVar7 = 13; iVar1 = 520; iVar9 = 3; break; case 206: StringCopy(&Var2, "TORSO_P1_19_14", 16); iVar6 = 19; iVar7 = 14; iVar1 = 520; iVar9 = 3; break; case 207: StringCopy(&Var2, "TORSO_P1_19_15", 16); iVar6 = 19; iVar7 = 15; iVar1 = 440; iVar9 = 3; break; case 208: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 20; iVar7 = 0; bVar0 = true; iVar9 = 4; break; case 209: StringCopy(&Var2, "TORSO_P1_21_0", 16); iVar6 = 21; iVar7 = 0; iVar1 = 220; break; case 210: StringCopy(&Var2, "TORSO_P1_21_1", 16); iVar6 = 21; iVar7 = 1; iVar1 = 200; break; case 211: StringCopy(&Var2, "TORSO_P1_21_2", 16); iVar6 = 21; iVar7 = 2; iVar1 = 240; break; case 212: StringCopy(&Var2, "TORSO_P1_21_3", 16); iVar6 = 21; iVar7 = 3; iVar1 = 240; break; case 213: StringCopy(&Var2, "TORSO_P1_21_4", 16); iVar6 = 21; iVar7 = 4; iVar1 = 260; break; case 214: StringCopy(&Var2, "TORSO_P1_21_5", 16); iVar6 = 21; iVar7 = 5; iVar1 = 275; break; case 215: StringCopy(&Var2, "TORSO_P1_21_6", 16); iVar6 = 21; iVar7 = 6; iVar1 = 275; break; case 216: StringCopy(&Var2, "TORSO_P1_21_7", 16); iVar6 = 21; iVar7 = 7; iVar1 = 280; break; case 217: StringCopy(&Var2, "TORSO_P1_21_8", 16); iVar6 = 21; iVar7 = 8; iVar1 = 280; break; case 218: StringCopy(&Var2, "TORSO_P1_21_9", 16); iVar6 = 21; iVar7 = 9; iVar1 = 280; break; case 219: StringCopy(&Var2, "TORSO_P1_21_10", 16); iVar6 = 21; iVar7 = 10; iVar1 = 280; break; case 220: StringCopy(&Var2, "TORSO_P1_21_11", 16); iVar6 = 21; iVar7 = 11; iVar1 = 280; break; case 221: StringCopy(&Var2, "TORSO_P1_21_12", 16); iVar6 = 21; iVar7 = 12; iVar1 = 280; break; case 222: StringCopy(&Var2, "TORSO_P1_21_13", 16); iVar6 = 21; iVar7 = 13; iVar1 = 280; break; case 223: StringCopy(&Var2, "TORSO_P1_22_0", 16); iVar6 = 22; iVar7 = 0; iVar1 = 3100; iVar9 = 3; break; case 224: StringCopy(&Var2, "TORSO_P1_22_1", 16); iVar6 = 22; iVar7 = 1; iVar1 = 2800; iVar9 = 3; break; case 225: StringCopy(&Var2, "TORSO_P1_22_2", 16); iVar6 = 22; iVar7 = 2; iVar1 = 2500; iVar9 = 3; break; case 226: StringCopy(&Var2, "TORSO_P1_22_3", 16); iVar6 = 22; iVar7 = 3; iVar1 = 3000; iVar9 = 3; break; default: return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_196(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 3; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "TORSO_P1_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "TORSO_P1_0_1", 16); iVar6 = 0; iVar7 = 1; break; case 2: StringCopy(&Var2, "TORSO_P1_0_2", 16); iVar6 = 0; iVar7 = 2; iVar1 = 180; break; case 3: StringCopy(&Var2, "TORSO_P1_0_3", 16); iVar6 = 0; iVar7 = 3; iVar1 = 22; break; case 4: StringCopy(&Var2, "TORSO_P1_0_4", 16); iVar6 = 0; iVar7 = 4; iVar1 = 20; break; case 5: StringCopy(&Var2, "TORSO_P1_0_5", 16); iVar6 = 0; iVar7 = 5; iVar1 = 18; break; case 6: StringCopy(&Var2, "TORSO_P1_0_6", 16); iVar6 = 0; iVar7 = 6; iVar1 = 19; break; case 7: StringCopy(&Var2, "TORSO_P1_0_7", 16); iVar6 = 0; iVar7 = 7; iVar1 = 22; break; case 8: StringCopy(&Var2, "TORSO_P1_0_8", 16); iVar6 = 0; iVar7 = 8; iVar1 = 20; break; case 9: StringCopy(&Var2, "TORSO_P1_0_9", 16); iVar6 = 0; iVar7 = 9; iVar1 = 19; break; case 10: StringCopy(&Var2, "TORSO_P1_0_10", 16); iVar6 = 0; iVar7 = 10; iVar1 = 19; break; case 11: StringCopy(&Var2, "TORSO_P1_0_11", 16); iVar6 = 0; iVar7 = 11; iVar1 = 18; break; case 12: StringCopy(&Var2, "TORSO_P1_0_12", 16); iVar6 = 0; iVar7 = 12; iVar1 = 20; break; case 13: StringCopy(&Var2, "TORSO_P1_0_13", 16); iVar6 = 0; iVar7 = 13; iVar1 = 22; break; case 14: StringCopy(&Var2, "TORSO_P1_0_14", 16); iVar6 = 0; iVar7 = 14; iVar1 = 19; break; case 15: StringCopy(&Var2, "TORSO_P1_0_15", 16); iVar6 = 0; iVar7 = 15; iVar1 = 22; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; iVar9 = 4; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 1; bVar0 = true; iVar9 = 4; break; case 18: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 2; bVar0 = true; iVar9 = 4; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 3; bVar0 = true; iVar9 = 4; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 4; bVar0 = true; iVar9 = 4; break; case 21: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 5; bVar0 = true; iVar9 = 4; break; case 22: StringCopy(&Var2, "TORSO_P1_2_0", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; iVar9 = 3; break; case 23: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; iVar9 = 1; break; case 24: StringCopy(&Var2, "TORSO_P1_4_0", 16); iVar6 = 4; iVar7 = 0; iVar1 = 20; iVar9 = 2; break; case 25: StringCopy(&Var2, "TORSO_P1_4_1", 16); iVar6 = 4; iVar7 = 1; iVar1 = 22; iVar9 = 2; break; case 26: StringCopy(&Var2, "TORSO_P1_4_2", 16); iVar6 = 4; iVar7 = 2; iVar1 = 20; iVar9 = 2; break; case 27: StringCopy(&Var2, "TORSO_P1_4_3", 16); iVar6 = 4; iVar7 = 3; iVar1 = 25; iVar9 = 2; break; case 28: StringCopy(&Var2, "TORSO_P1_4_4", 16); iVar6 = 4; iVar7 = 4; iVar1 = 23; iVar9 = 2; break; case 29: StringCopy(&Var2, "TORSO_P1_4_5", 16); iVar6 = 4; iVar7 = 5; iVar1 = 25; iVar9 = 2; break; case 30: StringCopy(&Var2, "TORSO_P1_4_6", 16); iVar6 = 4; iVar7 = 6; iVar1 = 28; iVar9 = 2; break; case 31: StringCopy(&Var2, "TORSO_P1_4_7", 16); iVar6 = 4; iVar7 = 7; iVar1 = 26; iVar9 = 2; break; case 32: StringCopy(&Var2, "TORSO_P1_4_8", 16); iVar6 = 4; iVar7 = 8; iVar1 = 24; iVar9 = 2; break; case 33: StringCopy(&Var2, "TORSO_P1_4_9", 16); iVar6 = 4; iVar7 = 9; iVar1 = 27; iVar9 = 2; break; case 34: StringCopy(&Var2, "TORSO_P1_4_10", 16); iVar6 = 4; iVar7 = 10; iVar1 = 29; iVar9 = 2; break; case 35: StringCopy(&Var2, "TORSO_P1_4_11", 16); iVar6 = 4; iVar7 = 11; iVar1 = 28; iVar9 = 2; break; case 36: StringCopy(&Var2, "TORSO_P1_4_12", 16); iVar6 = 4; iVar7 = 12; iVar1 = 25; iVar9 = 2; break; case 37: StringCopy(&Var2, "TORSO_P1_4_13", 16); iVar6 = 4; iVar7 = 13; iVar1 = 22; iVar9 = 2; break; case 38: StringCopy(&Var2, "TORSO_P1_4_14", 16); iVar6 = 4; iVar7 = 14; iVar1 = 27; iVar9 = 2; break; case 39: StringCopy(&Var2, "TORSO_P1_4_15", 16); iVar6 = 4; iVar7 = 15; iVar1 = 29; iVar9 = 2; break; case 40: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; iVar9 = 4; break; case 41: StringCopy(&Var2, "TORSO_P1_6_0", 16); iVar6 = 6; iVar7 = 0; iVar9 = 3; break; case 42: StringCopy(&Var2, "TORSO_P1_6_1", 16); iVar6 = 6; iVar7 = 1; iVar1 = 1270; iVar9 = 3; break; case 43: StringCopy(&Var2, "TORSO_P1_6_2", 16); iVar6 = 6; iVar7 = 2; iVar1 = 1270; iVar9 = 3; break; case 44: StringCopy(&Var2, "TORSO_P1_6_3", 16); iVar6 = 6; iVar7 = 3; iVar1 = 1270; iVar9 = 3; break; case 45: StringCopy(&Var2, "TORSO_P1_6_4", 16); iVar6 = 6; iVar7 = 4; iVar1 = 1090; iVar9 = 3; break; case 46: StringCopy(&Var2, "TORSO_P1_6_5", 16); iVar6 = 6; iVar7 = 5; iVar1 = 1090; iVar9 = 3; break; case 47: StringCopy(&Var2, "TORSO_P1_6_6", 16); iVar6 = 6; iVar7 = 6; iVar1 = 1120; iVar9 = 3; break; case 48: StringCopy(&Var2, "TORSO_P1_6_7", 16); iVar6 = 6; iVar7 = 7; iVar1 = 1120; iVar9 = 3; break; case 49: StringCopy(&Var2, "TORSO_P1_6_8", 16); iVar6 = 6; iVar7 = 8; iVar1 = 1290; iVar9 = 3; break; case 50: StringCopy(&Var2, "TORSO_P1_6_9", 16); iVar6 = 6; iVar7 = 9; iVar1 = 1290; iVar9 = 3; break; case 51: StringCopy(&Var2, "TORSO_P1_6_10", 16); iVar6 = 6; iVar7 = 10; iVar1 = 1320; iVar9 = 3; break; case 52: StringCopy(&Var2, "TORSO_P1_6_11", 16); iVar6 = 6; iVar7 = 11; iVar1 = 1320; iVar9 = 3; break; case 53: StringCopy(&Var2, "TORSO_P1_6_12", 16); iVar6 = 6; iVar7 = 12; iVar1 = 1590; iVar9 = 3; break; case 54: StringCopy(&Var2, "TORSO_P1_6_13", 16); iVar6 = 6; iVar7 = 13; iVar1 = 1590; iVar9 = 3; break; case 55: StringCopy(&Var2, "TORSO_P1_6_14", 16); iVar6 = 6; iVar7 = 14; iVar1 = 1590; iVar9 = 3; break; case 56: StringCopy(&Var2, "TORSO_P1_6_15", 16); iVar6 = 6; iVar7 = 15; iVar1 = 1320; iVar9 = 3; break; case 57: StringCopy(&Var2, "TORSO_P1_7_0", 16); iVar6 = 7; iVar7 = 0; iVar1 = 98; break; case 58: StringCopy(&Var2, "TORSO_P1_7_1", 16); iVar6 = 7; iVar7 = 1; iVar1 = 98; break; case 59: StringCopy(&Var2, "TORSO_P1_7_2", 16); iVar6 = 7; iVar7 = 2; iVar1 = 110; break; case 60: StringCopy(&Var2, "TORSO_P1_7_3", 16); iVar6 = 7; iVar7 = 3; iVar1 = 110; break; case 61: StringCopy(&Var2, "TORSO_P1_7_4", 16); iVar6 = 7; iVar7 = 4; iVar1 = 118; break; case 62: StringCopy(&Var2, "TORSO_P1_7_5", 16); iVar6 = 7; iVar7 = 5; iVar1 = 120; break; case 63: StringCopy(&Var2, "TORSO_P1_7_6", 16); iVar6 = 7; iVar7 = 6; iVar1 = 120; break; case 64: StringCopy(&Var2, "TORSO_P1_7_7", 16); iVar6 = 7; iVar7 = 7; iVar1 = 129; break; case 65: StringCopy(&Var2, "TORSO_P1_7_8", 16); iVar6 = 7; iVar7 = 8; iVar1 = 125; break; case 66: StringCopy(&Var2, "TORSO_P1_7_9", 16); iVar6 = 7; iVar7 = 9; iVar1 = 125; break; case 67: StringCopy(&Var2, "TORSO_P1_7_10", 16); iVar6 = 7; iVar7 = 10; iVar1 = 129; break; case 68: StringCopy(&Var2, "TORSO_P1_7_11", 16); iVar6 = 7; iVar7 = 11; iVar1 = 129; break; case 69: StringCopy(&Var2, "TORSO_P1_7_12", 16); iVar6 = 7; iVar7 = 12; iVar1 = 135; break; case 70: StringCopy(&Var2, "TORSO_P1_7_13", 16); iVar6 = 7; iVar7 = 13; iVar1 = 139; break; case 71: StringCopy(&Var2, "TORSO_P1_7_14", 16); iVar6 = 7; iVar7 = 14; iVar1 = 145; break; case 72: StringCopy(&Var2, "TORSO_P1_7_15", 16); iVar6 = 7; iVar7 = 15; iVar1 = 145; break; case 73: StringCopy(&Var2, "TORSO_P1_8_0", 16); iVar6 = 8; iVar7 = 0; break; case 74: StringCopy(&Var2, "TORSO_P1_8_1", 16); iVar6 = 8; iVar7 = 1; break; case 75: StringCopy(&Var2, "TORSO_P1_8_2", 16); iVar6 = 8; iVar7 = 2; break; case 76: StringCopy(&Var2, "TORSO_P1_8_3", 16); iVar6 = 8; iVar7 = 3; break; case 77: StringCopy(&Var2, "TORSO_P1_8_4", 16); iVar6 = 8; iVar7 = 4; iVar1 = 30; break; case 78: StringCopy(&Var2, "TORSO_P1_8_5", 16); iVar6 = 8; iVar7 = 5; iVar1 = 38; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "TORSO_P1_8_6", 16); iVar6 = 8; iVar7 = 6; iVar1 = 32; break; case 80: StringCopy(&Var2, "TORSO_P1_8_7", 16); iVar6 = 8; iVar7 = 7; iVar1 = 30; break; case 81: StringCopy(&Var2, "TORSO_P1_8_8", 16); iVar6 = 8; iVar7 = 8; iVar1 = 33; break; case 82: StringCopy(&Var2, "TORSO_P1_8_9", 16); iVar6 = 8; iVar7 = 9; iVar1 = 35; break; case 83: StringCopy(&Var2, "TORSO_P1_8_10", 16); iVar6 = 8; iVar7 = 10; iVar1 = 35; break; case 84: StringCopy(&Var2, "TORSO_P1_8_11", 16); iVar6 = 8; iVar7 = 11; iVar1 = 38; break; case 85: StringCopy(&Var2, "TORSO_P1_8_12", 16); iVar6 = 8; iVar7 = 12; iVar1 = 33; break; case 86: StringCopy(&Var2, "TORSO_P1_8_13", 16); iVar6 = 8; iVar7 = 13; iVar1 = 35; break; case 87: StringCopy(&Var2, "TORSO_P1_8_14", 16); iVar6 = 8; iVar7 = 14; iVar1 = 38; break; case 88: StringCopy(&Var2, "TORSO_P1_8_15", 16); iVar6 = 8; iVar7 = 15; iVar1 = 32; break; case 89: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 90: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 91: StringCopy(&Var2, "TORSO_P1_11_0", 16); iVar6 = 11; iVar7 = 0; break; case 92: StringCopy(&Var2, "TORSO_P1_11_1", 16); iVar6 = 11; iVar7 = 1; iVar1 = 59; break; case 93: StringCopy(&Var2, "TORSO_P1_11_2", 16); iVar6 = 11; iVar7 = 2; break; case 94: StringCopy(&Var2, "TORSO_P1_11_3", 16); iVar6 = 11; iVar7 = 3; iVar1 = 25; break; case 95: StringCopy(&Var2, "TORSO_P1_11_4", 16); iVar6 = 11; iVar7 = 4; iVar1 = 29; break; case 96: StringCopy(&Var2, "TORSO_P1_11_5", 16); iVar6 = 11; iVar7 = 5; iVar1 = 27; break; case 97: StringCopy(&Var2, "TORSO_P1_11_6", 16); iVar6 = 11; iVar7 = 6; iVar1 = 25; break; case 98: StringCopy(&Var2, "TORSO_P1_11_7", 16); iVar6 = 11; iVar7 = 7; iVar1 = 27; break; case 99: StringCopy(&Var2, "TORSO_P1_11_8", 16); iVar6 = 11; iVar7 = 8; iVar1 = 28; break; case 100: StringCopy(&Var2, "TORSO_P1_11_9", 16); iVar6 = 11; iVar7 = 9; iVar1 = 30; break; case 101: StringCopy(&Var2, "TORSO_P1_11_10", 16); iVar6 = 11; iVar7 = 10; iVar1 = 29; break; case 102: StringCopy(&Var2, "TORSO_P1_11_11", 16); iVar6 = 11; iVar7 = 11; iVar1 = 27; break; case 103: StringCopy(&Var2, "TORSO_P1_11_12", 16); iVar6 = 11; iVar7 = 12; iVar1 = 29; break; case 104: StringCopy(&Var2, "TORSO_P1_11_13", 16); iVar6 = 11; iVar7 = 13; iVar1 = 32; break; case 105: StringCopy(&Var2, "TORSO_P1_11_14", 16); iVar6 = 11; iVar7 = 14; iVar1 = 30; break; case 106: StringCopy(&Var2, "TORSO_P1_11_15", 16); iVar6 = 11; iVar7 = 15; iVar1 = 28; break; default: return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_197(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 2; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "HAIR_P1_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "HAIR_P1_0_1", 16); iVar6 = 0; iVar7 = 1; break; case 2: StringCopy(&Var2, "HAIR_P1_0_2", 16); iVar6 = 0; iVar7 = 2; break; case 3: StringCopy(&Var2, "HAIR_P1_0_3", 16); iVar6 = 0; iVar7 = 3; iVar9 = 3; break; case 4: StringCopy(&Var2, "HAIR_P1_0_4", 16); iVar6 = 0; iVar7 = 4; iVar9 = 3; break; case 5: StringCopy(&Var2, "HAIR_P1_0_5", 16); iVar6 = 0; iVar7 = 5; iVar9 = 3; break; case 6: StringCopy(&Var2, "HAIR_P1_0_6", 16); iVar6 = 0; iVar7 = 6; iVar9 = 3; break; case 7: StringCopy(&Var2, "HAIR_P1_0_7", 16); iVar6 = 0; iVar7 = 7; iVar9 = 3; break; case 8: StringCopy(&Var2, "HAIR_P1_0_8", 16); iVar6 = 0; iVar7 = 8; iVar9 = 3; break; case 9: StringCopy(&Var2, "HAIR_P1_0_9", 16); iVar6 = 0; iVar7 = 9; iVar9 = 3; break; case 10: StringCopy(&Var2, "HAIR_P1_0_10", 16); iVar6 = 0; iVar7 = 10; iVar9 = 3; break; case 11: StringCopy(&Var2, "HAIR_P1_0_11", 16); iVar6 = 0; iVar7 = 11; iVar9 = 3; break; case 12: StringCopy(&Var2, "HAIR_P1_0_12", 16); iVar6 = 0; iVar7 = 12; iVar9 = 3; break; case 13: StringCopy(&Var2, "HAIR_P1_0_13", 16); iVar6 = 0; iVar7 = 13; break; case 14: StringCopy(&Var2, "HAIR_P1_0_14", 16); iVar6 = 0; iVar7 = 14; iVar9 = 3; break; case 15: StringCopy(&Var2, "HAIR_P1_0_15", 16); iVar6 = 0; iVar7 = 15; iVar9 = 3; break; case 16: StringCopy(&Var2, "HAIR_P1_1_0", 16); iVar6 = 1; iVar7 = 0; iVar9 = 3; break; case 17: StringCopy(&Var2, "HAIR_P1_2_0", 16); iVar6 = 2; iVar7 = 0; iVar9 = 3; break; case 18: StringCopy(&Var2, "HAIR_P1_3_0", 16); iVar6 = 3; iVar7 = 0; iVar9 = 3; break; case 19: StringCopy(&Var2, "HAIR_P1_4_0", 16); iVar6 = 4; iVar7 = 0; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; default: func_163(iVar10, iParam0, 21, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_198(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 0; Global_76647[0 /*14*/].f_5 = 1; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 1; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 2; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 3; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 4; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 5; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 6; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 7; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 8; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 9; break; default: func_163(iVar10, iParam0, 10, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_199(int iParam0, int iParam1) { switch (iParam0) { case 0: func_216(iParam1); break; case 2: func_215(iParam1); break; case 3: func_212(iParam1); break; case 4: func_211(iParam1); break; case 6: func_210(iParam1); break; case 5: func_209(iParam1); break; case 8: func_208(iParam1); break; case 9: func_207(iParam1); break; case 10: func_206(iParam1); break; case 1: func_205(iParam1); break; case 7: func_204(iParam1); break; case 11: func_203(iParam1); break; case 12: func_202(iParam1); break; case 13: func_201(iParam1); break; case 14: func_200(iParam1); break; } } void func_200(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 14; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 1; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 2; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 3; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 4; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 5; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 6; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 7; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = -1; iVar7 = 0; iVar1 = 0; iVar8 = 8; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 11: StringCopy(&Var2, "PROPS_P0_H1", 16); iVar6 = 1; iVar7 = 0; iVar8 = 0; break; case 12: StringCopy(&Var2, "PROPS_P0_H2", 16); iVar6 = 2; iVar7 = 0; iVar1 = 320; iVar8 = 11; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 18: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; iVar8 = 0; break; case 21: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; iVar8 = 0; break; case 22: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 1; iVar8 = 0; break; case 23: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 2; iVar8 = 0; break; case 24: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 3; iVar8 = 0; break; case 25: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 4; iVar8 = 0; break; case 26: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 5; iVar8 = 0; break; case 27: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 6; iVar8 = 0; break; case 28: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 7; iVar8 = 0; break; case 29: StringCopy(&Var2, "PROPS_P0_H12", 16); iVar6 = 12; iVar7 = 0; iVar8 = 0; break; case 30: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 13; iVar7 = 0; iVar8 = 0; break; case 31: StringCopy(&Var2, "PROPS_P1_H8_0", 16); iVar6 = 14; iVar7 = 0; iVar1 = 270; iVar8 = 0; break; case 32: StringCopy(&Var2, "PROPS_P1_H8_1", 16); iVar6 = 14; iVar7 = 1; iVar1 = 270; iVar8 = 0; break; case 33: StringCopy(&Var2, "PROPS_P1_H9_0", 16); iVar6 = 15; iVar7 = 0; iVar1 = 200; iVar8 = 0; break; case 34: StringCopy(&Var2, "PROPS_P1_H9_1", 16); iVar6 = 15; iVar7 = 1; iVar1 = 200; iVar8 = 0; break; case 35: StringCopy(&Var2, "PROPS_P1_H10_0", 16); iVar6 = 16; iVar7 = 0; iVar1 = 350; iVar8 = 0; break; case 36: StringCopy(&Var2, "PROPS_P1_H10_1", 16); iVar6 = 16; iVar7 = 1; iVar1 = 350; iVar8 = 0; break; case 37: StringCopy(&Var2, "PROPS_P1_H11_0", 16); iVar6 = 17; iVar7 = 0; iVar1 = 450; iVar8 = 0; break; case 38: StringCopy(&Var2, "PROPS_P1_H12_0", 16); iVar6 = 18; iVar7 = 0; iVar1 = 500; iVar8 = 0; break; case 39: StringCopy(&Var2, "PROPS_P1_H12_1", 16); iVar6 = 18; iVar7 = 1; iVar1 = 500; iVar8 = 0; break; case 40: StringCopy(&Var2, "PROPS_P1_H13_0", 16); iVar6 = 19; iVar7 = 0; iVar1 = 50; iVar8 = 0; break; case 41: StringCopy(&Var2, "PROPS_P1_H13_1", 16); iVar6 = 19; iVar7 = 1; iVar1 = 50; iVar8 = 0; break; case 42: StringCopy(&Var2, "PROPS_P1_H14_0", 16); iVar6 = 20; iVar7 = 0; iVar1 = 99; iVar8 = 0; break; case 43: StringCopy(&Var2, "PROPS_P1_H14_1", 16); iVar6 = 20; iVar7 = 1; iVar1 = 99; iVar8 = 0; break; case 44: StringCopy(&Var2, "PROPS_P1_H14_2", 16); iVar6 = 20; iVar7 = 2; iVar1 = 99; iVar8 = 0; break; case 45: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 21; iVar7 = 0; iVar8 = 0; break; case 46: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 22; iVar7 = 0; iVar8 = 0; break; case 47: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 0; iVar8 = 0; break; case 48: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 1; iVar8 = 0; break; case 49: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 2; iVar8 = 0; break; case 50: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 3; iVar8 = 0; break; case 51: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 4; iVar8 = 0; break; case 52: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 5; iVar8 = 0; break; case 53: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 24; iVar7 = 0; iVar8 = 0; break; case 54: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 25; iVar7 = 0; iVar8 = 0; break; case 55: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 0; iVar8 = 0; break; case 56: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 27; iVar7 = 0; iVar8 = 0; break; case 57: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 28; iVar7 = 0; iVar8 = 0; break; case 58: StringCopy(&Var2, "PROPS_P0_E0", 16); iVar6 = 0; iVar7 = 0; iVar1 = 45; iVar8 = 10; break; case 59: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; iVar8 = 10; break; case 60: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; iVar8 = 10; break; case 61: StringCopy(&Var2, "PROPS_P0_E3", 16); iVar6 = 3; iVar7 = 0; iVar1 = 55; iVar8 = 10; break; case 62: StringCopy(&Var2, "PROPS_P0_E4", 16); iVar6 = 4; iVar7 = 0; iVar1 = 58; iVar8 = 10; break; case 63: StringCopy(&Var2, "PROPS_P0_E4_1", 16); iVar6 = 4; iVar7 = 1; iVar1 = 56; iVar8 = 10; break; case 64: StringCopy(&Var2, "PROPS_P0_E4_2", 16); iVar6 = 4; iVar7 = 2; iVar1 = 60; iVar8 = 10; break; case 65: StringCopy(&Var2, "PROPS_P0_E4_3", 16); iVar6 = 4; iVar7 = 3; iVar1 = 65; iVar8 = 10; break; case 66: StringCopy(&Var2, "PROPS_P0_E4_4", 16); iVar6 = 4; iVar7 = 4; iVar1 = 62; iVar8 = 10; break; case 67: StringCopy(&Var2, "PROPS_P0_E4_5", 16); iVar6 = 4; iVar7 = 5; iVar1 = 65; iVar8 = 10; break; case 68: StringCopy(&Var2, "PROPS_P0_E4_6", 16); iVar6 = 4; iVar7 = 6; iVar1 = 68; iVar8 = 10; break; case 69: StringCopy(&Var2, "PROPS_P0_E4_7", 16); iVar6 = 4; iVar7 = 7; iVar1 = 68; iVar8 = 10; break; case 70: StringCopy(&Var2, "PROPS_P0_E5", 16); iVar6 = 5; iVar7 = 0; iVar1 = 65; iVar8 = 10; break; case 71: StringCopy(&Var2, "PROPS_P0_E5_1", 16); iVar6 = 5; iVar7 = 1; iVar1 = 69; iVar8 = 10; break; case 72: StringCopy(&Var2, "PROPS_P0_E5_2", 16); iVar6 = 5; iVar7 = 2; iVar1 = 72; iVar8 = 10; break; case 73: StringCopy(&Var2, "PROPS_P0_E5_3", 16); iVar6 = 5; iVar7 = 3; iVar1 = 70; iVar8 = 10; break; case 74: StringCopy(&Var2, "PROPS_P0_E5_4", 16); iVar6 = 5; iVar7 = 4; iVar1 = 74; iVar8 = 10; break; case 75: StringCopy(&Var2, "PROPS_P0_E5_5", 16); iVar6 = 5; iVar7 = 5; iVar1 = 78; iVar8 = 10; break; case 76: StringCopy(&Var2, "PROPS_P0_E5_6", 16); iVar6 = 5; iVar7 = 6; iVar1 = 82; iVar8 = 10; break; case 77: StringCopy(&Var2, "PROPS_P0_E5_7", 16); iVar6 = 5; iVar7 = 7; iVar1 = 85; iVar8 = 10; break; case 78: StringCopy(&Var2, "PROPS_P0_E5_8", 16); iVar6 = 5; iVar7 = 8; iVar1 = 85; iVar8 = 10; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "PROPS_P0_E5_9", 16); iVar6 = 5; iVar7 = 9; iVar8 = 10; break; case 80: StringCopy(&Var2, "PROPS_P0_E6", 16); iVar6 = 6; iVar7 = 0; iVar1 = 69; iVar8 = 10; break; case 81: StringCopy(&Var2, "PROPS_P0_E6_1", 16); iVar6 = 6; iVar7 = 1; iVar1 = 69; iVar8 = 10; break; case 82: StringCopy(&Var2, "PROPS_P0_E6_2", 16); iVar6 = 6; iVar7 = 2; iVar1 = 69; iVar8 = 10; break; case 83: StringCopy(&Var2, "PROPS_P0_E6_3", 16); iVar6 = 6; iVar7 = 3; iVar1 = 69; iVar8 = 10; break; case 84: StringCopy(&Var2, "PROPS_P0_E6_4", 16); iVar6 = 6; iVar7 = 4; iVar1 = 69; iVar8 = 10; break; case 85: StringCopy(&Var2, "PROPS_P0_E6_5", 16); iVar6 = 6; iVar7 = 5; iVar1 = 69; iVar8 = 10; break; case 86: StringCopy(&Var2, "PROPS_P0_E6_6", 16); iVar6 = 6; iVar7 = 6; iVar1 = 69; iVar8 = 10; break; case 87: StringCopy(&Var2, "PROPS_P0_E6_7", 16); iVar6 = 6; iVar7 = 7; iVar1 = 69; iVar8 = 10; break; case 88: StringCopy(&Var2, "PROPS_P0_E6_8", 16); iVar6 = 6; iVar7 = 8; iVar1 = 69; iVar8 = 10; break; case 89: StringCopy(&Var2, "PROPS_P0_E6_9", 16); iVar6 = 6; iVar7 = 9; iVar1 = 69; iVar8 = 10; break; case 90: StringCopy(&Var2, "PROPS_P0_E7", 16); iVar6 = 7; iVar7 = 0; iVar8 = 10; break; case 91: StringCopy(&Var2, "PROPS_P0_E8", 16); iVar6 = 8; iVar7 = 0; iVar1 = 170; iVar8 = 10; break; case 92: StringCopy(&Var2, "PROPS_P0_E8_1", 16); iVar6 = 8; iVar7 = 1; iVar1 = 175; iVar8 = 10; break; case 93: StringCopy(&Var2, "PROPS_P0_E8_2", 16); iVar6 = 8; iVar7 = 2; iVar1 = 180; iVar8 = 10; break; case 94: StringCopy(&Var2, "PROPS_P0_E8_3", 16); iVar6 = 8; iVar7 = 3; iVar1 = 185; iVar8 = 10; break; case 95: StringCopy(&Var2, "PROPS_P0_E8_4", 16); iVar6 = 8; iVar7 = 4; iVar1 = 189; iVar8 = 10; break; case 96: StringCopy(&Var2, "PROPS_P0_E8_5", 16); iVar6 = 8; iVar7 = 5; iVar1 = 195; iVar8 = 10; break; case 97: StringCopy(&Var2, "PROPS_P0_E8_6", 16); iVar6 = 8; iVar7 = 6; iVar1 = 235; iVar8 = 10; break; case 98: StringCopy(&Var2, "PROPS_P0_E8_7", 16); iVar6 = 8; iVar7 = 7; iVar1 = 245; iVar8 = 10; break; case 99: StringCopy(&Var2, "PROPS_P0_E8_8", 16); iVar6 = 8; iVar7 = 8; iVar1 = 250; iVar8 = 10; break; case 100: StringCopy(&Var2, "PROPS_P0_E8_9", 16); iVar6 = 8; iVar7 = 9; iVar1 = 275; iVar8 = 10; break; case 101: StringCopy(&Var2, "PROPS_P0_E8_10", 16); iVar6 = 8; iVar7 = 10; iVar1 = 280; iVar8 = 10; break; case 102: StringCopy(&Var2, "PROPS_P0_E8_11", 16); iVar6 = 8; iVar7 = 11; iVar1 = 295; iVar8 = 10; break; case 103: StringCopy(&Var2, "PROPS_P0_E9", 16); iVar6 = 9; iVar7 = 0; iVar1 = 179; iVar8 = 10; break; case 104: StringCopy(&Var2, "PROPS_P0_E9_1", 16); iVar6 = 9; iVar7 = 1; iVar1 = 159; iVar8 = 10; break; case 105: StringCopy(&Var2, "PROPS_P0_E9_2", 16); iVar6 = 9; iVar7 = 2; iVar1 = 165; iVar8 = 10; break; case 106: StringCopy(&Var2, "PROPS_P0_E9_3", 16); iVar6 = 9; iVar7 = 3; iVar1 = 155; iVar8 = 10; break; case 107: StringCopy(&Var2, "PROPS_P0_E9_4", 16); iVar6 = 9; iVar7 = 4; iVar1 = 175; iVar8 = 10; break; case 108: StringCopy(&Var2, "PROPS_P0_E9_5", 16); iVar6 = 9; iVar7 = 5; iVar1 = 185; iVar8 = 10; break; case 109: StringCopy(&Var2, "PROPS_P0_E9_6", 16); iVar6 = 9; iVar7 = 6; iVar1 = 189; iVar8 = 10; break; case 110: StringCopy(&Var2, "PROPS_P0_E9_7", 16); iVar6 = 9; iVar7 = 7; iVar1 = 225; iVar8 = 10; break; case 111: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; iVar1 = 100; iVar8 = 10; break; case 112: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; iVar8 = 2; break; default: func_163(iVar10, iParam0, 113, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_201(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 13; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; default: func_163(iVar10, iParam0, 10, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_202(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 12; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "OUTFIT_P0_0", 16); iVar6 = 0; iVar7 = 0; bVar0 = true; break; case 1: StringCopy(&Var2, "OUTFIT_P0_1", 16); iVar6 = 0; iVar7 = 0; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 3: StringCopy(&Var2, "OUTFIT_P0_4", 16); iVar6 = 0; iVar7 = 0; break; case 4: StringCopy(&Var2, "OUTFIT_P0_7", 16); iVar6 = 0; iVar7 = 0; break; case 5: StringCopy(&Var2, "OUTFIT_P0_8", 16); iVar6 = 0; iVar7 = 0; break; case 6: StringCopy(&Var2, "OUTFIT_P0_9", 16); iVar6 = 0; iVar7 = 0; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 8: StringCopy(&Var2, "OUTFIT_P0_11", 16); iVar6 = 0; iVar7 = 0; break; case 9: StringCopy(&Var2, "OUTFIT_P0_12", 16); iVar6 = 0; iVar7 = 0; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 11: StringCopy(&Var2, "OUTFIT_P0_14", 16); iVar6 = 0; iVar7 = 0; break; case 12: StringCopy(&Var2, "OUTFIT_P0_17", 16); iVar6 = 0; iVar7 = 0; break; case 13: StringCopy(&Var2, "OUTFIT_P0_18", 16); iVar6 = 0; iVar7 = 0; break; case 14: StringCopy(&Var2, "OUTFIT_P0_19", 16); iVar6 = 0; iVar7 = 0; break; case 15: StringCopy(&Var2, "OUTFIT_P0_20", 16); iVar6 = 0; iVar7 = 0; break; case 16: StringCopy(&Var2, "OUTFIT_P0_22", 16); iVar6 = 0; iVar7 = 0; iVar1 = 10000; break; case 17: StringCopy(&Var2, "OUTFIT_P0_23", 16); iVar6 = 0; iVar7 = 0; break; case 18: StringCopy(&Var2, "OUTFIT_P0_24", 16); iVar6 = 0; iVar7 = 0; break; case 19: StringCopy(&Var2, "OUTFIT_P0_26", 16); iVar6 = 0; iVar7 = 0; break; case 20: StringCopy(&Var2, "OUTFIT_P0_28", 16); iVar6 = 0; iVar7 = 0; iVar1 = 105; break; case 21: StringCopy(&Var2, "OUTFIT_P0_29", 16); iVar6 = 0; iVar7 = 0; iVar1 = 105; break; case 22: StringCopy(&Var2, "OUTFIT_P0_30", 16); iVar6 = 0; iVar7 = 0; iVar1 = 105; break; case 23: StringCopy(&Var2, "OUTFIT_P0_31", 16); iVar6 = 0; iVar7 = 0; break; case 24: StringCopy(&Var2, "OUTFIT_P0_32", 16); iVar6 = 0; iVar7 = 0; break; case 25: StringCopy(&Var2, "OUTFIT_P0_33", 16); iVar6 = 0; iVar7 = 0; break; case 26: StringCopy(&Var2, "OUTFIT_P0_34", 16); iVar6 = 0; iVar7 = 0; break; case 27: StringCopy(&Var2, "OUTFIT_P0_35", 16); iVar6 = 0; iVar7 = 0; break; case 28: StringCopy(&Var2, "OUTFIT_P0_11", 16); iVar6 = 0; iVar7 = 0; break; case 29: StringCopy(&Var2, "OUTFIT_P0_36", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4900; break; case 30: StringCopy(&Var2, "OUTFIT_P0_37", 16); iVar6 = 0; iVar7 = 0; iVar1 = 840; break; case 31: StringCopy(&Var2, "OUTFIT_P0_38", 16); iVar6 = 0; iVar7 = 0; break; case 32: StringCopy(&Var2, "OUTFIT_P0_39", 16); iVar6 = 0; iVar7 = 0; break; case 33: StringCopy(&Var2, "OUTFIT_P0_40", 16); iVar6 = 0; iVar7 = 0; break; case 34: StringCopy(&Var2, "OUTFIT_P0_41", 16); iVar6 = 0; iVar7 = 0; break; case 35: StringCopy(&Var2, "OUTFIT_P0_42", 16); iVar6 = 0; iVar7 = 0; break; case 36: StringCopy(&Var2, "OUTFIT_P0_43", 16); iVar6 = 0; iVar7 = 0; break; case 37: StringCopy(&Var2, "OUTFIT_P0_44", 16); iVar6 = 0; iVar7 = 0; iVar1 = 3900; break; case 38: StringCopy(&Var2, "OUTFIT_P0_45", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4000; break; case 39: StringCopy(&Var2, "OUTFIT_P0_46", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5900; break; case 40: StringCopy(&Var2, "OUTFIT_P0_47", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4600; break; case 41: StringCopy(&Var2, "OUTFIT_P0_48", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5500; break; case 42: StringCopy(&Var2, "OUTFIT_P0_49", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4400; break; case 43: StringCopy(&Var2, "OUTFIT_P0_50", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4400; break; case 44: StringCopy(&Var2, "OUTFIT_P0_51", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4900; break; case 45: StringCopy(&Var2, "OUTFIT_P0_52", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5500; break; case 46: StringCopy(&Var2, "OUTFIT_P0_53", 16); iVar6 = 0; iVar7 = 0; iVar1 = 4500; break; case 47: StringCopy(&Var2, "OUTFIT_P0_54", 16); iVar6 = 0; iVar7 = 0; iVar1 = 5900; break; case 48: StringCopy(&Var2, "OUTFIT_P0_55", 16); iVar6 = 0; iVar7 = 0; break; case 49: StringCopy(&Var2, "OUTFIT_P0_17", 16); iVar6 = 0; iVar7 = 0; break; case 50: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 51: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 52: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; default: func_163(iVar10, iParam0, 53, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_203(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 11; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "JBIB_P0_02_0", 16); iVar6 = 2; iVar7 = 0; break; case 3: StringCopy(&Var2, "JBIB_P0_02_1", 16); iVar6 = 2; iVar7 = 1; break; case 4: StringCopy(&Var2, "JBIB_P0_02_2", 16); iVar6 = 2; iVar7 = 2; break; case 5: StringCopy(&Var2, "JBIB_P0_02_3", 16); iVar6 = 2; iVar7 = 3; break; case 6: StringCopy(&Var2, "JBIB_P0_02_4", 16); iVar6 = 2; iVar7 = 4; break; case 7: StringCopy(&Var2, "JBIB_P0_02_5", 16); iVar6 = 2; iVar7 = 5; break; case 8: StringCopy(&Var2, "JBIB_P0_03_0", 16); iVar6 = 3; iVar7 = 0; iVar1 = 390; break; case 9: StringCopy(&Var2, "JBIB_P0_03_1", 16); iVar6 = 3; iVar7 = 1; iVar1 = 390; break; case 10: StringCopy(&Var2, "JBIB_P0_03_2", 16); iVar6 = 3; iVar7 = 2; iVar1 = 420; break; case 11: StringCopy(&Var2, "JBIB_P0_03_3", 16); iVar6 = 3; iVar7 = 3; iVar1 = 420; break; case 12: StringCopy(&Var2, "JBIB_P0_03_4", 16); iVar6 = 3; iVar7 = 4; iVar1 = 490; break; case 13: StringCopy(&Var2, "JBIB_P0_03_5", 16); iVar6 = 3; iVar7 = 5; iVar1 = 490; break; case 14: StringCopy(&Var2, "JBIB_P0_03_6", 16); iVar6 = 3; iVar7 = 6; iVar1 = 540; break; case 15: StringCopy(&Var2, "JBIB_P0_03_7", 16); iVar6 = 3; iVar7 = 7; iVar1 = 540; break; case 16: StringCopy(&Var2, "JBIB_P0_03_8", 16); iVar6 = 3; iVar7 = 8; iVar1 = 550; break; case 17: StringCopy(&Var2, "JBIB_P0_03_9", 16); iVar6 = 3; iVar7 = 9; iVar1 = 540; break; case 18: StringCopy(&Var2, "JBIB_P0_04_0", 16); iVar6 = 4; iVar7 = 0; iVar1 = 850; break; case 19: StringCopy(&Var2, "JBIB_P0_04_1", 16); iVar6 = 4; iVar7 = 1; iVar1 = 850; break; case 20: StringCopy(&Var2, "JBIB_P0_04_2", 16); iVar6 = 4; iVar7 = 2; iVar1 = 890; break; case 21: StringCopy(&Var2, "JBIB_P0_04_3", 16); iVar6 = 4; iVar7 = 3; iVar1 = 890; break; case 22: StringCopy(&Var2, "JBIB_P0_04_4", 16); iVar6 = 4; iVar7 = 4; iVar1 = 920; break; case 23: StringCopy(&Var2, "JBIB_P0_04_5", 16); iVar6 = 4; iVar7 = 5; iVar1 = 920; break; case 24: StringCopy(&Var2, "JBIB_P0_04_6", 16); iVar6 = 4; iVar7 = 6; iVar1 = 950; break; case 25: StringCopy(&Var2, "JBIB_P0_04_7", 16); iVar6 = 4; iVar7 = 7; iVar1 = 980; break; case 26: StringCopy(&Var2, "JBIB_P0_04_8", 16); iVar6 = 4; iVar7 = 8; iVar1 = 1050; break; case 27: StringCopy(&Var2, "JBIB_P0_04_9", 16); iVar6 = 4; iVar7 = 9; iVar1 = 1100; break; case 28: StringCopy(&Var2, "JBIB_P0_05_0", 16); iVar6 = 5; iVar7 = 0; iVar1 = 1890; break; case 29: StringCopy(&Var2, "JBIB_P0_05_1", 16); iVar6 = 5; iVar7 = 1; iVar1 = 1820; break; case 30: StringCopy(&Var2, "JBIB_P0_05_2", 16); iVar6 = 5; iVar7 = 2; iVar1 = 1820; break; case 31: StringCopy(&Var2, "JBIB_P0_05_3", 16); iVar6 = 5; iVar7 = 3; iVar1 = 1850; break; case 32: StringCopy(&Var2, "JBIB_P0_05_4", 16); iVar6 = 5; iVar7 = 4; iVar1 = 1850; break; case 33: StringCopy(&Var2, "JBIB_P0_05_5", 16); iVar6 = 5; iVar7 = 5; iVar1 = 1900; break; case 34: StringCopy(&Var2, "JBIB_P0_05_6", 16); iVar6 = 5; iVar7 = 6; iVar1 = 1920; break; case 35: StringCopy(&Var2, "JBIB_P0_05_7", 16); iVar6 = 5; iVar7 = 7; iVar1 = 1980; break; case 36: StringCopy(&Var2, "JBIB_P0_05_8", 16); iVar6 = 5; iVar7 = 8; iVar1 = 2100; break; case 37: StringCopy(&Var2, "JBIB_P0_05_9", 16); iVar6 = 5; iVar7 = 9; iVar1 = 2120; break; case 38: StringCopy(&Var2, "JBIB_P0_05_10", 16); iVar6 = 5; iVar7 = 10; iVar1 = 2000; break; case 39: StringCopy(&Var2, "JBIB_P0_05_11", 16); iVar6 = 5; iVar7 = 11; iVar1 = 2200; break; case 40: StringCopy(&Var2, "JBIB_P0_05_12", 16); iVar6 = 5; iVar7 = 12; iVar1 = 2280; break; case 41: StringCopy(&Var2, "JBIB_P0_05_13", 16); iVar6 = 5; iVar7 = 13; iVar1 = 2300; break; case 42: StringCopy(&Var2, "JBIB_P0_05_14", 16); iVar6 = 5; iVar7 = 14; iVar1 = 2350; break; case 43: StringCopy(&Var2, "JBIB_P0_05_15", 16); iVar6 = 5; iVar7 = 15; iVar1 = 2280; break; case 44: StringCopy(&Var2, "JBIB_P0_06_0", 16); iVar6 = 6; iVar7 = 0; break; default: func_163(iVar10, iParam0, 45, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_204(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 7; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; default: func_163(iVar10, iParam0, 1, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_205(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 1; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "BERD_P0_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "BERD_P0_1_0", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "BERD_P0_2_0", 16); iVar6 = 2; iVar7 = 0; break; case 3: StringCopy(&Var2, "BERD_P0_3_0", 16); iVar6 = 3; iVar7 = 0; break; case 4: StringCopy(&Var2, "BERD_P0_4_0", 16); iVar6 = 4; iVar7 = 0; break; default: func_163(iVar10, iParam0, 5, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_206(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 10; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 1; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 2; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 3; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 4; break; case 12: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 5; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 6; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 7; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 1; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 2; break; case 18: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 3; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 4; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 5; break; case 21: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; break; case 22: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 1; break; case 23: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 2; break; case 24: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 3; break; case 25: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 4; break; case 26: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 5; break; case 27: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 6; break; case 28: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; break; case 29: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 1; break; case 30: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 2; break; case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 3; break; case 32: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 4; break; case 33: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 5; break; case 34: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 6; break; case 35: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 7; break; case 36: StringCopy(&Var2, "DECL_P0_10_8", 16); iVar6 = 10; iVar7 = 8; break; case 37: StringCopy(&Var2, "DECL_P0_10_9", 16); iVar6 = 10; iVar7 = 9; break; case 38: StringCopy(&Var2, "DECL_P0_10_10", 16); iVar6 = 10; iVar7 = 10; break; case 39: StringCopy(&Var2, "DECL_P0_10_11", 16); iVar6 = 10; iVar7 = 11; break; case 40: StringCopy(&Var2, "DECL_P0_10_12", 16); iVar6 = 10; iVar7 = 12; break; case 41: StringCopy(&Var2, "DECL_P0_10_13", 16); iVar6 = 10; iVar7 = 13; break; case 42: StringCopy(&Var2, "DECL_P0_10_14", 16); iVar6 = 10; iVar7 = 14; break; case 43: StringCopy(&Var2, "DECL_P0_10_15", 16); iVar6 = 10; iVar7 = 15; break; case 44: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; break; case 45: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 1; break; case 46: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 2; break; case 47: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 3; break; default: func_163(iVar10, iParam0, 48, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_207(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 9; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 1; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 9: StringCopy(&Var2, "SPEC2_P0_08_0", 16); iVar6 = 8; iVar7 = 0; iVar1 = 125; break; case 10: StringCopy(&Var2, "SPEC2_P0_08_1", 16); iVar6 = 8; iVar7 = 1; iVar1 = 150; break; case 11: StringCopy(&Var2, "SPEC2_P0_08_2", 16); iVar6 = 8; iVar7 = 2; iVar1 = 175; break; case 12: StringCopy(&Var2, "SPEC2_P0_08_3", 16); iVar6 = 8; iVar7 = 3; iVar1 = 85; break; case 13: StringCopy(&Var2, "SPEC2_P0_08_4", 16); iVar6 = 8; iVar7 = 4; iVar1 = 150; break; case 14: StringCopy(&Var2, "SPEC2_P0_08_5", 16); iVar6 = 8; iVar7 = 5; iVar1 = 175; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 1; bVar0 = true; break; case 18: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; bVar0 = true; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; bVar0 = true; break; default: func_163(iVar10, iParam0, 20, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_208(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 8; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 10: StringCopy(&Var2, "SPEC_P0_10", 16); iVar6 = 10; iVar7 = 0; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; bVar0 = true; break; case 12: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; bVar0 = true; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 13; iVar7 = 0; bVar0 = true; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 14; iVar7 = 0; bVar0 = true; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 15; iVar7 = 0; bVar0 = true; break; case 16: StringCopy(&Var2, "SPEC_P0_16", 16); iVar6 = 16; iVar7 = 0; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 0; bVar0 = true; break; case 18: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 18; iVar7 = 0; bVar0 = true; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 19; iVar7 = 0; bVar0 = true; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 20; iVar7 = 0; bVar0 = true; break; case 21: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 21; iVar7 = 0; bVar0 = true; break; case 22: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 22; iVar7 = 0; bVar0 = true; break; case 23: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 23; iVar7 = 0; bVar0 = true; break; default: func_163(iVar10, iParam0, 24, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_209(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 5; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 1; bVar0 = true; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 2; bVar0 = true; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 3; bVar0 = true; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 4; bVar0 = true; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 12: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; default: func_163(iVar10, iParam0, 14, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_210(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 6; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "FEET_P0_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "FEET_P0_0_1", 16); iVar6 = 0; iVar7 = 1; iVar1 = 665; break; case 2: StringCopy(&Var2, "FEET_P0_0_2", 16); iVar6 = 0; iVar7 = 2; iVar1 = 620; break; case 3: StringCopy(&Var2, "FEET_P0_0_3", 16); iVar6 = 0; iVar7 = 3; iVar1 = 540; break; case 4: StringCopy(&Var2, "FEET_P0_0_4", 16); iVar6 = 0; iVar7 = 4; iVar1 = 580; break; case 5: StringCopy(&Var2, "FEET_P0_0_5", 16); iVar6 = 0; iVar7 = 5; iVar1 = 650; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; break; case 7: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; break; case 8: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 9: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 10: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 11: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 12: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 7; iVar7 = 0; bVar0 = true; break; case 13: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; break; case 14: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 15: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; bVar0 = true; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; bVar0 = true; break; case 18: StringCopy(&Var2, "FEET_P0_13_0", 16); iVar6 = 13; iVar7 = 0; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 14; iVar7 = 0; bVar0 = true; break; case 20: StringCopy(&Var2, "FEET_P0_15_0", 16); iVar6 = 15; iVar7 = 0; break; case 21: StringCopy(&Var2, "FEET_P0_15_1", 16); iVar6 = 15; iVar7 = 1; iVar1 = 64; break; case 22: StringCopy(&Var2, "FEET_P0_15_2", 16); iVar6 = 15; iVar7 = 2; iVar1 = 56; break; case 23: StringCopy(&Var2, "FEET_P0_15_3", 16); iVar6 = 15; iVar7 = 3; iVar1 = 69; break; case 24: StringCopy(&Var2, "FEET_P0_15_4", 16); iVar6 = 15; iVar7 = 4; iVar1 = 59; break; case 25: StringCopy(&Var2, "FEET_P0_15_5", 16); iVar6 = 15; iVar7 = 5; iVar1 = 62; break; case 26: StringCopy(&Var2, "FEET_P0_15_6", 16); iVar6 = 15; iVar7 = 6; iVar1 = 74; break; case 27: StringCopy(&Var2, "FEET_P0_15_7", 16); iVar6 = 15; iVar7 = 7; iVar1 = 68; break; case 28: StringCopy(&Var2, "FEET_P0_15_8", 16); iVar6 = 15; iVar7 = 8; iVar1 = 72; break; case 29: StringCopy(&Var2, "FEET_P0_15_9", 16); iVar6 = 15; iVar7 = 9; iVar1 = 70; break; case 30: StringCopy(&Var2, "FEET_P0_16_0", 16); iVar6 = 16; iVar7 = 0; iVar1 = 48; break; case 31: StringCopy(&Var2, "FEET_P0_16_1", 16); iVar6 = 16; iVar7 = 1; iVar1 = 48; break; case 32: StringCopy(&Var2, "FEET_P0_16_2", 16); iVar6 = 16; iVar7 = 2; iVar1 = 55; break; case 33: StringCopy(&Var2, "FEET_P0_16_3", 16); iVar6 = 16; iVar7 = 3; iVar1 = 75; break; case 34: StringCopy(&Var2, "FEET_P0_16_4", 16); iVar6 = 16; iVar7 = 4; iVar1 = 65; break; case 35: StringCopy(&Var2, "FEET_P0_16_5", 16); iVar6 = 16; iVar7 = 5; iVar1 = 68; break; case 36: StringCopy(&Var2, "FEET_P0_16_6", 16); iVar6 = 16; iVar7 = 6; iVar1 = 58; break; case 37: StringCopy(&Var2, "FEET_P0_16_7", 16); iVar6 = 16; iVar7 = 7; iVar1 = 68; break; case 38: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 0; bVar0 = true; break; case 39: StringCopy(&Var2, "FEET_P0_18_0", 16); iVar6 = 18; iVar7 = 0; iVar1 = 790; break; case 40: StringCopy(&Var2, "FEET_P0_18_1", 16); iVar6 = 18; iVar7 = 1; iVar1 = 750; break; case 41: StringCopy(&Var2, "FEET_P0_18_2", 16); iVar6 = 18; iVar7 = 2; iVar1 = 860; break; case 42: StringCopy(&Var2, "FEET_P0_18_3", 16); iVar6 = 18; iVar7 = 3; iVar1 = 750; break; case 43: StringCopy(&Var2, "FEET_P0_18_4", 16); iVar6 = 18; iVar7 = 4; iVar1 = 790; break; case 44: StringCopy(&Var2, "FEET_P0_18_5", 16); iVar6 = 18; iVar7 = 5; iVar1 = 840; break; case 45: StringCopy(&Var2, "FEET_P0_18_6", 16); iVar6 = 18; iVar7 = 6; iVar1 = 820; break; case 46: StringCopy(&Var2, "FEET_P0_18_7", 16); iVar6 = 18; iVar7 = 7; iVar1 = 800; break; case 47: StringCopy(&Var2, "FEET_P0_18_8", 16); iVar6 = 18; iVar7 = 8; iVar1 = 850; break; case 48: StringCopy(&Var2, "FEET_P0_18_9", 16); iVar6 = 18; iVar7 = 9; iVar1 = 870; break; case 49: StringCopy(&Var2, "FEET_P0_18_10", 16); iVar6 = 18; iVar7 = 10; iVar1 = 720; break; case 50: StringCopy(&Var2, "FEET_P0_18_11", 16); iVar6 = 18; iVar7 = 11; iVar1 = 740; break; case 51: StringCopy(&Var2, "FEET_P0_18_12", 16); iVar6 = 18; iVar7 = 12; iVar1 = 800; break; case 52: StringCopy(&Var2, "FEET_P0_18_13", 16); iVar6 = 18; iVar7 = 13; iVar1 = 750; break; case 53: StringCopy(&Var2, "FEET_P0_18_14", 16); iVar6 = 18; iVar7 = 14; iVar1 = 770; break; case 54: StringCopy(&Var2, "FEET_P0_18_15", 16); iVar6 = 18; iVar7 = 15; iVar1 = 860; break; case 55: StringCopy(&Var2, "FEET_P0_19_0", 16); iVar6 = 19; iVar7 = 0; iVar1 = 850; break; case 56: StringCopy(&Var2, "FEET_P0_19_1", 16); iVar6 = 19; iVar7 = 1; iVar1 = 800; break; case 57: StringCopy(&Var2, "FEET_P0_19_2", 16); iVar6 = 19; iVar7 = 2; iVar1 = 780; break; case 58: StringCopy(&Var2, "FEET_P0_19_3", 16); iVar6 = 19; iVar7 = 3; iVar1 = 890; break; case 59: StringCopy(&Var2, "FEET_P0_19_4", 16); iVar6 = 19; iVar7 = 4; iVar1 = 820; break; case 60: StringCopy(&Var2, "FEET_P0_19_5", 16); iVar6 = 19; iVar7 = 5; iVar1 = 840; break; case 61: StringCopy(&Var2, "FEET_P0_19_6", 16); iVar6 = 19; iVar7 = 6; iVar1 = 870; break; case 62: StringCopy(&Var2, "FEET_P0_19_7", 16); iVar6 = 19; iVar7 = 7; iVar1 = 930; break; case 63: StringCopy(&Var2, "FEET_P0_19_8", 16); iVar6 = 19; iVar7 = 8; iVar1 = 880; break; case 64: StringCopy(&Var2, "FEET_P0_19_9", 16); iVar6 = 19; iVar7 = 9; iVar1 = 900; break; case 65: StringCopy(&Var2, "FEET_P0_19_10", 16); iVar6 = 19; iVar7 = 10; iVar1 = 920; break; case 66: StringCopy(&Var2, "FEET_P0_19_11", 16); iVar6 = 19; iVar7 = 11; iVar1 = 970; break; case 67: StringCopy(&Var2, "FEET_P0_19_12", 16); iVar6 = 19; iVar7 = 12; iVar1 = 990; break; case 68: StringCopy(&Var2, "FEET_P0_19_13", 16); iVar6 = 19; iVar7 = 13; iVar1 = 960; break; case 69: StringCopy(&Var2, "FEET_P0_19_14", 16); iVar6 = 19; iVar7 = 14; iVar1 = 980; break; case 70: StringCopy(&Var2, "FEET_P0_19_15", 16); iVar6 = 19; iVar7 = 15; iVar1 = 950; break; case 71: StringCopy(&Var2, "FEET_P0_20_0", 16); iVar6 = 20; iVar7 = 0; iVar1 = 110; break; case 72: StringCopy(&Var2, "FEET_P0_20_1", 16); iVar6 = 20; iVar7 = 1; iVar1 = 115; break; case 73: StringCopy(&Var2, "FEET_P0_20_2", 16); iVar6 = 20; iVar7 = 2; iVar1 = 120; break; case 74: StringCopy(&Var2, "FEET_P0_20_3", 16); iVar6 = 20; iVar7 = 3; iVar1 = 110; break; case 75: StringCopy(&Var2, "FEET_P0_20_4", 16); iVar6 = 20; iVar7 = 4; iVar1 = 125; break; case 76: StringCopy(&Var2, "FEET_P0_20_5", 16); iVar6 = 20; iVar7 = 5; iVar1 = 128; break; case 77: StringCopy(&Var2, "FEET_P0_20_6", 16); iVar6 = 20; iVar7 = 6; iVar1 = 135; break; case 78: StringCopy(&Var2, "FEET_P0_20_7", 16); iVar6 = 20; iVar7 = 7; iVar1 = 130; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "FEET_P0_20_8", 16); iVar6 = 20; iVar7 = 8; iVar1 = 145; break; case 80: StringCopy(&Var2, "FEET_P0_20_9", 16); iVar6 = 20; iVar7 = 9; iVar1 = 110; break; case 81: StringCopy(&Var2, "FEET_P0_20_10", 16); iVar6 = 20; iVar7 = 10; iVar1 = 120; break; case 82: StringCopy(&Var2, "FEET_P0_20_11", 16); iVar6 = 20; iVar7 = 11; iVar1 = 150; break; case 83: StringCopy(&Var2, "FEET_P0_20_12", 16); iVar6 = 20; iVar7 = 12; iVar1 = 125; break; case 84: StringCopy(&Var2, "FEET_P0_20_13", 16); iVar6 = 20; iVar7 = 13; iVar1 = 120; break; case 85: StringCopy(&Var2, "FEET_P0_20_14", 16); iVar6 = 20; iVar7 = 14; iVar1 = 130; break; case 86: StringCopy(&Var2, "FEET_P0_20_15", 16); iVar6 = 20; iVar7 = 15; iVar1 = 110; break; case 87: StringCopy(&Var2, "FEET_P0_21_0", 16); iVar6 = 21; iVar7 = 0; iVar1 = 720; break; case 88: StringCopy(&Var2, "FEET_P0_21_1", 16); iVar6 = 21; iVar7 = 1; iVar1 = 680; break; case 89: StringCopy(&Var2, "FEET_P0_21_2", 16); iVar6 = 21; iVar7 = 2; iVar1 = 650; break; case 90: StringCopy(&Var2, "FEET_P0_21_3", 16); iVar6 = 21; iVar7 = 3; iVar1 = 670; break; case 91: StringCopy(&Var2, "FEET_P0_21_4", 16); iVar6 = 21; iVar7 = 4; iVar1 = 700; break; case 92: StringCopy(&Var2, "FEET_P0_21_5", 16); iVar6 = 21; iVar7 = 5; iVar1 = 680; break; case 93: StringCopy(&Var2, "FEET_P0_21_6", 16); iVar6 = 21; iVar7 = 6; iVar1 = 720; break; case 94: StringCopy(&Var2, "FEET_P0_21_7", 16); iVar6 = 21; iVar7 = 7; iVar1 = 740; break; case 95: StringCopy(&Var2, "FEET_P0_21_8", 16); iVar6 = 21; iVar7 = 8; iVar1 = 760; break; case 96: StringCopy(&Var2, "FEET_P0_21_9", 16); iVar6 = 21; iVar7 = 9; iVar1 = 780; break; case 97: StringCopy(&Var2, "FEET_P0_21_10", 16); iVar6 = 21; iVar7 = 10; iVar1 = 750; break; case 98: StringCopy(&Var2, "FEET_P0_21_11", 16); iVar6 = 21; iVar7 = 11; iVar1 = 700; break; default: func_163(iVar10, iParam0, 99, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_211(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 4; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "LEGS_P0_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "LEGS_P0_0_0", 16); iVar6 = 0; iVar7 = 1; break; case 2: StringCopy(&Var2, "LEGS_P0_0_2", 16); iVar6 = 0; iVar7 = 2; break; case 3: StringCopy(&Var2, "LEGS_P0_0_3", 16); iVar6 = 0; iVar7 = 3; break; case 4: StringCopy(&Var2, "LEGS_P0_0_4", 16); iVar6 = 0; iVar7 = 4; break; case 5: StringCopy(&Var2, "LEGS_P0_0_5", 16); iVar6 = 0; iVar7 = 5; break; case 6: StringCopy(&Var2, "LEGS_P0_0_6", 16); iVar6 = 0; iVar7 = 6; break; case 7: StringCopy(&Var2, "LEGS_P0_0_7", 16); iVar6 = 0; iVar7 = 7; break; case 8: StringCopy(&Var2, "LEGS_P0_0_8", 16); iVar6 = 0; iVar7 = 8; break; case 9: StringCopy(&Var2, "LEGS_P0_0_9", 16); iVar6 = 0; iVar7 = 9; break; case 10: StringCopy(&Var2, "LEGS_P0_0_10", 16); iVar6 = 0; iVar7 = 10; break; case 11: StringCopy(&Var2, "LEGS_P0_0_11", 16); iVar6 = 0; iVar7 = 11; break; case 12: StringCopy(&Var2, "LEGS_P0_0_12", 16); iVar6 = 0; iVar7 = 12; break; case 13: StringCopy(&Var2, "LEGS_P0_0_13", 16); iVar6 = 0; iVar7 = 13; break; case 14: StringCopy(&Var2, "LEGS_P0_0_14", 16); iVar6 = 0; iVar7 = 14; break; case 15: StringCopy(&Var2, "LEGS_P0_0_15", 16); iVar6 = 0; iVar7 = 15; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; bVar0 = true; break; case 18: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 1; bVar0 = true; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 21: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 22: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 23: StringCopy(&Var2, "LEGS_P0_7_0", 16); iVar6 = 7; iVar7 = 0; iVar1 = 115; break; case 24: StringCopy(&Var2, "LEGS_P0_7_1", 16); iVar6 = 7; iVar7 = 1; iVar1 = 115; break; case 25: StringCopy(&Var2, "LEGS_P0_7_2", 16); iVar6 = 7; iVar7 = 2; iVar1 = 128; break; case 26: StringCopy(&Var2, "LEGS_P0_7_3", 16); iVar6 = 7; iVar7 = 3; iVar1 = 118; break; case 27: StringCopy(&Var2, "LEGS_P0_7_4", 16); iVar6 = 7; iVar7 = 4; iVar1 = 125; break; case 28: StringCopy(&Var2, "LEGS_P0_7_5", 16); iVar6 = 7; iVar7 = 5; iVar1 = 128; break; case 29: StringCopy(&Var2, "LEGS_P0_7_6", 16); iVar6 = 7; iVar7 = 6; iVar1 = 128; break; case 30: StringCopy(&Var2, "LEGS_P0_7_7", 16); iVar6 = 7; iVar7 = 7; iVar1 = 125; break; case 31: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 8; iVar7 = 0; bVar0 = true; break; case 32: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 33: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 34: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; bVar0 = true; break; case 35: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 1; bVar0 = true; break; case 36: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 2; bVar0 = true; break; case 37: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 3; bVar0 = true; break; case 38: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 4; bVar0 = true; break; case 39: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 5; bVar0 = true; break; case 40: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; bVar0 = true; break; case 41: StringCopy(&Var2, "LEGS_P0_13_0", 16); iVar6 = 13; iVar7 = 0; iVar1 = 68; break; case 42: StringCopy(&Var2, "LEGS_P0_13_1", 16); iVar6 = 13; iVar7 = 1; iVar1 = 68; break; case 43: StringCopy(&Var2, "LEGS_P0_13_2", 16); iVar6 = 13; iVar7 = 2; iVar1 = 68; break; case 44: StringCopy(&Var2, "LEGS_P0_13_3", 16); iVar6 = 13; iVar7 = 3; iVar1 = 68; break; case 45: StringCopy(&Var2, "LEGS_P0_13_4", 16); iVar6 = 13; iVar7 = 4; iVar1 = 68; break; case 46: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 14; iVar7 = 0; bVar0 = true; break; case 47: StringCopy(&Var2, "LEGS_P0_15_0", 16); iVar6 = 15; iVar7 = 0; break; case 48: StringCopy(&Var2, "LEGS_P0_15_1", 16); iVar6 = 15; iVar7 = 1; iVar1 = 550; break; case 49: StringCopy(&Var2, "LEGS_P0_15_2", 16); iVar6 = 15; iVar7 = 2; iVar1 = 650; break; case 50: StringCopy(&Var2, "LEGS_P0_15_3", 16); iVar6 = 15; iVar7 = 3; iVar1 = 875; break; case 51: StringCopy(&Var2, "LEGS_P0_15_4", 16); iVar6 = 15; iVar7 = 4; iVar1 = 820; break; case 52: StringCopy(&Var2, "LEGS_P0_15_5", 16); iVar6 = 15; iVar7 = 5; iVar1 = 720; break; case 53: StringCopy(&Var2, "LEGS_P0_15_6", 16); iVar6 = 15; iVar7 = 6; iVar1 = 750; break; case 54: StringCopy(&Var2, "LEGS_P0_15_7", 16); iVar6 = 15; iVar7 = 7; iVar1 = 850; break; case 55: StringCopy(&Var2, "LEGS_P0_16_0", 16); iVar6 = 16; iVar7 = 0; break; case 56: StringCopy(&Var2, "LEGS_P0_16_1", 16); iVar6 = 16; iVar7 = 1; iVar1 = 48; break; case 57: StringCopy(&Var2, "LEGS_P0_16_2", 16); iVar6 = 16; iVar7 = 2; iVar1 = 48; break; case 58: StringCopy(&Var2, "LEGS_P0_16_3", 16); iVar6 = 16; iVar7 = 3; iVar1 = 38; break; case 59: StringCopy(&Var2, "LEGS_P0_16_4", 16); iVar6 = 16; iVar7 = 4; iVar1 = 38; break; case 60: StringCopy(&Var2, "LEGS_P0_16_5", 16); iVar6 = 16; iVar7 = 5; iVar1 = 42; break; case 61: StringCopy(&Var2, "LEGS_P0_16_6", 16); iVar6 = 16; iVar7 = 6; iVar1 = 58; break; case 62: StringCopy(&Var2, "LEGS_P0_16_7", 16); iVar6 = 16; iVar7 = 7; iVar1 = 46; break; case 63: StringCopy(&Var2, "LEGS_P0_16_8", 16); iVar6 = 16; iVar7 = 8; iVar1 = 46; break; case 64: StringCopy(&Var2, "LEGS_P0_16_9", 16); iVar6 = 16; iVar7 = 9; iVar1 = 46; break; case 65: StringCopy(&Var2, "LEGS_P0_16_10", 16); iVar6 = 16; iVar7 = 10; iVar1 = 68; break; case 66: StringCopy(&Var2, "LEGS_P0_16_11", 16); iVar6 = 16; iVar7 = 11; iVar1 = 58; break; case 67: StringCopy(&Var2, "LEGS_P0_16_12", 16); iVar6 = 16; iVar7 = 12; iVar1 = 50; break; case 68: StringCopy(&Var2, "LEGS_P0_16_13", 16); iVar6 = 16; iVar7 = 13; iVar1 = 68; break; case 69: StringCopy(&Var2, "LEGS_P0_16_14", 16); iVar6 = 16; iVar7 = 14; iVar1 = 68; break; case 70: StringCopy(&Var2, "LEGS_P0_16_15", 16); iVar6 = 16; iVar7 = 15; iVar1 = 42; break; case 71: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 17; iVar7 = 0; bVar0 = true; break; case 72: StringCopy(&Var2, "LEGS_P0_18_0", 16); iVar6 = 18; iVar7 = 0; break; case 73: StringCopy(&Var2, "LEGS_P0_18_1", 16); iVar6 = 18; iVar7 = 1; iVar1 = 250; break; case 74: StringCopy(&Var2, "LEGS_P0_18_2", 16); iVar6 = 18; iVar7 = 2; iVar1 = 250; break; case 75: StringCopy(&Var2, "LEGS_P0_18_3", 16); iVar6 = 18; iVar7 = 3; iVar1 = 290; break; case 76: StringCopy(&Var2, "LEGS_P0_18_4", 16); iVar6 = 18; iVar7 = 4; iVar1 = 270; break; case 77: StringCopy(&Var2, "LEGS_P0_18_5", 16); iVar6 = 18; iVar7 = 5; iVar1 = 270; break; case 78: StringCopy(&Var2, "LEGS_P0_18_6", 16); iVar6 = 18; iVar7 = 6; iVar1 = 15; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "LEGS_P0_18_7", 16); iVar6 = 18; iVar7 = 7; iVar1 = 12; break; case 80: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 19; iVar7 = 0; bVar0 = true; break; case 81: StringCopy(&Var2, "LEGS_P0_20_0", 16); iVar6 = 20; iVar7 = 0; break; case 82: StringCopy(&Var2, "LEGS_P0_20_1", 16); iVar6 = 20; iVar7 = 1; iVar1 = 118; break; case 83: StringCopy(&Var2, "LEGS_P0_20_2", 16); iVar6 = 20; iVar7 = 2; iVar1 = 110; break; case 84: StringCopy(&Var2, "LEGS_P0_21_0", 16); iVar6 = 21; iVar7 = 0; iVar1 = 88; break; case 85: StringCopy(&Var2, "LEGS_P0_21_1", 16); iVar6 = 21; iVar7 = 1; iVar1 = 95; break; case 86: StringCopy(&Var2, "LEGS_P0_21_2", 16); iVar6 = 21; iVar7 = 2; iVar1 = 95; break; case 87: StringCopy(&Var2, "LEGS_P0_21_3", 16); iVar6 = 21; iVar7 = 3; iVar1 = 98; break; case 88: StringCopy(&Var2, "LEGS_P0_22_0", 16); iVar6 = 22; iVar7 = 0; iVar1 = 140; break; case 89: StringCopy(&Var2, "LEGS_P0_23_0", 16); iVar6 = 23; iVar7 = 0; break; case 90: StringCopy(&Var2, "LEGS_P0_23_1", 16); iVar6 = 23; iVar7 = 1; iVar1 = 150; break; case 91: StringCopy(&Var2, "LEGS_P0_23_2", 16); iVar6 = 23; iVar7 = 2; iVar1 = 130; break; case 92: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 24; iVar7 = 0; bVar0 = true; break; case 93: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 25; iVar7 = 0; bVar0 = true; break; case 94: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 26; iVar7 = 0; bVar0 = true; break; case 95: StringCopy(&Var2, "LEGS_P0_27_0", 16); iVar6 = 27; iVar7 = 0; break; case 96: StringCopy(&Var2, "LEGS_P0_28_0", 16); iVar6 = 28; iVar7 = 0; iVar1 = 45; break; case 97: StringCopy(&Var2, "LEGS_P0_28_1", 16); iVar6 = 28; iVar7 = 1; iVar1 = 48; break; case 98: StringCopy(&Var2, "LEGS_P0_28_2", 16); iVar6 = 28; iVar7 = 2; iVar1 = 48; break; case 99: StringCopy(&Var2, "LEGS_P0_28_3", 16); iVar6 = 28; iVar7 = 3; iVar1 = 52; break; case 100: StringCopy(&Var2, "LEGS_P0_28_4", 16); iVar6 = 28; iVar7 = 4; iVar1 = 52; break; case 101: StringCopy(&Var2, "LEGS_P0_28_5", 16); iVar6 = 28; iVar7 = 5; iVar1 = 55; break; case 102: StringCopy(&Var2, "LEGS_P0_28_6", 16); iVar6 = 28; iVar7 = 6; iVar1 = 55; break; case 103: StringCopy(&Var2, "LEGS_P0_28_7", 16); iVar6 = 28; iVar7 = 7; iVar1 = 55; break; case 104: StringCopy(&Var2, "LEGS_P0_28_8", 16); iVar6 = 28; iVar7 = 8; iVar1 = 58; break; case 105: StringCopy(&Var2, "LEGS_P0_28_9", 16); iVar6 = 28; iVar7 = 9; iVar1 = 58; break; case 106: StringCopy(&Var2, "LEGS_P0_28_10", 16); iVar6 = 28; iVar7 = 10; iVar1 = 60; break; case 107: StringCopy(&Var2, "LEGS_P0_28_11", 16); iVar6 = 28; iVar7 = 11; iVar1 = 60; break; case 108: StringCopy(&Var2, "LEGS_P0_28_12", 16); iVar6 = 28; iVar7 = 12; iVar1 = 62; break; case 109: StringCopy(&Var2, "LEGS_P0_28_13", 16); iVar6 = 28; iVar7 = 13; iVar1 = 62; break; case 110: StringCopy(&Var2, "LEGS_P0_28_14", 16); iVar6 = 28; iVar7 = 14; iVar1 = 65; break; case 111: StringCopy(&Var2, "LEGS_P0_28_15", 16); iVar6 = 28; iVar7 = 15; iVar1 = 65; break; case 112: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 29; iVar7 = 0; break; default: func_163(iVar10, iParam0, 113, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_212(int iParam0) { if (iParam0 < 60) { func_214(iParam0); } else { func_213(iParam0); } if (Global_76647[0 /*14*/].f_2 == -1) { func_163(3, iParam0, 181, -1); } } void func_213(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 3; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 60: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 9; iVar7 = 0; bVar0 = true; break; case 61: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 10; iVar7 = 0; bVar0 = true; break; case 62: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 11; iVar7 = 0; bVar0 = true; break; case 63: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 0; bVar0 = true; break; case 64: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 1; bVar0 = true; break; case 65: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 2; bVar0 = true; break; case 66: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 3; bVar0 = true; break; case 67: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 4; bVar0 = true; break; case 68: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 12; iVar7 = 5; bVar0 = true; break; case 69: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 13; iVar7 = 0; bVar0 = true; break; case 70: StringCopy(&Var2, "TORSO_P0_14_0", 16); iVar6 = 14; iVar7 = 0; iVar1 = 120; break; case 71: StringCopy(&Var2, "TORSO_P0_14_1", 16); iVar6 = 14; iVar7 = 1; iVar1 = 120; break; case 72: StringCopy(&Var2, "TORSO_P0_14_2", 16); iVar6 = 14; iVar7 = 2; iVar1 = 120; break; case 73: StringCopy(&Var2, "TORSO_P0_14_3", 16); iVar6 = 14; iVar7 = 3; iVar1 = 120; break; case 74: StringCopy(&Var2, "TORSO_P0_14_4", 16); iVar6 = 14; iVar7 = 4; iVar1 = 120; break; case 75: StringCopy(&Var2, "TORSO_P0_14_5", 16); iVar6 = 14; iVar7 = 5; iVar1 = 120; break; case 76: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 15; iVar7 = 0; bVar0 = true; break; case 77: StringCopy(&Var2, "TORSO_P0_16_0", 16); iVar6 = 16; iVar7 = 0; break; case 78: StringCopy(&Var2, "TORSO_P0_16_1", 16); iVar6 = 16; iVar7 = 1; iVar1 = 20; break; case joaat("MPSV_LP0_31"): StringCopy(&Var2, "TORSO_P0_16_2", 16); iVar6 = 16; iVar7 = 2; iVar1 = 24; break; case 80: StringCopy(&Var2, "TORSO_P0_16_3", 16); iVar6 = 16; iVar7 = 3; iVar1 = 22; break; case 81: StringCopy(&Var2, "TORSO_P0_16_4", 16); iVar6 = 16; iVar7 = 4; iVar1 = 25; break; case 82: StringCopy(&Var2, "TORSO_P0_16_5", 16); iVar6 = 16; iVar7 = 5; iVar1 = 25; break; case 83: StringCopy(&Var2, "TORSO_P0_16_6", 16); iVar6 = 16; iVar7 = 6; iVar1 = 22; break; case 84: StringCopy(&Var2, "TORSO_P0_16_7", 16); iVar6 = 16; iVar7 = 7; iVar1 = 27; break; case 85: StringCopy(&Var2, "TORSO_P0_17_0", 16); iVar6 = 17; iVar7 = 0; break; case 86: StringCopy(&Var2, "TORSO_P0_17_1", 16); iVar6 = 17; iVar7 = 1; break; case 87: StringCopy(&Var2, "TORSO_P0_17_2", 16); iVar6 = 17; iVar7 = 2; break; case 88: StringCopy(&Var2, "TORSO_P0_17_3", 16); iVar6 = 17; iVar7 = 3; iVar1 = 48; break; case 89: StringCopy(&Var2, "TORSO_P0_17_4", 16); iVar6 = 17; iVar7 = 4; iVar1 = 40; break; case 90: StringCopy(&Var2, "TORSO_P0_17_5", 16); iVar6 = 17; iVar7 = 5; iVar1 = 45; break; case 91: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 18; iVar7 = 0; bVar0 = true; break; case 92: StringCopy(&Var2, "TORSO_P0_19_0", 16); iVar6 = 19; iVar7 = 0; break; case 93: StringCopy(&Var2, "TORSO_P0_19_1", 16); iVar6 = 19; iVar7 = 1; iVar1 = 190; break; case 94: StringCopy(&Var2, "TORSO_P0_19_2", 16); iVar6 = 19; iVar7 = 2; iVar1 = 190; break; case 95: StringCopy(&Var2, "TORSO_P0_19_3", 16); iVar6 = 19; iVar7 = 3; iVar1 = 190; break; case 96: StringCopy(&Var2, "TORSO_P0_19_4", 16); iVar6 = 19; iVar7 = 4; iVar1 = 210; break; case 97: StringCopy(&Var2, "TORSO_P0_20_0", 16); iVar6 = 20; iVar7 = 0; break; case 98: StringCopy(&Var2, "TORSO_P0_20_1", 16); iVar6 = 20; iVar7 = 1; iVar1 = 115; break; case 99: StringCopy(&Var2, "TORSO_P0_20_2", 16); iVar6 = 20; iVar7 = 2; iVar1 = 55; break; case 100: StringCopy(&Var2, "TORSO_P0_20_3", 16); iVar6 = 20; iVar7 = 3; iVar1 = 110; break; case 101: StringCopy(&Var2, "TORSO_P0_20_4", 16); iVar6 = 20; iVar7 = 4; iVar1 = 99; break; case 102: StringCopy(&Var2, "TORSO_P0_20_5", 16); iVar6 = 20; iVar7 = 5; iVar1 = 49; break; case 103: StringCopy(&Var2, "TORSO_P0_20_6", 16); iVar6 = 20; iVar7 = 6; iVar1 = 120; break; case 104: StringCopy(&Var2, "TORSO_P0_20_7", 16); iVar6 = 20; iVar7 = 7; iVar1 = 45; break; case 105: StringCopy(&Var2, "TORSO_P0_20_8", 16); iVar6 = 20; iVar7 = 8; iVar1 = 115; break; case 106: StringCopy(&Var2, "TORSO_P0_20_9", 16); iVar6 = 20; iVar7 = 9; iVar1 = 105; break; case 107: StringCopy(&Var2, "TORSO_P0_20_10", 16); iVar6 = 20; iVar7 = 10; iVar1 = 90; break; case 108: StringCopy(&Var2, "TORSO_P0_20_11", 16); iVar6 = 20; iVar7 = 11; iVar1 = 95; break; case 109: StringCopy(&Var2, "TORSO_P0_20_12", 16); iVar6 = 20; iVar7 = 12; iVar1 = 39; break; case 110: StringCopy(&Var2, "TORSO_P0_20_13", 16); iVar6 = 20; iVar7 = 13; iVar1 = 95; break; case 111: StringCopy(&Var2, "TORSO_P0_20_14", 16); iVar6 = 20; iVar7 = 14; iVar1 = 35; break; case 112: StringCopy(&Var2, "TORSO_P0_20_15", 16); iVar6 = 20; iVar7 = 15; iVar1 = 95; break; case 113: StringCopy(&Var2, "TORSO_P0_21_0", 16); iVar6 = 21; iVar7 = 0; iVar1 = 88; break; case 114: StringCopy(&Var2, "TORSO_P0_21_1", 16); iVar6 = 21; iVar7 = 1; iVar1 = 60; break; case 115: StringCopy(&Var2, "TORSO_P0_21_2", 16); iVar6 = 21; iVar7 = 2; iVar1 = 70; break; case 116: StringCopy(&Var2, "TORSO_P0_21_3", 16); iVar6 = 21; iVar7 = 3; iVar1 = 80; break; case 117: StringCopy(&Var2, "TORSO_P0_21_4", 16); iVar6 = 21; iVar7 = 4; iVar1 = 90; break; case 118: StringCopy(&Var2, "TORSO_P0_21_5", 16); iVar6 = 21; iVar7 = 5; iVar1 = 80; break; case 119: StringCopy(&Var2, "TORSO_P0_21_6", 16); iVar6 = 21; iVar7 = 6; iVar1 = 70; break; case 120: StringCopy(&Var2, "TORSO_P0_21_7", 16); iVar6 = 21; iVar7 = 7; iVar1 = 95; break; case 121: StringCopy(&Var2, "TORSO_P0_21_8", 16); iVar6 = 21; iVar7 = 8; iVar1 = 105; break; case 122: StringCopy(&Var2, "TORSO_P0_21_9", 16); iVar6 = 21; iVar7 = 9; iVar1 = 95; break; case 123: StringCopy(&Var2, "TORSO_P0_21_10", 16); iVar6 = 21; iVar7 = 10; iVar1 = 110; break; case 124: StringCopy(&Var2, "TORSO_P0_21_11", 16); iVar6 = 21; iVar7 = 11; iVar1 = 98; break; case 125: StringCopy(&Var2, "TORSO_P0_21_12", 16); iVar6 = 21; iVar7 = 12; iVar1 = 88; break; case 126: StringCopy(&Var2, "TORSO_P0_21_13", 16); iVar6 = 21; iVar7 = 13; iVar1 = 98; break; case 127: StringCopy(&Var2, "TORSO_P0_21_14", 16); iVar6 = 21; iVar7 = 14; iVar1 = 110; break; case 128: StringCopy(&Var2, "TORSO_P0_21_15", 16); iVar6 = 21; iVar7 = 15; iVar1 = 98; break; case 129: StringCopy(&Var2, "TORSO_P0_22_0", 16); iVar6 = 22; iVar7 = 0; break; case 130: StringCopy(&Var2, "TORSO_P0_22_1", 16); iVar6 = 22; iVar7 = 1; iVar1 = 4950; break; case 131: StringCopy(&Var2, "TORSO_P0_22_2", 16); iVar6 = 22; iVar7 = 2; iVar1 = 4195; break; case 132: StringCopy(&Var2, "TORSO_P0_22_3", 16); iVar6 = 22; iVar7 = 3; iVar1 = 3195; break; case 133: StringCopy(&Var2, "TORSO_P0_22_4", 16); iVar6 = 22; iVar7 = 4; iVar1 = 2950; break; case 134: StringCopy(&Var2, "TORSO_P0_22_5", 16); iVar6 = 22; iVar7 = 5; iVar1 = 3950; break; case 135: StringCopy(&Var2, "TORSO_P0_23_0", 16); iVar6 = 23; iVar7 = 0; iVar1 = 3200; break; case 136: StringCopy(&Var2, "TORSO_P0_23_1", 16); iVar6 = 23; iVar7 = 1; iVar1 = 3200; break; case 137: StringCopy(&Var2, "TORSO_P0_23_2", 16); iVar6 = 23; iVar7 = 2; iVar1 = 3200; break; case 138: StringCopy(&Var2, "TORSO_P0_23_3", 16); iVar6 = 23; iVar7 = 3; iVar1 = 3200; break; case 139: StringCopy(&Var2, "TORSO_P0_23_4", 16); iVar6 = 23; iVar7 = 4; iVar1 = 3200; break; case 140: StringCopy(&Var2, "TORSO_P0_23_5", 16); iVar6 = 23; iVar7 = 5; iVar1 = 3200; break; case 141: StringCopy(&Var2, "TORSO_P0_23_6", 16); iVar6 = 23; iVar7 = 6; iVar1 = 3200; break; case 142: StringCopy(&Var2, "TORSO_P0_23_7", 16); iVar6 = 23; iVar7 = 7; iVar1 = 3200; break; case 143: StringCopy(&Var2, "TORSO_P0_23_8", 16); iVar6 = 23; iVar7 = 8; iVar1 = 3200; break; case 144: StringCopy(&Var2, "TORSO_P0_23_9", 16); iVar6 = 23; iVar7 = 9; iVar1 = 3200; break; case 145: StringCopy(&Var2, "TORSO_P0_23_10", 16); iVar6 = 23; iVar7 = 10; iVar1 = 3200; break; case 146: StringCopy(&Var2, "TORSO_P0_23_11", 16); iVar6 = 23; iVar7 = 11; iVar1 = 3200; break; case 147: StringCopy(&Var2, "TORSO_P0_23_12", 16); iVar6 = 23; iVar7 = 12; iVar1 = 3200; break; case 148: StringCopy(&Var2, "TORSO_P0_23_13", 16); iVar6 = 23; iVar7 = 13; iVar1 = 3200; break; case 149: StringCopy(&Var2, "TORSO_P0_23_14", 16); iVar6 = 23; iVar7 = 14; iVar1 = 3200; break; case 150: StringCopy(&Var2, "TORSO_P0_23_15", 16); iVar6 = 23; iVar7 = 15; iVar1 = 3200; break; case 151: StringCopy(&Var2, "TORSO_P0_24_0", 16); iVar6 = 24; iVar7 = 0; iVar1 = 1350; break; case 152: StringCopy(&Var2, "TORSO_P0_24_1", 16); iVar6 = 24; iVar7 = 1; iVar1 = 1400; break; case 153: StringCopy(&Var2, "TORSO_P0_24_2", 16); iVar6 = 24; iVar7 = 2; iVar1 = 1200; break; case 154: StringCopy(&Var2, "TORSO_P0_24_3", 16); iVar6 = 24; iVar7 = 3; iVar1 = 1250; break; case 155: StringCopy(&Var2, "TORSO_P0_24_4", 16); iVar6 = 24; iVar7 = 4; iVar1 = 1350; break; case 156: StringCopy(&Var2, "TORSO_P0_24_5", 16); iVar6 = 24; iVar7 = 5; iVar1 = 1300; break; case 157: StringCopy(&Var2, "TORSO_P0_24_6", 16); iVar6 = 24; iVar7 = 6; iVar1 = 1380; break; case 158: StringCopy(&Var2, "TORSO_P0_24_7", 16); iVar6 = 24; iVar7 = 7; iVar1 = 1340; break; case 159: StringCopy(&Var2, "TORSO_P0_24_8", 16); iVar6 = 24; iVar7 = 8; iVar1 = 1380; break; case 160: StringCopy(&Var2, "TORSO_P0_24_9", 16); iVar6 = 24; iVar7 = 9; iVar1 = 1250; break; case 161: StringCopy(&Var2, "TORSO_P0_25_0", 16); iVar6 = 25; iVar7 = 0; iVar1 = 840; break; case 162: StringCopy(&Var2, "TORSO_P0_25_1", 16); iVar6 = 25; iVar7 = 1; iVar1 = 840; break; case 163: StringCopy(&Var2, "TORSO_P0_25_2", 16); iVar6 = 25; iVar7 = 2; iVar1 = 840; break; case 164: StringCopy(&Var2, "TORSO_P0_25_3", 16); iVar6 = 25; iVar7 = 3; iVar1 = 840; break; case 165: StringCopy(&Var2, "TORSO_P0_25_4", 16); iVar6 = 25; iVar7 = 4; iVar1 = 840; break; case 166: StringCopy(&Var2, "TORSO_P0_25_5", 16); iVar6 = 25; iVar7 = 5; iVar1 = 840; break; case 167: StringCopy(&Var2, "TORSO_P0_25_6", 16); iVar6 = 25; iVar7 = 6; iVar1 = 840; break; case 168: StringCopy(&Var2, "TORSO_P0_25_7", 16); iVar6 = 25; iVar7 = 7; iVar1 = 840; break; case 169: StringCopy(&Var2, "TORSO_P0_26_0", 16); iVar6 = 26; iVar7 = 0; break; case 170: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 27; iVar7 = 0; bVar0 = true; break; case 171: StringCopy(&Var2, "TORSO_P0_28_0", 16); iVar6 = 28; iVar7 = 0; break; case 172: StringCopy(&Var2, "TORSO_P0_28_1", 16); iVar6 = 28; iVar7 = 1; iVar1 = 130; break; case 173: StringCopy(&Var2, "TORSO_P0_28_2", 16); iVar6 = 28; iVar7 = 2; iVar1 = 110; break; case 174: StringCopy(&Var2, "TORSO_P0_29_0", 16); iVar6 = 29; iVar7 = 0; bVar0 = true; break; case 175: StringCopy(&Var2, "TORSO_P0_30_0", 16); iVar6 = 30; iVar7 = 0; iVar1 = 290; break; case 176: StringCopy(&Var2, "TORSO_P0_30_1", 16); iVar6 = 30; iVar7 = 1; iVar1 = 320; break; case 177: StringCopy(&Var2, "TORSO_P0_31_0", 16); iVar6 = 31; iVar7 = 0; iVar1 = 59; break; case 178: StringCopy(&Var2, "TORSO_P0_31_1", 16); iVar6 = 31; iVar7 = 1; iVar1 = 55; break; case 179: StringCopy(&Var2, "TORSO_P0_31_2", 16); iVar6 = 31; iVar7 = 2; iVar1 = 59; break; case 180: StringCopy(&Var2, "TORSO_P0_31_3", 16); iVar6 = 31; iVar7 = 3; iVar1 = 49; break; default: return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_214(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 3; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "TORSO_P0_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "TORSO_P0_0_0", 16); iVar6 = 0; iVar7 = 1; break; case 2: StringCopy(&Var2, "TORSO_P0_0_2", 16); iVar6 = 0; iVar7 = 2; iVar1 = 3500; break; case 3: StringCopy(&Var2, "TORSO_P0_0_3", 16); iVar6 = 0; iVar7 = 3; break; case 4: StringCopy(&Var2, "TORSO_P0_0_4", 16); iVar6 = 0; iVar7 = 4; break; case 5: StringCopy(&Var2, "TORSO_P0_0_5", 16); iVar6 = 0; iVar7 = 5; break; case 6: StringCopy(&Var2, "TORSO_P0_0_6", 16); iVar6 = 0; iVar7 = 6; break; case 7: StringCopy(&Var2, "TORSO_P0_0_7", 16); iVar6 = 0; iVar7 = 7; break; case 8: StringCopy(&Var2, "TORSO_P0_0_8", 16); iVar6 = 0; iVar7 = 8; break; case 9: StringCopy(&Var2, "TORSO_P0_0_9", 16); iVar6 = 0; iVar7 = 9; break; case 10: StringCopy(&Var2, "TORSO_P0_0_10", 16); iVar6 = 0; iVar7 = 10; break; case 11: StringCopy(&Var2, "TORSO_P0_0_11", 16); iVar6 = 0; iVar7 = 11; break; case 12: StringCopy(&Var2, "TORSO_P0_0_12", 16); iVar6 = 0; iVar7 = 12; break; case 13: StringCopy(&Var2, "TORSO_P0_0_13", 16); iVar6 = 0; iVar7 = 13; break; case 14: StringCopy(&Var2, "TORSO_P0_0_14", 16); iVar6 = 0; iVar7 = 14; break; case 15: StringCopy(&Var2, "TORSO_P0_0_15", 16); iVar6 = 0; iVar7 = 15; break; case 16: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 1; iVar7 = 0; bVar0 = true; break; case 17: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 0; iVar1 = 20; break; case 18: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 1; iVar1 = 18; break; case 19: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 2; iVar1 = 22; break; case 20: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 2; iVar7 = 3; iVar1 = 25; break; case 21: StringCopy(&Var2, "TORSO_P0_2_4", 16); iVar6 = 2; iVar7 = 4; iVar1 = 19; break; case 22: StringCopy(&Var2, "TORSO_P0_2_5", 16); iVar6 = 2; iVar7 = 5; iVar1 = 20; break; case 23: StringCopy(&Var2, "TORSO_P0_2_6", 16); iVar6 = 2; iVar7 = 6; iVar1 = 22; break; case 24: StringCopy(&Var2, "TORSO_P0_2_7", 16); iVar6 = 2; iVar7 = 7; iVar1 = 18; break; case 25: StringCopy(&Var2, "TORSO_P0_2_8", 16); iVar6 = 2; iVar7 = 8; iVar1 = 39; break; case 26: StringCopy(&Var2, "TORSO_P0_2_9", 16); iVar6 = 2; iVar7 = 9; iVar1 = 32; break; case 27: StringCopy(&Var2, "TORSO_P0_2_10", 16); iVar6 = 2; iVar7 = 10; iVar1 = 35; break; case 28: StringCopy(&Var2, "TORSO_P0_2_11", 16); iVar6 = 2; iVar7 = 11; iVar1 = 35; break; case 29: StringCopy(&Var2, "TORSO_P0_2_12", 16); iVar6 = 2; iVar7 = 12; iVar1 = 210; break; case 30: StringCopy(&Var2, "TORSO_P0_2_13", 16); iVar6 = 2; iVar7 = 13; iVar1 = 250; break; case 31: StringCopy(&Var2, "TORSO_P0_2_14", 16); iVar6 = 2; iVar7 = 14; iVar1 = 290; break; case 32: StringCopy(&Var2, "TORSO_P0_2_15", 16); iVar6 = 2; iVar7 = 15; iVar1 = 310; break; case 33: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 0; bVar0 = true; break; case 34: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 3; iVar7 = 1; bVar0 = true; break; case 35: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 4; iVar7 = 0; bVar0 = true; break; case 36: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; bVar0 = true; break; case 37: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 6; iVar7 = 0; bVar0 = true; break; case 38: StringCopy(&Var2, "TORSO_P0_7_0", 16); iVar6 = 7; iVar7 = 0; iVar1 = 150; break; case 39: StringCopy(&Var2, "TORSO_P0_7_1", 16); iVar6 = 7; iVar7 = 1; iVar1 = 160; break; case 40: StringCopy(&Var2, "TORSO_P0_7_2", 16); iVar6 = 7; iVar7 = 2; iVar1 = 150; break; case 41: StringCopy(&Var2, "TORSO_P0_7_3", 16); iVar6 = 7; iVar7 = 3; iVar1 = 150; break; case 42: StringCopy(&Var2, "TORSO_P0_7_4", 16); iVar6 = 7; iVar7 = 4; iVar1 = 160; break; case 43: StringCopy(&Var2, "TORSO_P0_7_5", 16); iVar6 = 7; iVar7 = 5; iVar1 = 160; break; case 44: StringCopy(&Var2, "TORSO_P0_8_0", 16); iVar6 = 8; iVar7 = 0; break; case 45: StringCopy(&Var2, "TORSO_P0_8_1", 16); iVar6 = 8; iVar7 = 1; iVar1 = 52; break; case 46: StringCopy(&Var2, "TORSO_P0_8_2", 16); iVar6 = 8; iVar7 = 2; iVar1 = 52; break; case 47: StringCopy(&Var2, "TORSO_P0_8_3", 16); iVar6 = 8; iVar7 = 3; iVar1 = 55; break; case 48: StringCopy(&Var2, "TORSO_P0_8_4", 16); iVar6 = 8; iVar7 = 4; iVar1 = 55; break; case 49: StringCopy(&Var2, "TORSO_P0_8_5", 16); iVar6 = 8; iVar7 = 5; iVar1 = 58; break; case 50: StringCopy(&Var2, "TORSO_P0_8_6", 16); iVar6 = 8; iVar7 = 6; iVar1 = 58; break; case 51: StringCopy(&Var2, "TORSO_P0_8_7", 16); iVar6 = 8; iVar7 = 7; iVar1 = 62; break; case 52: StringCopy(&Var2, "TORSO_P0_8_8", 16); iVar6 = 8; iVar7 = 8; iVar1 = 65; break; case 53: StringCopy(&Var2, "TORSO_P0_8_9", 16); iVar6 = 8; iVar7 = 9; iVar1 = 65; break; case 54: StringCopy(&Var2, "TORSO_P0_8_10", 16); iVar6 = 8; iVar7 = 10; iVar1 = 68; break; case 55: StringCopy(&Var2, "TORSO_P0_8_11", 16); iVar6 = 8; iVar7 = 11; iVar1 = 68; break; case 56: StringCopy(&Var2, "TORSO_P0_8_12", 16); iVar6 = 8; iVar7 = 12; iVar1 = 55; break; case 57: StringCopy(&Var2, "TORSO_P0_8_13", 16); iVar6 = 8; iVar7 = 13; iVar1 = 62; break; case 58: StringCopy(&Var2, "TORSO_P0_8_14", 16); iVar6 = 8; iVar7 = 14; iVar1 = 58; break; case 59: StringCopy(&Var2, "TORSO_P0_8_15", 16); iVar6 = 8; iVar7 = 15; iVar1 = 58; break; default: return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_215(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 2; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "HAIR_P0_0_0", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "HAIR_P0_1_0", 16); iVar6 = 1; iVar7 = 0; break; case 2: StringCopy(&Var2, "HAIR_P0_2_0", 16); iVar6 = 2; iVar7 = 0; break; case 3: StringCopy(&Var2, "HAIR_P0_3_0", 16); iVar6 = 3; iVar7 = 0; break; case 4: StringCopy(&Var2, "HAIR_P0_4_0", 16); iVar6 = 4; iVar7 = 0; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 5; iVar7 = 0; break; default: func_163(iVar10, iParam0, 6, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_216(int iParam0) { bool bVar0; int iVar1; struct<2> Var2; int iVar6; int iVar7; int iVar8; int iVar9; int iVar10; bVar0 = false; iVar1 = 10; iVar6 = 0; iVar7 = 0; iVar8 = -1; iVar9 = 2; iVar10 = 0; Global_76647[0 /*14*/].f_5 = 0; switch (iParam0) { case 0: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 0; break; case 1: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 1; break; case 2: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 2; break; case 3: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 3; break; case 4: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 4; break; case 5: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 5; break; case 6: StringCopy(&Var2, "NO_LABEL", 16); iVar6 = 0; iVar7 = 6; break; default: func_163(iVar10, iParam0, 7, -1); return; break; } func_156(&(Global_76647[0 /*14*/]), iVar10, iParam0, &Var2, iVar6, iVar7, iVar1, bVar0, iVar8, iVar9, 0); } void func_217() { Global_76647[0 /*14*/].f_1 = -1; Global_76647[0 /*14*/].f_2 = -1; Global_76647[0 /*14*/].f_5 = -1; Global_76647[0 /*14*/].f_3 = -1; Global_76647[0 /*14*/].f_4 = -1; Global_76647[0 /*14*/].f_7 = 0; Global_76647[0 /*14*/].f_6 = 0; Global_76647[0 /*14*/].f_13 = -1; Global_76647[0 /*14*/].f_12 = 0; Global_76647[0 /*14*/] = 0; StringCopy(&(Global_76647[0 /*14*/].f_8), "NO_LABEL", 16); } void func_218(int iParam0, int iParam1) { if (func_2(iParam0)) { STREAMING::REQUEST_MODEL(func_41(iParam0, iParam1)); } else if (iParam0 != 145) { } } void func_219(struct<3> Param0, float fParam3, int iParam4, float fParam5, bool bParam6) { int iVar0; if (bParam6) { if (!CAM::IS_SCREEN_FADED_OUT()) { if (!CAM::IS_SCREEN_FADING_OUT()) { CAM::DO_SCREEN_FADE_OUT(800); } } while (!CAM::IS_SCREEN_FADED_OUT()) { SYSTEM::WAIT(0); } } MISC::CLEAR_AREA(Param0, 5f, true, false, false, false); if (ENTITY::DOES_ENTITY_EXIST(PLAYER::PLAYER_PED_ID())) { if (!PED::IS_PED_INJURED(PLAYER::PLAYER_PED_ID())) { ENTITY::SET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), Param0, true, false, false, true); if (fParam3 != -1f) { ENTITY::SET_ENTITY_HEADING(PLAYER::PLAYER_PED_ID(), fParam3); } CAM::SET_GAMEPLAY_CAM_RELATIVE_PITCH(0f, 1f); CAM::SET_GAMEPLAY_CAM_RELATIVE_HEADING(0f); AUDIO::RESET_PED_AUDIO_FLAGS(PLAYER::PLAYER_PED_ID()); } } SYSTEM::WAIT(0); MISC::SET_GAME_PAUSED(true); STREAMING::NEW_LOAD_SCENE_START_SPHERE(Param0, fParam5, 0); iVar0 = 0; while (!STREAMING::IS_NEW_LOAD_SCENE_LOADED() && iVar0 < iParam4) { iVar0++; SYSTEM::WAIT(0); } STREAMING::NEW_LOAD_SCENE_STOP(); MISC::CLEAR_AREA(Param0, 5f, true, false, false, false); CAM::SET_GAMEPLAY_CAM_RELATIVE_PITCH(0f, 1f); CAM::SET_GAMEPLAY_CAM_RELATIVE_HEADING(0f); MISC::SET_GAME_PAUSED(false); if (bParam6) { CAM::DO_SCREEN_FADE_IN(800); } } int func_220() { if (Global_77093) { return 1; } else if (Global_61711 && !Global_61717) { return 1; } return 0; } void func_221() { CUTSCENE::REMOVE_CUTSCENE(); Global_42180 = 0; SCRIPT::TERMINATE_THIS_THREAD(); } void func_222() { Global_98994 = 1; }
610433.c
/* * Copyright (c) 2003, 2007-14 Matteo Frigo * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ /* This file was automatically generated --- DO NOT EDIT */ /* Generated on Fri Jan 27 16:09:17 EST 2017 */ #include "codelet-dft.h" #ifdef HAVE_FMA /* Generated by: ../../../genfft/gen_notw.native -fma -reorder-insns -schedule-for-pipeline -compact -variables 4 -pipeline-latency 4 -n 20 -name n1_20 -include n.h */ /* * This function contains 208 FP additions, 72 FP multiplications, * (or, 136 additions, 0 multiplications, 72 fused multiply/add), * 86 stack variables, 4 constants, and 80 memory accesses */ #include "n.h" static void n1_20(const R *ri, const R *ii, R *ro, R *io, stride is, stride os, INT v, INT ivs, INT ovs) { DK(KP951056516, +0.951056516295153572116439333379382143405698634); DK(KP559016994, +0.559016994374947424102293417182819058860154590); DK(KP618033988, +0.618033988749894848204586834365638117720309180); DK(KP250000000, +0.250000000000000000000000000000000000000000000); { INT i; for (i = v; i > 0; i = i - 1, ri = ri + ivs, ii = ii + ivs, ro = ro + ovs, io = io + ovs, MAKE_VOLATILE_STRIDE(80, is), MAKE_VOLATILE_STRIDE(80, os)) { E T1Y, T1Z, T1W, T1V; { E T1d, TP, TD, T7, T3b, T2N, T2f, T1R, T2U, TB, T2P, T2A, T3d, T37, T3j; E TJ, T2n, T1b, T1T, T1y, T2b, T2h, T1j, T2V, Tm, T2O, T2H, T3c, T34, T1e; E T1f, T3i, TG, T2m, T10, T1S, T1J, T28, T2g; { E T4, T1N, T3, T2L, TN, T5, T1O, T1P, T1h, T1i; { E T1, T2, TL, TM; T1 = ri[0]; T2 = ri[WS(is, 10)]; TL = ii[0]; TM = ii[WS(is, 10)]; T4 = ri[WS(is, 5)]; T1N = T1 - T2; T3 = T1 + T2; T2L = TL + TM; TN = TL - TM; T5 = ri[WS(is, 15)]; T1O = ii[WS(is, 5)]; T1P = ii[WS(is, 15)]; } { E T1o, Tp, T2u, T13, T14, Ts, T2v, T1r, Tx, T1t, Tw, T2x, T18, Ty, T1u; E T1v; { E Tq, Tr, T1p, T1q; { E Tn, To, T11, T12; Tn = ri[WS(is, 8)]; { E TO, T6, T2M, T1Q; TO = T4 - T5; T6 = T4 + T5; T2M = T1O + T1P; T1Q = T1O - T1P; T1d = TO + TN; TP = TN - TO; TD = T3 + T6; T7 = T3 - T6; T3b = T2L + T2M; T2N = T2L - T2M; T2f = T1N + T1Q; T1R = T1N - T1Q; To = ri[WS(is, 18)]; } T11 = ii[WS(is, 8)]; T12 = ii[WS(is, 18)]; Tq = ri[WS(is, 13)]; T1o = Tn - To; Tp = Tn + To; T2u = T11 + T12; T13 = T11 - T12; Tr = ri[WS(is, 3)]; T1p = ii[WS(is, 13)]; T1q = ii[WS(is, 3)]; } { E Tu, Tv, T16, T17; Tu = ri[WS(is, 12)]; T14 = Tq - Tr; Ts = Tq + Tr; T2v = T1p + T1q; T1r = T1p - T1q; Tv = ri[WS(is, 2)]; T16 = ii[WS(is, 12)]; T17 = ii[WS(is, 2)]; Tx = ri[WS(is, 17)]; T1t = Tu - Tv; Tw = Tu + Tv; T2x = T16 + T17; T18 = T16 - T17; Ty = ri[WS(is, 7)]; T1u = ii[WS(is, 17)]; T1v = ii[WS(is, 7)]; } } { E TH, T19, T1w, TI; { E Tt, T2w, T35, TA, T2z, T36, Tz, T2y; TH = Tp + Ts; Tt = Tp - Ts; T19 = Tx - Ty; Tz = Tx + Ty; T2y = T1u + T1v; T1w = T1u - T1v; T2w = T2u - T2v; T35 = T2u + T2v; TI = Tw + Tz; TA = Tw - Tz; T2z = T2x - T2y; T36 = T2x + T2y; T2U = Tt - TA; TB = Tt + TA; T2P = T2w + T2z; T2A = T2w - T2z; T3d = T35 + T36; T37 = T35 - T36; } { E T1s, T29, T1x, T2a, T15, T1a; T15 = T13 - T14; T1h = T14 + T13; T1i = T19 + T18; T1a = T18 - T19; T1s = T1o - T1r; T29 = T1o + T1r; T3j = TH - TI; TJ = TH + TI; T1x = T1t - T1w; T2a = T1t + T1w; T2n = T15 - T1a; T1b = T15 + T1a; T1T = T1s + T1x; T1y = T1s - T1x; T2b = T29 - T2a; T2h = T29 + T2a; } } } { E Ta, T1z, T2B, TS, TT, Td, T2C, T1C, Ti, T1E, Th, T2E, TX, Tj, T1F; E T1G; { E Tb, Tc, T1A, T1B; { E TQ, TR, T8, T9; T8 = ri[WS(is, 4)]; T9 = ri[WS(is, 14)]; T1j = T1h + T1i; T1Y = T1h - T1i; TQ = ii[WS(is, 4)]; TR = ii[WS(is, 14)]; Ta = T8 + T9; T1z = T8 - T9; Tb = ri[WS(is, 9)]; T2B = TQ + TR; TS = TQ - TR; Tc = ri[WS(is, 19)]; T1A = ii[WS(is, 9)]; T1B = ii[WS(is, 19)]; } { E Tf, Tg, TV, TW; Tf = ri[WS(is, 16)]; TT = Tb - Tc; Td = Tb + Tc; T2C = T1A + T1B; T1C = T1A - T1B; Tg = ri[WS(is, 6)]; TV = ii[WS(is, 16)]; TW = ii[WS(is, 6)]; Ti = ri[WS(is, 1)]; T1E = Tf - Tg; Th = Tf + Tg; T2E = TV + TW; TX = TV - TW; Tj = ri[WS(is, 11)]; T1F = ii[WS(is, 1)]; T1G = ii[WS(is, 11)]; } } { E TE, TY, T1H, TF; { E Te, T2D, T32, Tl, T2G, T33, Tk, T2F; TE = Ta + Td; Te = Ta - Td; TY = Ti - Tj; Tk = Ti + Tj; T2F = T1F + T1G; T1H = T1F - T1G; T2D = T2B - T2C; T32 = T2B + T2C; TF = Th + Tk; Tl = Th - Tk; T2G = T2E - T2F; T33 = T2E + T2F; T2V = Te - Tl; Tm = Te + Tl; T2O = T2D + T2G; T2H = T2D - T2G; T3c = T32 + T33; T34 = T32 - T33; } { E T1D, T26, T1I, T27, TU, TZ; TU = TS - TT; T1e = TT + TS; T1f = TY + TX; TZ = TX - TY; T1D = T1z - T1C; T26 = T1z + T1C; T3i = TE - TF; TG = TE + TF; T1I = T1E - T1H; T27 = T1E + T1H; T2m = TU - TZ; T10 = TU + TZ; T1S = T1D + T1I; T1J = T1D - T1I; T28 = T26 - T27; T2g = T26 + T27; } } } } { E T1g, T3g, T3f, T2S, T2R, T2k, T2j; { E T2s, T2r, TC, T2Q; T2s = Tm - TB; TC = Tm + TB; T1g = T1e + T1f; T1Z = T1e - T1f; T2r = FNMS(KP250000000, TC, T7); ro[WS(os, 10)] = T7 + TC; T2Q = T2O + T2P; T2S = T2O - T2P; { E T2K, T2I, T2t, T2J; T2K = FMA(KP618033988, T2A, T2H); T2I = FNMS(KP618033988, T2H, T2A); T2t = FNMS(KP559016994, T2s, T2r); T2J = FMA(KP559016994, T2s, T2r); ro[WS(os, 18)] = FMA(KP951056516, T2I, T2t); ro[WS(os, 2)] = FNMS(KP951056516, T2I, T2t); ro[WS(os, 6)] = FMA(KP951056516, T2K, T2J); ro[WS(os, 14)] = FNMS(KP951056516, T2K, T2J); T2R = FNMS(KP250000000, T2Q, T2N); } io[WS(os, 10)] = T2N + T2Q; } { E T30, T2Z, TK, T3e; TK = TG + TJ; T30 = TG - TJ; { E T2T, T2X, T2Y, T2W; T2T = FNMS(KP559016994, T2S, T2R); T2X = FMA(KP559016994, T2S, T2R); T2Y = FMA(KP618033988, T2U, T2V); T2W = FNMS(KP618033988, T2V, T2U); io[WS(os, 14)] = FMA(KP951056516, T2Y, T2X); io[WS(os, 6)] = FNMS(KP951056516, T2Y, T2X); io[WS(os, 18)] = FNMS(KP951056516, T2W, T2T); io[WS(os, 2)] = FMA(KP951056516, T2W, T2T); T2Z = FNMS(KP250000000, TK, TD); } ro[0] = TD + TK; T3e = T3c + T3d; T3g = T3c - T3d; { E T31, T39, T3a, T38; T31 = FMA(KP559016994, T30, T2Z); T39 = FNMS(KP559016994, T30, T2Z); T3a = FNMS(KP618033988, T34, T37); T38 = FMA(KP618033988, T37, T34); ro[WS(os, 8)] = FMA(KP951056516, T3a, T39); ro[WS(os, 12)] = FNMS(KP951056516, T3a, T39); ro[WS(os, 16)] = FMA(KP951056516, T38, T31); ro[WS(os, 4)] = FNMS(KP951056516, T38, T31); T3f = FNMS(KP250000000, T3e, T3b); } io[0] = T3b + T3e; } { E T24, T23, T1c, T2i; T1c = T10 + T1b; T24 = T10 - T1b; { E T3h, T3l, T3m, T3k; T3h = FMA(KP559016994, T3g, T3f); T3l = FNMS(KP559016994, T3g, T3f); T3m = FNMS(KP618033988, T3i, T3j); T3k = FMA(KP618033988, T3j, T3i); io[WS(os, 12)] = FMA(KP951056516, T3m, T3l); io[WS(os, 8)] = FNMS(KP951056516, T3m, T3l); io[WS(os, 16)] = FNMS(KP951056516, T3k, T3h); io[WS(os, 4)] = FMA(KP951056516, T3k, T3h); T23 = FNMS(KP250000000, T1c, TP); } io[WS(os, 5)] = TP + T1c; T2i = T2g + T2h; T2k = T2g - T2h; { E T25, T2d, T2e, T2c; T25 = FMA(KP559016994, T24, T23); T2d = FNMS(KP559016994, T24, T23); T2e = FNMS(KP618033988, T28, T2b); T2c = FMA(KP618033988, T2b, T28); io[WS(os, 17)] = FMA(KP951056516, T2e, T2d); io[WS(os, 13)] = FNMS(KP951056516, T2e, T2d); io[WS(os, 9)] = FMA(KP951056516, T2c, T25); io[WS(os, 1)] = FNMS(KP951056516, T2c, T25); T2j = FNMS(KP250000000, T2i, T2f); } ro[WS(os, 5)] = T2f + T2i; } { E T1m, T1l, T1k, T1U; T1k = T1g + T1j; T1m = T1g - T1j; { E T2l, T2p, T2q, T2o; T2l = FMA(KP559016994, T2k, T2j); T2p = FNMS(KP559016994, T2k, T2j); T2q = FNMS(KP618033988, T2m, T2n); T2o = FMA(KP618033988, T2n, T2m); ro[WS(os, 17)] = FNMS(KP951056516, T2q, T2p); ro[WS(os, 13)] = FMA(KP951056516, T2q, T2p); ro[WS(os, 9)] = FNMS(KP951056516, T2o, T2l); ro[WS(os, 1)] = FMA(KP951056516, T2o, T2l); T1l = FNMS(KP250000000, T1k, T1d); } io[WS(os, 15)] = T1d + T1k; T1U = T1S + T1T; T1W = T1S - T1T; { E T1n, T1L, T1M, T1K; T1n = FNMS(KP559016994, T1m, T1l); T1L = FMA(KP559016994, T1m, T1l); T1M = FMA(KP618033988, T1y, T1J); T1K = FNMS(KP618033988, T1J, T1y); io[WS(os, 19)] = FMA(KP951056516, T1M, T1L); io[WS(os, 11)] = FNMS(KP951056516, T1M, T1L); io[WS(os, 7)] = FMA(KP951056516, T1K, T1n); io[WS(os, 3)] = FNMS(KP951056516, T1K, T1n); T1V = FNMS(KP250000000, T1U, T1R); } ro[WS(os, 15)] = T1R + T1U; } } } { E T21, T1X, T20, T22; T21 = FMA(KP559016994, T1W, T1V); T1X = FNMS(KP559016994, T1W, T1V); T20 = FNMS(KP618033988, T1Z, T1Y); T22 = FMA(KP618033988, T1Y, T1Z); ro[WS(os, 19)] = FNMS(KP951056516, T22, T21); ro[WS(os, 11)] = FMA(KP951056516, T22, T21); ro[WS(os, 7)] = FNMS(KP951056516, T20, T1X); ro[WS(os, 3)] = FMA(KP951056516, T20, T1X); } } } } static const kdft_desc desc = { 20, "n1_20", {136, 0, 72, 0}, &GENUS, 0, 0, 0, 0 }; void X(codelet_n1_20) (planner *p) { X(kdft_register) (p, n1_20, &desc); } #else /* HAVE_FMA */ /* Generated by: ../../../genfft/gen_notw.native -compact -variables 4 -pipeline-latency 4 -n 20 -name n1_20 -include n.h */ /* * This function contains 208 FP additions, 48 FP multiplications, * (or, 184 additions, 24 multiplications, 24 fused multiply/add), * 81 stack variables, 4 constants, and 80 memory accesses */ #include "n.h" static void n1_20(const R *ri, const R *ii, R *ro, R *io, stride is, stride os, INT v, INT ivs, INT ovs) { DK(KP587785252, +0.587785252292473129168705954639072768597652438); DK(KP951056516, +0.951056516295153572116439333379382143405698634); DK(KP250000000, +0.250000000000000000000000000000000000000000000); DK(KP559016994, +0.559016994374947424102293417182819058860154590); { INT i; for (i = v; i > 0; i = i - 1, ri = ri + ivs, ii = ii + ivs, ro = ro + ovs, io = io + ovs, MAKE_VOLATILE_STRIDE(80, is), MAKE_VOLATILE_STRIDE(80, os)) { E T7, T2Q, T3h, TD, TP, T1U, T2l, T1d, Tt, TA, TB, T2w, T2z, T2S, T35; E T36, T3f, TH, TI, TJ, T15, T1a, T1b, T1s, T1x, T1W, T29, T2a, T2j, T1h; E T1i, T1j, Te, Tl, Tm, T2D, T2G, T2R, T32, T33, T3e, TE, TF, TG, TU; E TZ, T10, T1D, T1I, T1V, T26, T27, T2i, T1e, T1f, T1g; { E T3, T1Q, TN, T2O, T6, TO, T1T, T2P; { E T1, T2, TL, TM; T1 = ri[0]; T2 = ri[WS(is, 10)]; T3 = T1 + T2; T1Q = T1 - T2; TL = ii[0]; TM = ii[WS(is, 10)]; TN = TL - TM; T2O = TL + TM; } { E T4, T5, T1R, T1S; T4 = ri[WS(is, 5)]; T5 = ri[WS(is, 15)]; T6 = T4 + T5; TO = T4 - T5; T1R = ii[WS(is, 5)]; T1S = ii[WS(is, 15)]; T1T = T1R - T1S; T2P = T1R + T1S; } T7 = T3 - T6; T2Q = T2O - T2P; T3h = T2O + T2P; TD = T3 + T6; TP = TN - TO; T1U = T1Q - T1T; T2l = T1Q + T1T; T1d = TO + TN; } { E Tp, T1o, T13, T2u, Ts, T14, T1r, T2v, Tw, T1t, T18, T2x, Tz, T19, T1w; E T2y; { E Tn, To, T11, T12; Tn = ri[WS(is, 8)]; To = ri[WS(is, 18)]; Tp = Tn + To; T1o = Tn - To; T11 = ii[WS(is, 8)]; T12 = ii[WS(is, 18)]; T13 = T11 - T12; T2u = T11 + T12; } { E Tq, Tr, T1p, T1q; Tq = ri[WS(is, 13)]; Tr = ri[WS(is, 3)]; Ts = Tq + Tr; T14 = Tq - Tr; T1p = ii[WS(is, 13)]; T1q = ii[WS(is, 3)]; T1r = T1p - T1q; T2v = T1p + T1q; } { E Tu, Tv, T16, T17; Tu = ri[WS(is, 12)]; Tv = ri[WS(is, 2)]; Tw = Tu + Tv; T1t = Tu - Tv; T16 = ii[WS(is, 12)]; T17 = ii[WS(is, 2)]; T18 = T16 - T17; T2x = T16 + T17; } { E Tx, Ty, T1u, T1v; Tx = ri[WS(is, 17)]; Ty = ri[WS(is, 7)]; Tz = Tx + Ty; T19 = Tx - Ty; T1u = ii[WS(is, 17)]; T1v = ii[WS(is, 7)]; T1w = T1u - T1v; T2y = T1u + T1v; } Tt = Tp - Ts; TA = Tw - Tz; TB = Tt + TA; T2w = T2u - T2v; T2z = T2x - T2y; T2S = T2w + T2z; T35 = T2u + T2v; T36 = T2x + T2y; T3f = T35 + T36; TH = Tp + Ts; TI = Tw + Tz; TJ = TH + TI; T15 = T13 - T14; T1a = T18 - T19; T1b = T15 + T1a; T1s = T1o - T1r; T1x = T1t - T1w; T1W = T1s + T1x; T29 = T1o + T1r; T2a = T1t + T1w; T2j = T29 + T2a; T1h = T14 + T13; T1i = T19 + T18; T1j = T1h + T1i; } { E Ta, T1z, TS, T2B, Td, TT, T1C, T2C, Th, T1E, TX, T2E, Tk, TY, T1H; E T2F; { E T8, T9, TQ, TR; T8 = ri[WS(is, 4)]; T9 = ri[WS(is, 14)]; Ta = T8 + T9; T1z = T8 - T9; TQ = ii[WS(is, 4)]; TR = ii[WS(is, 14)]; TS = TQ - TR; T2B = TQ + TR; } { E Tb, Tc, T1A, T1B; Tb = ri[WS(is, 9)]; Tc = ri[WS(is, 19)]; Td = Tb + Tc; TT = Tb - Tc; T1A = ii[WS(is, 9)]; T1B = ii[WS(is, 19)]; T1C = T1A - T1B; T2C = T1A + T1B; } { E Tf, Tg, TV, TW; Tf = ri[WS(is, 16)]; Tg = ri[WS(is, 6)]; Th = Tf + Tg; T1E = Tf - Tg; TV = ii[WS(is, 16)]; TW = ii[WS(is, 6)]; TX = TV - TW; T2E = TV + TW; } { E Ti, Tj, T1F, T1G; Ti = ri[WS(is, 1)]; Tj = ri[WS(is, 11)]; Tk = Ti + Tj; TY = Ti - Tj; T1F = ii[WS(is, 1)]; T1G = ii[WS(is, 11)]; T1H = T1F - T1G; T2F = T1F + T1G; } Te = Ta - Td; Tl = Th - Tk; Tm = Te + Tl; T2D = T2B - T2C; T2G = T2E - T2F; T2R = T2D + T2G; T32 = T2B + T2C; T33 = T2E + T2F; T3e = T32 + T33; TE = Ta + Td; TF = Th + Tk; TG = TE + TF; TU = TS - TT; TZ = TX - TY; T10 = TU + TZ; T1D = T1z - T1C; T1I = T1E - T1H; T1V = T1D + T1I; T26 = T1z + T1C; T27 = T1E + T1H; T2i = T26 + T27; T1e = TT + TS; T1f = TY + TX; T1g = T1e + T1f; } { E T2s, TC, T2r, T2I, T2K, T2A, T2H, T2J, T2t; T2s = KP559016994 * (Tm - TB); TC = Tm + TB; T2r = FNMS(KP250000000, TC, T7); T2A = T2w - T2z; T2H = T2D - T2G; T2I = FNMS(KP587785252, T2H, KP951056516 * T2A); T2K = FMA(KP951056516, T2H, KP587785252 * T2A); ro[WS(os, 10)] = T7 + TC; T2J = T2s + T2r; ro[WS(os, 14)] = T2J - T2K; ro[WS(os, 6)] = T2J + T2K; T2t = T2r - T2s; ro[WS(os, 2)] = T2t - T2I; ro[WS(os, 18)] = T2t + T2I; } { E T2V, T2T, T2U, T2N, T2Y, T2L, T2M, T2X, T2W; T2V = KP559016994 * (T2R - T2S); T2T = T2R + T2S; T2U = FNMS(KP250000000, T2T, T2Q); T2L = Tt - TA; T2M = Te - Tl; T2N = FNMS(KP587785252, T2M, KP951056516 * T2L); T2Y = FMA(KP951056516, T2M, KP587785252 * T2L); io[WS(os, 10)] = T2Q + T2T; T2X = T2V + T2U; io[WS(os, 6)] = T2X - T2Y; io[WS(os, 14)] = T2Y + T2X; T2W = T2U - T2V; io[WS(os, 2)] = T2N + T2W; io[WS(os, 18)] = T2W - T2N; } { E T2Z, TK, T30, T38, T3a, T34, T37, T39, T31; T2Z = KP559016994 * (TG - TJ); TK = TG + TJ; T30 = FNMS(KP250000000, TK, TD); T34 = T32 - T33; T37 = T35 - T36; T38 = FMA(KP951056516, T34, KP587785252 * T37); T3a = FNMS(KP587785252, T34, KP951056516 * T37); ro[0] = TD + TK; T39 = T30 - T2Z; ro[WS(os, 12)] = T39 - T3a; ro[WS(os, 8)] = T39 + T3a; T31 = T2Z + T30; ro[WS(os, 4)] = T31 - T38; ro[WS(os, 16)] = T31 + T38; } { E T3g, T3i, T3j, T3d, T3m, T3b, T3c, T3l, T3k; T3g = KP559016994 * (T3e - T3f); T3i = T3e + T3f; T3j = FNMS(KP250000000, T3i, T3h); T3b = TE - TF; T3c = TH - TI; T3d = FMA(KP951056516, T3b, KP587785252 * T3c); T3m = FNMS(KP587785252, T3b, KP951056516 * T3c); io[0] = T3h + T3i; T3l = T3j - T3g; io[WS(os, 8)] = T3l - T3m; io[WS(os, 12)] = T3m + T3l; T3k = T3g + T3j; io[WS(os, 4)] = T3d + T3k; io[WS(os, 16)] = T3k - T3d; } { E T23, T1c, T24, T2c, T2e, T28, T2b, T2d, T25; T23 = KP559016994 * (T10 - T1b); T1c = T10 + T1b; T24 = FNMS(KP250000000, T1c, TP); T28 = T26 - T27; T2b = T29 - T2a; T2c = FMA(KP951056516, T28, KP587785252 * T2b); T2e = FNMS(KP587785252, T28, KP951056516 * T2b); io[WS(os, 5)] = TP + T1c; T2d = T24 - T23; io[WS(os, 13)] = T2d - T2e; io[WS(os, 17)] = T2d + T2e; T25 = T23 + T24; io[WS(os, 1)] = T25 - T2c; io[WS(os, 9)] = T25 + T2c; } { E T2k, T2m, T2n, T2h, T2p, T2f, T2g, T2q, T2o; T2k = KP559016994 * (T2i - T2j); T2m = T2i + T2j; T2n = FNMS(KP250000000, T2m, T2l); T2f = TU - TZ; T2g = T15 - T1a; T2h = FMA(KP951056516, T2f, KP587785252 * T2g); T2p = FNMS(KP587785252, T2f, KP951056516 * T2g); ro[WS(os, 5)] = T2l + T2m; T2q = T2n - T2k; ro[WS(os, 13)] = T2p + T2q; ro[WS(os, 17)] = T2q - T2p; T2o = T2k + T2n; ro[WS(os, 1)] = T2h + T2o; ro[WS(os, 9)] = T2o - T2h; } { E T1m, T1k, T1l, T1K, T1M, T1y, T1J, T1L, T1n; T1m = KP559016994 * (T1g - T1j); T1k = T1g + T1j; T1l = FNMS(KP250000000, T1k, T1d); T1y = T1s - T1x; T1J = T1D - T1I; T1K = FNMS(KP587785252, T1J, KP951056516 * T1y); T1M = FMA(KP951056516, T1J, KP587785252 * T1y); io[WS(os, 15)] = T1d + T1k; T1L = T1m + T1l; io[WS(os, 11)] = T1L - T1M; io[WS(os, 19)] = T1L + T1M; T1n = T1l - T1m; io[WS(os, 3)] = T1n - T1K; io[WS(os, 7)] = T1n + T1K; } { E T1Z, T1X, T1Y, T1P, T21, T1N, T1O, T22, T20; T1Z = KP559016994 * (T1V - T1W); T1X = T1V + T1W; T1Y = FNMS(KP250000000, T1X, T1U); T1N = T1h - T1i; T1O = T1e - T1f; T1P = FNMS(KP587785252, T1O, KP951056516 * T1N); T21 = FMA(KP951056516, T1O, KP587785252 * T1N); ro[WS(os, 15)] = T1U + T1X; T22 = T1Z + T1Y; ro[WS(os, 11)] = T21 + T22; ro[WS(os, 19)] = T22 - T21; T20 = T1Y - T1Z; ro[WS(os, 3)] = T1P + T20; ro[WS(os, 7)] = T20 - T1P; } } } } static const kdft_desc desc = { 20, "n1_20", {184, 24, 24, 0}, &GENUS, 0, 0, 0, 0 }; void X(codelet_n1_20) (planner *p) { X(kdft_register) (p, n1_20, &desc); } #endif /* HAVE_FMA */
637375.c
/* Test the optimization of `vdupq_n_u16' ARM Neon intrinsic. */ /* { dg-do compile } */ /* { dg-require-effective-target arm_neon_ok } */ /* { dg-options "-O2" } */ /* { dg-add-options arm_neon } */ #include <arm_neon.h> uint16x8_t out_uint16x8_t; void test_vdupq_nu16 (void) { out_uint16x8_t = vdupq_n_u16 (~0x1200); } /* { dg-final { scan-assembler "vmov\.i16\[ \]+\[qQ\]\[0-9\]+, #60927\(\[ \]+@\[a-zA-Z0-9 \]+\)?\n" } } */
903391.c
/* * Copyright (c) 2020 Murilo Ijanc' <[email protected]> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <err.h> #include <math.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include "capybara/serie_int16.h" #include "capybara/utils.h" #define SERIE ((struct serie_int16_impl *)s) #define N(x) (sizeof(x) / sizeof(x[0])) /* implementation */ struct serie_int16_impl { serie_int16_ops *ops; /* internal */ char *name; int16_t *data; size_t size; size_t capacity; }; static const char *set_name(serie_int16_t *, const char *); static char *get_name(serie_int16_t *); static void free_serie(serie_int16_t *); static cap_error_t resize(struct serie_int16_impl *); static cap_error_t add(serie_int16_t *, int16_t); static size_t size(serie_int16_t *); static int16_t *get(serie_int16_t *, size_t); static int set(serie_int16_t *, size_t, int16_t); static int delete(serie_int16_t *, size_t); static int16_t *min(serie_int16_t *); static int16_t *max(serie_int16_t *); static double mean(serie_int16_t *); static long double sum(serie_int16_t *); static double variance(serie_int16_t *); static double std_dev(serie_int16_t *); static void sort(serie_int16_t *); static int cmp(const void *, const void *); static double median(serie_int16_t *); static serie_int16_ops int16_ops = { set_name, get_name, free_serie, add, size, get, set, delete, min, max, mean, sum, variance, std_dev, sort, median, }; static double median(serie_int16_t *s) { double median = 0.0; const size_t sz = size(s); const size_t lhs = (sz - 1) / 2 ; const size_t rhs = sz / 2 ; if (sz == 0) return 0.0; sort(s); if (lhs == rhs) median = (double)*get(s, lhs); else median = (double)((*get(s, lhs) + *get(s, rhs)) / 2.0); return median; } static void sort(serie_int16_t *s) { const size_t sz = size(s); const size_t szint = sizeof(int16_t); qsort(SERIE->data, sz, szint, cmp); } static int cmp(const void *a, const void *b) { const int16_t *ia = (const int16_t *)a; const int16_t *ib = (const int16_t *)b; return *ia - *ib; } static double std_dev(serie_int16_t *s) { const double vr = variance(s); const double s_dev = sqrt(vr); return s_dev; } static double variance(serie_int16_t *s) { size_t i; double variance = 0; const size_t sz = size(s); int16_t *x; long double delta = 0; const double mn = mean(s); if (sz == 0) return (0); for (i = 0; i < sz; i++) { x = get(s, i); delta = (long double)*x - mn; variance += (delta * delta - variance) / (i + 1); } return variance; } static long double sum(serie_int16_t *s) { size_t i; long double sum = 0; const size_t sz = size(s); int16_t *x; if (sz == 0) return (0); for (i = 0; i < sz; i++) { x = get(s, i); sum += (long double)*x; } return sum; } static double mean(serie_int16_t *s) { size_t i; double mean = 0; const size_t sz = size(s); int16_t *x; if (sz == 0) return (0); for (i = 0; i < sz; i++) { x = get(s, i); mean += ((double)*x - mean) / (i + 1); } return mean; } static int16_t * max(serie_int16_t *s) { size_t i; int16_t *max; int16_t *x; const size_t sz = size(s); if (sz == 0) return (0); max = get(s, 0); for (i = 0; i < sz; i++) { x = get(s, i); if (*x > *max) max = x; } return max; } static int16_t * min(serie_int16_t *s) { size_t i; int16_t *min; int16_t *x; const size_t sz = size(s); if (sz == 0) return (0); min = get(s, 0); for (i = 0; i < sz; i++) { x = get(s, i); if (*x < *min) min = x; } return min; } static int delete(serie_int16_t *s, size_t index) { memmove(&SERIE->data[index], &SERIE->data[index+1], SERIE->size - index - 1); SERIE->size--; return (0); } static int set(serie_int16_t *s, size_t index, int16_t v) { SERIE->data[index] = v; return (0); } static int16_t * get(serie_int16_t *s, size_t index) { return &SERIE->data[index]; } static size_t size(serie_int16_t *s) { return SERIE->size; } static cap_error_t resize(struct serie_int16_impl *s) { int16_t *data; size_t nsize; /* new size */ nsize = SERIE->size * 2; /* first time size = 0 */ if (nsize == 0) nsize = 4; /* TODO: check xrealloc return */ data = xrealloc(SERIE->data, nsize + sizeof(int16_t)); SERIE->data = data; SERIE->capacity = nsize; return (CAPY_ERROR_OK); } static cap_error_t add(serie_int16_t *s, int16_t v) { cap_error_t err; if (SERIE->size == SERIE->capacity) if ((err = resize(SERIE)) != CAPY_ERROR_OK) { free_serie(s); return err; } SERIE->data[SERIE->size++] = v; return (CAPY_ERROR_OK); } static void free_serie(serie_int16_t *s) { if (SERIE == NULL) return; if (SERIE->name != NULL) free(SERIE->name); if (SERIE->data != NULL) free(SERIE->data); free(SERIE); } static char * get_name(serie_int16_t *s) { return SERIE->name; } static const char * set_name(serie_int16_t *s, const char *name) { char *n; if (name == NULL) { SERIE->name = NULL; return NULL; } n = xstrdup(name); SERIE->name = n; return NULL; } serie_int16_t * serie_int16_new(void) { struct serie_int16_impl *s; s = xcalloc(1, sizeof(struct serie_int16_impl)); s->ops = &int16_ops; return (serie_int16_t *)s; }
477127.c
/* * Odyssey. * * Scalable PostgreSQL connection pooler. */ #include <kiwi.h> #include <machinarium.h> #include <odyssey.h> static inline int od_auth_query_do(od_server_t *server, char *query, kiwi_var_t *user, kiwi_password_t *result) { od_instance_t *instance = server->global->instance; od_debug(&instance->logger, "auth_query", server->client, server, "%s", query); machine_msg_t *msg; msg = kiwi_fe_write_auth_query(NULL, query, user->value); if (msg == NULL) return -1; int rc; rc = od_write(&server->io, msg); if (rc == -1) { od_error(&instance->logger, "auth_query", server->client, server, "write error: %s", od_io_error(&server->io)); return -1; } /* update server sync state */ od_server_sync_request(server, 1); /* wait for response */ int has_result = 0; while (1) { msg = od_read(&server->io, UINT32_MAX); if (msg == NULL) { if (!machine_timedout()) { od_error(&instance->logger, "auth_query", server->client, server, "read error: %s", od_io_error(&server->io)); } return -1; } kiwi_be_type_t type; type = *(char *)machine_msg_data(msg); od_debug(&instance->logger, "auth_query", server->client, server, "%s", kiwi_be_type_to_string(type)); switch (type) { case KIWI_BE_ERROR_RESPONSE: od_backend_error(server, "auth_query", machine_msg_data(msg), machine_msg_size(msg)); goto error; case KIWI_BE_ROW_DESCRIPTION: break; case KIWI_BE_DATA_ROW: { if (has_result) goto error; char *pos = (char *)machine_msg_data(msg) + 1; uint32_t pos_size = machine_msg_size(msg) - 1; /* size */ uint32_t size; rc = kiwi_read32(&size, &pos, &pos_size); if (kiwi_unlikely(rc == -1)) goto error; /* count */ uint16_t count; rc = kiwi_read16(&count, &pos, &pos_size); if (kiwi_unlikely(rc == -1)) goto error; if (count != 2) goto error; /* user (not used) */ uint32_t user_len; rc = kiwi_read32(&user_len, &pos, &pos_size); if (kiwi_unlikely(rc == -1)) goto error; char *user = pos; rc = kiwi_readn(user_len, &pos, &pos_size); if (kiwi_unlikely(rc == -1)) goto error; (void)user; (void)user_len; /* password */ uint32_t password_len; rc = kiwi_read32(&password_len, &pos, &pos_size); if (kiwi_unlikely(rc == -1)) goto error; char *password = pos; rc = kiwi_readn(password_len, &pos, &pos_size); if (kiwi_unlikely(rc == -1)) goto error; result->password = malloc(password_len + 1); if (result->password == NULL) goto error; memcpy(result->password, password, password_len); result->password[password_len] = 0; result->password_len = password_len + 1; has_result = 1; break; } case KIWI_BE_READY_FOR_QUERY: od_backend_ready(server, machine_msg_data(msg), machine_msg_size(msg)); machine_msg_free(msg); return 0; default: break; } machine_msg_free(msg); } return 0; error: machine_msg_free(msg); return -1; } __attribute__((hot)) static inline int od_auth_query_format(od_rule_t *rule, kiwi_var_t *user, char *peer, char *output, int output_len) { char *dst_pos = output; char *dst_end = output + output_len; char *format_pos = rule->auth_query; char *format_end = rule->auth_query + strlen(rule->auth_query); while (format_pos < format_end) { if (*format_pos == '%') { format_pos++; if (od_unlikely(format_pos == format_end)) break; int len; switch (*format_pos) { case 'u': len = od_snprintf(dst_pos, dst_end - dst_pos, "%s", user->value); dst_pos += len; break; case 'h': len = od_snprintf(dst_pos, dst_end - dst_pos, "%s", peer); dst_pos += len; break; default: if (od_unlikely((dst_end - dst_pos) < 2)) break; dst_pos[0] = '%'; dst_pos[1] = *format_pos; dst_pos += 2; break; } } else { if (od_unlikely((dst_end - dst_pos) < 1)) break; dst_pos[0] = *format_pos; dst_pos += 1; } format_pos++; } if (od_unlikely((dst_end - dst_pos) < 1)) return -1; dst_pos[0] = 0; dst_pos++; return dst_pos - output; } int od_auth_query(od_client_t *client, char *peer) { od_global_t *global = client->global; od_rule_t *rule = client->rule; kiwi_var_t *user = &client->startup.user; kiwi_password_t *password = &client->password; od_instance_t *instance = global->instance; od_router_t *router = global->router; /* create internal auth client */ od_client_t *auth_client; auth_client = od_client_allocate(); if (auth_client == NULL) return -1; auth_client->global = global; od_id_generate(&auth_client->id, "a"); /* set auth query route user and database */ kiwi_var_set(&auth_client->startup.user, KIWI_VAR_UNDEF, rule->auth_query_user, strlen(rule->auth_query_user) + 1); kiwi_var_set(&auth_client->startup.database, KIWI_VAR_UNDEF, rule->auth_query_db, strlen(rule->auth_query_db) + 1); /* route */ od_router_status_t status; status = od_router_route(router, auth_client); if (status != OD_ROUTER_OK) { od_client_free(auth_client); return -1; } /* attach */ status = od_router_attach(router, auth_client, false); if (status != OD_ROUTER_OK) { od_router_unroute(router, auth_client); od_client_free(auth_client); return -1; } od_server_t *server; server = auth_client->server; od_debug(&instance->logger, "auth_query", NULL, server, "attached to server %s%.*s", server->id.id_prefix, (int)sizeof(server->id.id), server->id.id); /* connect to server, if necessary */ int rc; if (server->io.io == NULL) { rc = od_backend_connect(server, "auth_query", NULL, NULL); if (rc == -1) { od_router_close(router, auth_client); od_router_unroute(router, auth_client); od_client_free(auth_client); return -1; } } /* preformat and execute query */ char query[OD_QRY_MAX_SZ]; od_auth_query_format(rule, user, peer, query, sizeof(query)); rc = od_auth_query_do(server, query, user, password); if (rc == -1) { od_router_close(router, auth_client); od_router_unroute(router, auth_client); od_client_free(auth_client); return -1; } /* detach and unroute */ od_router_detach(router, auth_client); od_router_unroute(router, auth_client); od_client_free(auth_client); return 0; }
450661.c
#include <NTL/tools.h> #include <cctype> #include <cstdio> #include <NTL/new.h> NTL_START_IMPL NTL_CHEAP_THREAD_LOCAL void (*ErrorCallback)() = 0; NTL_CHEAP_THREAD_LOCAL void (*ErrorMsgCallback)(const char *) = 0; void TerminalError(const char *s) { if (ErrorMsgCallback) (*ErrorMsgCallback)(s); else cerr << s << "\n"; if (ErrorCallback) (*ErrorCallback)(); abort(); } // The following implementation of CharToIntVal is completely portable. long CharToIntVal(long a) { switch (a) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; case 'A': return 10; case 'B': return 11; case 'C': return 12; case 'D': return 13; case 'E': return 14; case 'F': return 15; case 'a': return 10; case 'b': return 11; case 'c': return 12; case 'd': return 13; case 'e': return 14; case 'f': return 15; default: return -1; } } // The following implementation of IntValToChar is completely portable. char IntValToChar(long a) { switch (a) { case 0: return '0'; case 1: return '1'; case 2: return '2'; case 3: return '3'; case 4: return '4'; case 5: return '5'; case 6: return '6'; case 7: return '7'; case 8: return '8'; case 9: return '9'; case 10: return 'a'; case 11: return 'b'; case 12: return 'c'; case 13: return 'd'; case 14: return 'e'; case 15: return 'f'; default: LogicError("IntValToChar: bad arg"); } return 0; // to supress warnings } long IsWhiteSpace(long a) { if (a > NTL_MAX_INT || a < NTL_MIN_INT) return 0; int b = (int) a; if (isspace(b)) return 1; else return 0; } long SkipWhiteSpace(istream& s) { long c; c = s.peek(); while (IsWhiteSpace(c)) { s.get(); c = s.peek(); } if (c == EOF) return 0; else return 1; } long IsEOFChar(long c) { return c == EOF; } void PrintTime(ostream& s, double t) { long hh, mm, ss; ss = long(t + 0.5); hh = ss/3600; ss = ss - hh*3600; mm = ss/60; ss = ss - mm*60; if (hh > 0) s << hh << ":"; if (hh > 0 || mm > 0) { if (hh > 0 && mm < 10) s << "0"; s << mm << ":"; } if ((hh > 0 || mm > 0) && ss < 10) s << "0"; s << ss; } NTL_END_IMPL
814120.c
#include "multimac.h" #include <assert.h> static const uint8_t g_ContextBuf[] = { 0x39,0xc7,0x37,0xf0,0xf8,0xc3,0xf6,0x95,0x60,0xab,0x37,0x3d,0x8a,0xd1,0xe9,0x65, 0x0b,0x82,0x5c,0x5f,0xf4,0x4f,0x74,0x3b,0xf8,0x78,0x55,0x2a,0x10,0x4d,0x24,0x29, 0xc0,0x92,0x23,0x6a,0x21,0xb9,0xb6,0x6e,0x6b,0x15,0xdf,0x50,0x87,0xae,0x9c,0x46, 0xc2,0x19,0xcd,0x94,0x44,0x80,0xc7,0xdf,0x7e,0x25,0x3e,0x8b,0xd0,0x2c,0xdb,0x05, 0x58,0x40,0xa6,0x89,0x84,0x04,0x44,0x89,0x8a,0x75,0xff,0x74,0x35,0xfe,0x29,0xe3, 0x44,0xcd,0x86,0xb6,0x3f,0x8c,0x2e,0xc0,0x06,0xe7,0x8e,0x5a,0xb0,0xc4,0xd9,0xa8, 0x74,0x3a,0x94,0xeb,0x79,0xae,0xd3,0x56,0x98,0xd9,0xb8,0x62,0x35,0x04,0x8a,0x3f, 0x80,0x26,0xc6,0x20,0x82,0xcd,0x69,0xa1,0x1d,0x4e,0x97,0x85,0xde,0x78,0xb9,0x9c, 0x08,0xf6,0x2e,0x1b,0x61,0x53,0x44,0xbe,0xb8,0x61,0x04,0xb4,0xcd,0xe7,0x74,0xa1, 0x98,0x6c,0x11,0x05,0x68,0x61,0x36,0x35,0x35,0x50,0x8e,0xbd,0xf4,0x72,0xd6,0x53, 0x12,0x98,0x5b,0x41,0x31,0xc9,0xaf,0x1a,0xb4,0x5c,0x5f,0x20,0x05,0x85,0xad,0xae, 0x4d,0x2c,0xba,0xa7,0x1f,0xe9,0xee,0x0d,0x25,0x2c,0x6b,0xc9,0x46,0x5e,0x02,0xc9, 0xbe,0x2e,0xd4,0x46,0xcb,0x10,0xf3,0xdc,0xcc,0x41,0xa1,0x02,0xe5,0xd7,0xeb,0xd0, 0x8c,0x4f,0x44,0x85,0x24,0x16,0x7f,0xa6,0xc4,0xd8,0x8b,0x6c,0x39,0x47,0xdf,0xc6, 0x28,0x35,0x56,0x1c,0xdc,0x31,0x23,0x78,0x96,0x39,0xd3,0xee,0x4f,0x6d,0x6d,0x23, 0x41,0x20,0xea,0xbb,0x11,0x8c,0x5d,0xaf,0xa1,0xf7,0x8e,0x70,0x9c,0x31,0x9a,0x38, 0x66,0x31,0x93,0x99,0x0b,0xda,0x45,0xf8,0x8c,0x4b,0x89,0x30,0x81,0xee,0xe4,0x97, 0x95,0xf7,0x45,0xbd,0xa9,0x2d,0xfd,0xb7,0xbf,0x91,0xc4,0x18,0x78,0x0a,0x32,0xd0, 0xc1,0x68,0x19,0x20,0x68,0xaf,0x0d,0x9b,0x34,0x95,0x1f,0xc1,0xa0,0x55,0xe4,0x1f, 0x88,0xdd,0x85,0xbe,0x53,0xb5,0xba,0x4c,0xad,0x3a,0x5d,0xc0,0x37,0xc3,0xed,0x4c, 0x93,0x6f,0x52,0x42,0x51,0x93,0xea,0x13,0xbb,0xe5,0x5f,0x84,0x3c,0x25,0xf4,0x40, 0x64,0x24,0x0c,0xa2,0x65,0x57,0xef,0x2a,0x27,0x38,0x25,0xa2,0x86,0x2e,0x90,0xec, 0x3d,0xe7,0x2e,0x01,0x78,0x13,0xbb,0x87,0xa8,0x49,0x11,0xbd,0xb3,0x39,0x44,0x08, 0x85,0x81,0x4d,0xd6,0x0d,0xa2,0x74,0xbf,0xc0,0xe9,0xa0,0x41,0xab,0x5e,0x30,0x23, 0xb0,0x88,0xc9,0x3b,0x9f,0x93,0x13,0x38,0xe5,0x41,0x4d,0xff,0xdc,0x5d,0x17,0x1f, 0x83,0x87,0xed,0xc7,0x8c,0x26,0x47,0x76,0xa0,0xb2,0x4f,0x39,0x95,0x14,0x37,0x17, 0xf3,0x50,0x79,0x80,0x0d,0x40,0x80,0x03,0xa1,0x71,0x45,0x22,0x5b,0x39,0x7e,0x65, 0x7c,0xa3,0x6d,0x21,0xc3,0x64,0xc7,0x33,0xf6,0x5b,0x0e,0x47,0xe3,0xd1,0x19,0x7f, 0x22,0x3b,0x66,0xe9,0xe5,0x41,0xc6,0x87,0x64,0x82,0xa2,0x8f,0x8a,0xea,0x8f,0x65, 0x5c,0x83,0x8c,0x13,0x0f,0x43,0x65,0xf7,0x73,0xa7,0x80,0x74,0xc0,0xe7,0xa8,0x0d, 0xb8,0xe3,0xeb,0x05,0x7f,0x9a,0x92,0x56,0x2e,0x5c,0xc4,0x9d,0x9a,0x61,0x14,0x7f, 0x81,0x00,0x25,0x57,0x9a,0xeb,0x1a,0xf6,0x73,0x96,0xc9,0x78,0xc3,0xb3,0x73,0x64, 0x24,0x7a,0xe6,0x72,0x43,0x48,0xdc,0x90,0x8a,0x86,0x1f,0x8b,0xa3,0x17,0xfa,0xdd, 0x7b,0x6e,0xf2,0xac,0xd1,0xdd,0xa8,0xfc,0x01,0xe0,0x1f,0x4b,0x4a,0xb4,0xd6,0x02, 0xbc,0x76,0x95,0x74,0x52,0x4d,0xe1,0xec,0x30,0x8f,0x36,0xe4,0x4c,0xfd,0x6b,0x69, 0x0a,0x77,0x53,0xb5,0xa3,0x95,0xdd,0x60,0x69,0x9c,0xdb,0x19,0x4c,0xf3,0xee,0xe4, 0xa5,0x1e,0x11,0x43,0x51,0x3d,0x3f,0x9a,0x1f,0x14,0x80,0xc4,0x22,0x5d,0xac,0x63, 0xe0,0x46,0x1f,0xc1,0xed,0x71,0x03,0x8e,0x07,0x70,0x2f,0x7c,0x36,0x19,0xe4,0x4e, 0x94,0x50,0x32,0x2b,0xef,0x16,0x0c,0xd9,0x94,0xab,0xd3,0xe0,0x82,0x7e,0x90,0x96, 0xca,0xb4,0x72,0x7c,0x32,0x9b,0xc5,0x75,0x59,0x5d,0xcb,0x81,0xb7,0x79,0xe3,0x44, 0x76,0x31,0xeb,0xf0,0x05,0x69,0xe3,0x54,0x4e,0x43,0xb0,0x2d,0x54,0xc8,0x6b,0x08, 0xa0,0xb4,0xdf,0x09,0x68,0x23,0x4f,0xbd,0x2f,0x35,0xd2,0x89,0x83,0x58,0x8b,0x43, 0xab,0x38,0x58,0x8c,0x17,0xa2,0xc3,0x4e,0x38,0xb7,0x48,0xba,0xa4,0xce,0xed,0x8b, 0x45,0x80,0x60,0xda,0xaf,0x9d,0x8a,0x07,0x63,0x91,0xd6,0xb1,0x70,0x30,0xe1,0x0f, 0x92,0xb9,0x4e,0x44,0x3d,0x9b,0x1a,0x07,0x45,0x5a,0x3a,0x62,0x58,0x59,0xd5,0x81, 0x23,0x3e,0x7f,0xf6,0xb6,0xf2,0x0d,0xa6,0xa2,0x5e,0x56,0x0d,0x0d,0x2d,0x09,0x24, 0x95,0xe2,0xb6,0xc7,0xb1,0xfc,0x47,0x70,0x5d,0x8a,0x33,0xab,0x4a,0x72,0x7f,0x7d, 0xb3,0x55,0xfe,0x2b,0xad,0xae,0xce,0xbd,0xe1,0xb9,0x32,0x1e,0x74,0x11,0x4c,0x48, 0xed,0x1b,0xc1,0xdf,0x4e,0xa2,0x6a,0xdf,0xe5,0x84,0x3d,0x04,0x85,0xac,0x57,0xd0, 0x17,0x7f,0x6c,0x4f,0x7a,0x81,0x31,0xbe,0x87,0xa0,0xd9,0xaa,0xd9,0xc4,0xee,0x8d,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xeb,0xe0,0xa8, 0xd9,0x4b,0x37,0x9c,0xfe,0x96,0x94,0xd5,0x67,0x23,0x77,0x66,0xf2,0x56,0x45,0x4f, 0xae,0x18,0x4a,0x00,0x3b,0x66,0x7a,0x53,0xf7,0x9e,0xe7,0x42,0xc6,0x43,0xad,0x70, 0xac,0x2d,0x16,0x97,0x9d,0x36,0xa3,0x1d,0xe3,0xd1,0x9b,0xbc,0xfd,0x1a,0x64,0x76, 0xe4,0xdf,0x56,0x89,0x68,0xb0,0x8a,0xdc,0x27,0xfb,0x8e,0xb8,0x66,0x75,0xa2,0x80, 0x71,0x87,0x8c,0x73,0x91,0x31,0xb0,0xfb,0x67,0x3a,0xca,0x6d,0xed,0x07,0xae,0x51, 0x8e,0xfe,0x00,0xa3,0x9a,0x59,0x38,0x0e,0x3c,0x95,0x04,0xdb,0x49,0xad,0x9a,0x0e, 0x20,0x44,0xdc,0x7d,0xf2,0x7d,0xb5,0x3e,0xa4,0xa0,0x7e,0xb9,0x9a,0xde,0x55,0x6a, 0xb5,0x3e,0xb5,0xb0,0x34,0xf6,0x10,0x1f,0xb5,0x5e,0x69,0xb4,0x5b,0x05,0x75,0x19, 0x37,0x9a,0xf0,0xa8,0xe5,0x3d,0xf7,0x71,0xba,0x00,0xa3,0x8a,0xfb,0x07,0xbc,0x4b, 0x59,0x9e,0xd8,0x02,0xbc,0x90,0x07,0xef,0x6e,0xa7,0xe9,0x7a,0xae,0xfd,0xb1,0xf1, 0x93,0x9f,0x0f,0xf2,0x9e,0x24,0xe7,0x1a,0x08,0x14,0xca,0x16,0xba,0xb6,0x33,0x7a, 0x73,0xef,0x05,0x55,0x13,0xa2,0x24,0x9e,0xe3,0xf5,0x73,0x73,0x02,0x40,0x62,0x27, 0x92,0x12,0x45,0xa4,0x12,0xe5,0x7d,0xff,0xab,0x35,0x2d,0x0d,0xb1,0x8c,0x53,0xc6, 0x77,0x45,0x60,0xa2,0x39,0xfc,0x7c,0x71,0x8c,0x34,0x91,0x1f,0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x3d,0x32,0x07,0x86,0x73,0xac,0xe5,0x00,0x2a, 0x5f,0xb7,0x52,0x64,0x43,0x8c,0x4d,0xa2,0x7c,0xc4,0x32,0x11,0x14,0x2a,0x2c,0xbc, 0x4a,0x55,0x34,0x67,0x2a,0xe8,0x75,0x2b,0xd1,0xa1,0x24,0x22,0xaa,0x63,0x04,0xb4, 0xaa,0x5d,0x39,0xe1,0xce,0x3d,0xa6,0x12,0xb8,0x7a,0x22,0x53,0x5e,0x84,0x6f,0xc9, 0xca,0x95,0xa9,0xa8,0x64,0xdf,0x97,0x61,0xaa,0x9b,0xec,0x12,0xcf,0xab,0x1e,0xc1, 0x43,0xde,0xad,0x7f,0x25,0x7b,0xda,0xdb,0x1b,0xc8,0x21,0x1f,0x05,0xbc,0x4a,0x16, 0x96,0x33,0xbb,0x08,0x5e,0x92,0x12,0x7e,0x38,0xa6,0xb9,0xec,0x8f,0xe0,0xb6,0x47, 0xbe,0x6f,0x76,0x6d,0x37,0x99,0x78,0x44,0xd0,0x34,0x09,0x59,0xdb,0xbe,0xaa,0x32, 0xd2,0xa1,0xd0,0x09,0x12,0xf7,0x60,0x4a,0x9b,0x7b,0x37,0x60,0x86,0x85,0x89,0xd1, 0x88,0x29,0x4b,0x91,0xc0,0xdd,0x81,0x73,0x0d,0x20,0x9c,0x8e,0xab,0xde,0x79,0x17, 0x36,0x0d,0x6c,0x63,0x96,0x2f,0x6d,0x72,0x24,0xad,0x46,0xf8,0x01,0x00,0xf6,0xec, 0xd8,0x01,0xa4,0x13,0xca,0x5f,0xc9,0xfd,0x1c,0x06,0xe8,0xc5,0x18,0xf3,0x56,0x3e, 0x68,0xe5,0x4f,0x78,0xd5,0x97,0xf5,0x75,0x8c,0xd1,0x21,0xf8,0xe6,0x7e,0xa4,0x36, 0x0c,0x2d,0x11,0x5f,0x48,0x54,0x0e,0xd7,0xbf,0xc4,0x70,0x96,0x61,0x01,0xad,0x15, 0xe6,0x66,0xd9,0x76,0x89,0x70,0xbc,0xc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d,0xa6,0x4f,0x67,0x5b,0xeb,0x0d,0xa2,0x13,0xd3,0xdb, 0x65,0x61,0x87,0x9c,0x69,0x80,0x96,0xb9,0x95,0xab,0x1b,0xb7,0x8d,0x45,0xd8,0x39, 0x83,0x3d,0x5c,0xfd,0x1a,0x10,0x19,0x1b,0xf7,0x4e,0x78,0x04,0x19,0xa1,0x8a,0xce, 0xcd,0xf4,0x25,0x26,0x5f,0xc9,0xa5,0x28,0xe5,0x9b,0xde,0x05,0xd3,0x0f,0x3a,0x95, 0xb3,0xe6,0x3d,0x0a,0xc3,0x88,0x4c,0x60,0x75,0x78,0x5f,0xc2,0xc9,0xe3,0x70,0xb0, 0xbf,0xe9,0x12,0xa2,0x05,0xd8,0xd8,0x7b,0xba,0x97,0x7d,0xa3,0x82,0xb7,0xf5,0x67, 0x58,0x3d,0xbd,0xe2,0x69,0x30,0x12,0x9f,0x4d,0x1c,0x7b,0x27,0x1a,0xcb,0xec,0xf0, 0x57,0x78,0x3d,0x54,0x1e,0x89,0xe8,0x6a,0xbf,0x0e,0x57,0xd9,0xa4,0x79,0x8e,0xc2, 0x63,0x00,0x96,0xac,0x37,0xf8,0x92,0x29,0x66,0x21,0x34,0x46,0x8e,0x17,0xbb,0x6b, 0xad,0xed,0x44,0xc6,0xd4,0x61,0xd8,0x39,0xf7,0x9e,0x52,0x20,0x99,0x75,0xd3,0xa7, 0xc4,0x76,0x88,0xd2,0x7a,0x31,0xa7,0x94,0x5c,0x66,0x94,0xe7,0x1f,0xdf,0x47,0x7e, 0x61,0x8e,0x51,0x6d,0xd8,0x18,0x24,0x33,0x0f,0x42,0xaf,0x93,0xed,0x3b,0x3b,0x88, 0x3b,0x00,0x74,0x75,0xac,0xff,0xee,0x41,0x06,0x63,0x83,0xe1,0xcd,0xc9,0x8c,0x7c, 0xcb,0x8a,0x39,0xf2,0x75,0x22,0x49,0x66,0x84,0x54,0x6d,0x36,0x57,0x9f,0x31,0xb5, 0x94,0x41,0x9a,0x8c,0xdb,0x70,0xe4,0x33,0xc9,0x58,0x6e,0xb9,0xd9,0x06,0x50,0x61, 0xd3,0x9f,0x1b,0x00,0xd3,0x88,0x3b,0x72,0xb4,0x13,0x2b,0xab,0xca,0x5e,0xee,0xb3, 0xa5,0x16,0x6a,0x01,0x74,0x6b,0x5d,0x02,0xbf,0x66,0x76,0x96,0x66,0x2d,0x6b,0x2d, 0x57,0xf6,0x56,0xfa,0x5c,0xda,0x7b,0xd4,0xe0,0xbc,0xcf,0x1b,0x57,0x5b,0x07,0xbf, 0x7c,0x2c,0xee,0xf0,0xb5,0x79,0x12,0xbb,0x98,0xf9,0xc5,0x39,0x18,0x4a,0x09,0xbb, 0x7d,0xef,0xe7,0xf6,0x40,0x55,0xdf,0x0c,0x21,0x9d,0x57,0x23,0x33,0xd3,0xf7,0x84, 0xde,0xd5,0x59,0xe0,0xba,0x67,0xb5,0xe2,0x84,0xdc,0x70,0xc6,0x5c,0x7f,0x5c,0x0c, 0x96,0x49,0x12,0x52,0x37,0x11,0x90,0x92,0x4f,0xbe,0x69,0x7c,0x2f,0xd4,0x35,0xd2, 0xfb,0x2c,0xdb,0xbc,0x5b,0x54,0xb0,0x6a,0x53,0x37,0x17,0x8d,0xe7,0xac,0x7b,0x54, 0xe7,0x78,0x24,0x0c,0x17,0xce,0xea,0x2f,0x19,0xd9,0x77,0x2d,0xe9,0x61,0xc8,0x38, 0x6e,0xf0,0x6e,0x36,0x78,0xab,0xf7,0xc2,0x42,0x93,0xad,0x90,0x4c,0xb8,0x23,0x9b, 0x93,0xb7,0x8a,0xf5,0x6d,0xfa,0x5c,0x74,0x24,0xa4,0x16,0x82,0x2c,0x8c,0x02,0x24, 0x86,0xc3,0xbd,0x29,0x53,0x16,0x52,0xa4,0xa4,0x7f,0xc4,0xdb,0xf7,0x76,0x62,0x41, 0x88,0x5a,0x9c,0x16,0x0f,0xf5,0x4a,0x23,0x36,0xbf,0x92,0x44,0x4a,0x17,0xc0,0x62, 0x61,0x4e,0x7b,0xf0,0x79,0x23,0x69,0x8a,0x4c,0x0d,0xb2,0x6e,0x48,0xfa,0x73,0xf9, 0x15,0x6b,0x34,0x35,0xf5,0x70,0xf3,0xcb,0x96,0xae,0x25,0x6a,0x46,0x81,0xaa,0x39, 0xaf,0x4c,0x1f,0xa7,0x29,0x50,0xbf,0x80,0xf6,0x44,0xdc,0x47,0xae,0xdc,0x0c,0xfc, 0xba,0xb9,0x08,0x28,0xd0,0x9d,0x88,0x50,0x7e,0x72,0xba,0xd9,0xe0,0x6c,0x26,0x41, 0xa9,0x92,0x48,0x87,0x52,0x4f,0x91,0x5e,0x2f,0x30,0x3e,0xb6,0x78,0x80,0x90,0xbd, 0xb8,0x89,0x48,0x63,0xe9,0xc7,0x8d,0x78,0x11,0x97,0x75,0x96,0x21,0x6d,0xbb,0x65, 0x3b,0xf7,0xe1,0x8b,0x50,0xe4,0xbf,0x7d,0x51,0xcd,0x7f,0x6c,0x2a,0xae,0x02,0x04, 0x17,0x01,0x4f,0x33,0x60,0x45,0xd9,0x6d,0xe8,0x59,0x5c,0x0f,0x22,0x48,0x06,0xc6, 0xcc,0x4f,0x50,0x7d,0x80,0xfe,0xce,0x97,0x93,0xea,0x51,0x53,0x82,0x57,0x15,0xf4, 0xfb,0xfc,0x62,0xe9,0x14,0x5e,0x42,0xcd,0x6c,0x7d,0x3c,0xdd,0xf8,0xb4,0xc2,0x82, 0x84,0x71,0x2c,0x81,0x80,0xd0,0xaf,0xea,0x38,0xa5,0x89,0x72,0x93,0xba,0xc1,0x57, 0xa4,0xce,0xa7,0x23,0xf8,0x4a,0x39,0x52,0x29,0xcd,0x95,0xfd,0x3a,0x6e,0x5b,0x52, 0xea,0x97,0xfa,0x6d,0x51,0x28,0x1d,0x2c,0x10,0x3c,0x02,0x5b,0xe1,0x4f,0x6b,0x43, 0xf9,0x70,0x9b,0x2f,0x0c,0x45,0x06,0xaf,0x90,0x7f,0x6d,0x5b,0xf7,0x4a,0x84,0x4b, 0x50,0xc4,0x05,0xb3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0xaa,0x60, 0x4a,0xe5,0x68,0x22,0x2d,0x39,0x83,0x29,0x81,0x23,0x3e,0x48,0x33,0xd8,0x00,0xab, 0x60,0xbc,0x5c,0x1a,0x16,0x66,0x82,0xc7,0xa0,0xf9,0x9f,0x1c,0x48,0xdc,0xa8,0x5a, 0x43,0x05,0x36,0xbf,0x84,0x2a,0xb3,0x56,0x6c,0xfc,0xfb,0x08,0x0e,0x3e,0x69,0xe4, 0x06,0x27,0x20,0x98,0x22,0xba,0x7b,0x4c,0x5d,0xec,0x00,0x4e,0xd0,0x15,0x88,0x16, 0x45,0x3c,0xe8,0x6f,0xd4,0xe1,0x22,0xff,0x4e,0x75,0x9f,0x09,0x6f,0x1e,0x43,0x44, 0xd3,0x15,0x41,0xbb,0xdc,0xc0,0xad,0xd0,0x9a,0x7a,0xa4,0x9e,0x7d,0x16,0x36,0xd5, 0xae,0x40,0x21,0xc8,0x79,0xef,0x62,0xec,0x19,0x32,0xda,0xcd,0x23,0x6f,0x00,0x1e, 0x38,0x50,0xc3,0xbb,0x02,0xd6,0xcd,0x7e,0xcb,0x6f,0x8d,0xf1,0xcb,0xca,0x61,0x0b, 0x79,0x8f,0x96,0x88,0x38,0x65,0x14,0x93,0x72,0x47,0xfc,0x3e,0xca,0x30,0xd2,0x6e, 0x15,0x45,0x3b,0x50,0x30,0x35,0x25,0x9e,0x3e,0x9d,0xfc,0xab,0x5c,0x21,0x8c,0xe1, 0x65,0x33,0x2c,0xb0,0x48,0xc1,0x99,0x2d,0xb7,0x5a,0x62,0x17,0xf9,0xb0,0xf3,0x93, 0x31,0x76,0xa3,0x97,0xa5,0x1d,0xc2,0x92,0x44,0xcb,0x16,0xc1,0x5d,0x8e,0x3f,0x51, 0x42,0x4b,0x54,0xd1,0x63,0xaa,0xb0,0x6c,0x5e,0x19,0x01,0xdb,0x4a,0xb6,0x85,0xc3, 0xe9,0x39,0xc4,0x40,0xba,0x7c,0xca,0x43,0xb2,0x91,0x50,0x73,0x79,0xba,0x12,0x50, 0x27,0x19,0xf5,0xeb,0x77,0xb1,0xfa,0x76,0x71,0xa1,0x69,0xbc,0x50,0x36,0xd9,0x20, 0x09,0x47,0x6e,0xac,0x60,0x14,0x6f,0xf5,0x4b,0x68,0x62,0xec,0x60,0xa9,0x66,0x07, 0xa7,0xde,0x7d,0xcc,0x32,0xf3,0x4d,0xf3,0xbb,0x41,0x7a,0x85,0x01,0xcb,0x14,0x28, 0xb0,0x9a,0x32,0x49,0x36,0xd0,0x59,0xb8,0x24,0xf6,0xbe,0x9f,0x44,0xa4,0x02,0xb2, 0xc5,0x1f,0xa7,0xfa,0xcf,0x17,0x9a,0x4d,0x2f,0xca,0xca,0xaa,0x30,0xec,0x53,0x68, 0xe7,0xac,0x42,0xca,0x8e,0x3d,0x68,0x71,0xc5,0x3e,0x16,0xea,0x7b,0xae,0x24,0xc3, 0xbb,0x66,0xf6,0x77,0x60,0x97,0x5e,0xc8,0xe6,0x17,0xe0,0x6a,0x8d,0x7e,0xc5,0xa4, 0xea,0x62,0xd4,0xbb,0x5f,0xa0,0xdc,0x65,0x81,0x84,0xd8,0x41,0xc6,0x51,0x67,0x07, 0xbc,0x15,0x74,0xad,0xc4,0x2d,0x4c,0xde,0x53,0x71,0x44,0x69,0x6f,0x55,0x83,0x04, 0xd3,0x2d,0x94,0xc5,0x00,0xab,0x89,0xf4,0x2a,0xe7,0xab,0xce,0x09,0xe9,0x6c,0xb1, 0xc8,0xd3,0xb2,0xb8,0x38,0xa4,0xa0,0xb6,0xd2,0xc9,0xb9,0xf0,0x82,0xaa,0x86,0xa8, 0xb1,0x70,0x78,0xc6,0x2b,0x23,0x38,0x34,0x10,0xe0,0x6d,0xa2,0x96,0xa2,0x44,0xe9, 0xed,0x52,0xcf,0x96,0x44,0x13,0xa4,0xc6,0x89,0xf6,0x23,0x79,0x44,0xbf,0x35,0xa5, 0x74,0x90,0x86,0x2a,0xeb,0x63,0x6a,0xca,0x53,0x1e,0xcc,0x7c,0x64,0x88,0xc8,0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87,0xc2,0x55,0x8a,0x0d,0xa9, 0xc4,0x20,0x30,0x93,0x63,0xe6,0x01,0xf3,0xc0,0x42,0xb8,0x96,0x5a,0xe5,0xc6,0x26, 0x2f,0xb6,0xb3,0xfe,0x56,0x63,0xca,0xa9,0x1f,0xc3,0xed,0xba,0x6a,0x26,0xbf,0x99, 0x04,0xd5,0xec,0x39,0x9c,0x52,0x49,0xdd,0xd4,0x5a,0x04,0x3d,0x2b,0xb2,0x45,0x20, 0xab,0xf4,0x29,0x2d,0x22,0x0e,0xd7,0x19,0x4b,0x57,0x36,0x14,0x3c,0xd3,0x5e,0xcd, 0x14,0xec,0x28,0xb3,0xfe,0xb4,0x96,0x6f,0x7e,0x63,0x5c,0x67,0xf1,0x6c,0x92,0x66, 0x36,0x36,0xee,0xad,0xb2,0x24,0xbd,0x83,0x37,0x32,0x12,0xe8,0x14,0xdc,0x33,0xff, 0xfa,0xbd,0xc4,0xc2,0x6c,0x26,0x1b,0x8e,0xd4,0x93,0xd0,0xe5,0xc8,0xb7,0xf6,0xeb, 0x2a,0x05,0x44,0x89,0x67,0xcf,0x67,0xde,0x83,0x19,0xcb,0xa9,0x42,0xce,0x9f,0x7f, 0x3c,0x2c,0x98,0xed,0x78,0x0c,0xdf,0x94,0x3a,0x5a,0x2d,0xc3,0xce,0x8d,0xcd,0x51, 0xb9,0x8a,0xfa,0xf5,0xd8,0x89,0x1c,0x87,0x47,0xaf,0xa4,0x5c,0xea,0xb3,0x0c,0x30, 0x24,0x6b,0xca,0x47,0x41,0x41,0x57,0x38,0x5b,0x67,0xef,0x5b,0xc2,0xc9,0x28,0x60, 0x49,0x82,0x32,0x86,0xc1,0x6a,0x00,0xed,0x5b,0x3f,0xb5,0x14,0x13,0xae,0x46,0x7d, 0x95,0x1e,0xd1,0x6a,0x2c,0xaa,0x30,0x67,0xb5,0x2b,0x4e,0x1f,0x5e,0x2c,0x76,0xe6, 0xa3,0x9b,0xea,0x98,0xc7,0xc9,0xa3,0x38,0x6c,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b,0x40,0x0f,0x00,0x4f,0xfd,0xd4,0x93,0xd0,0x63, 0x75,0x2a,0x5a,0xf9,0x1a,0x5f,0x67,0x61,0x12,0x22,0xff,0x2a,0x38,0x9a,0xb9,0x81, 0x4f,0x2d,0xa0,0x91,0xc2,0x22,0xf7,0x34,0xdf,0xc7,0xa9,0xc4,0x2f,0x64,0x9a,0xd6, 0x33,0xde,0x58,0x44,0x38,0x58,0xae,0x9c,0xf9,0xaf,0x73,0xf9,0xf0,0x49,0x7d,0x4b, 0x61,0x5c,0xf5,0x67,0xd9,0x39,0xe7,0xcd,0x59,0xbc,0xae,0x72,0x4d,0x62,0x6b,0xdf, 0xf3,0xbc,0x54,0x6a,0x39,0x02,0x61,0x29,0xdb,0x2a,0x31,0x75,0x08,0x43,0xf6,0x36, 0x9e,0x22,0x9a,0xbd,0x21,0xf0,0xc9,0x62,0x93,0x53,0x60,0x66,0x19,0x98,0x7f,0xaa, 0x32,0x84,0xc1,0x99,0x1a,0x2c,0xef,0x40,0xba,0x33,0xba,0x93,0x7e,0xdd,0xe1,0x9c, 0x01,0x6d,0x88,0x34,0x2c,0x6f,0x29,0xb8,0xca,0x35,0x37,0x2e,0xbf,0x33,0x8e,0xe8, 0x87,0x34,0xb5,0xdb,0x4c,0x51,0x8a,0x4d,0x73,0x43,0x1e,0xa1,0x10,0x2e,0x74,0x55, 0x39,0x19,0xb3,0xd4,0x78,0x33,0x86,0x28,0x47,0x7a,0x48,0xe2,0x33,0x74,0x8b,0x0f, 0x39,0x79,0x39,0xeb,0xe7,0xdf,0xf1,0x5e,0x14,0x3c,0x07,0xc2,0xc4,0x4e,0xdc,0xe7, 0xe5,0x48,0x34,0xc3,0xf6,0x92,0xb6,0x5f,0x48,0x42,0x89,0x17,0x3e,0x07,0x1e,0x21, 0x33,0xb9,0x99,0xe4,0xdc,0x1f,0x81,0x96,0xa6,0x50,0x6d,0xe2,0xf5,0x58,0x24,0x25, 0xae,0x50,0xfe,0x27,0xe3,0x46,0x43,0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xfc,0xe7,0x60,0xb3,0x8b,0x95,0x83,0x63,0x06,0x53,0x57,0xc3,0x8c, 0x93,0xd3,0xea,0x2c,0x17,0xc4,0x54,0x5f,0xbf,0xae,0xc0,0x95,0x08,0xa3,0x68,0xc9, 0x76,0xb8,0x0e,0x71,0x43,0x91,0xa4,0xae,0x81,0x4c,0xa6,0x36,0x68,0xc4,0x4a,0xf9, 0xf3,0x59,0x9a,0xc8,0x4f,0x52,0x94,0xdb,0x38,0x3f,0xf0,0x90,0x28,0x76,0x1f,0x53, 0x8f,0xb2,0x41,0xd3,0x6b,0x35,0x6e,0x6c,0xd0,0x5d,0x31,0xce,0x7c,0x41,0x50,0xc8, 0x3d,0xda,0x6f,0x66,0x17,0x03,0xab,0x60,0x8a,0xdc,0x19,0x60,0x4e,0xd3,0x62,0xdb, 0x5e,0x4d,0xf4,0x99,0x39,0x9f,0x0e,0x4a,0x03,0xed,0x34,0xed,0x25,0xeb,0x1e,0x96, 0xa9,0x14,0x21,0x40,0xd3,0xb9,0x20,0x64,0xd7,0x74,0x62,0x05,0xfe,0xb3,0x80,0xde, 0x18,0x7e,0x2f,0xed,0x48,0xfd,0x6c,0x95,0xc4,0x45,0xd5,0x39,0x0c,0x9c,0xab,0x8d, 0x2d,0xf1,0xcd,0x1e,0x43,0x20,0x60,0xf9,0xca,0x01,0x9b,0x13,0xfe,0x74,0x59,0xa2, 0x25,0xa9,0xc0,0x58,0x2c,0x86,0xfe,0x84,0x31,0x80,0x42,0x96,0x82,0xc6,0xb6,0x51, 0xc3,0x97,0x29,0x2d,0xb8,0xa1,0x92,0xd9,0xe7,0x72,0xe0,0x41,0x58,0x46,0x0e,0x8a, 0x07,0x8c,0xe9,0xce,0x77,0x78,0x3a,0x8a,0x9e,0xef,0x17,0x53,0xea,0x93,0xff,0x69, 0x35,0x2c,0x1c,0x2a,0xb2,0x50,0x45,0xc1,0xe8,0x8a,0xef,0x22,0xe1,0x4c,0xa0,0x24, 0x58,0x77,0x49,0x6a,0x3f,0x7e,0x13,0x91,0xd9,0x8d,0xc0,0xce,0x53,0x50,0x80,0x9a, 0x47,0x3d,0x05,0x57,0xdb,0xb4,0x56,0x7e,0x18,0x03,0xa8,0x85,0x43,0x0e,0x80,0x18, 0x98,0x90,0xd0,0xf4,0x6d,0xcc,0x30,0x44,0xeb,0x8d,0x4d,0xe0,0x77,0x7b,0x5c,0x20, 0xce,0xc6,0x52,0x07,0x18,0x8f,0xa9,0x61,0x99,0x75,0x93,0x58,0xe0,0xad,0x92,0xa4, 0x41,0x86,0xb2,0xb5,0x72,0x9d,0x4f,0x5c,0x65,0x5e,0x0d,0xd8,0xef,0x30,0xf5,0x9c, 0xe1,0xc5,0xa5,0x0f,0x7b,0x28,0xe7,0x23,0xb6,0xbf,0x9b,0x1d,0xbb,0x5f,0x21,0xe9, 0x17,0x07,0x1e,0x68,0x4c,0x96,0xc0,0x00,0x02,0x4b,0x80,0x68,0x59,0x65,0x42,0x2f, 0x25,0x01,0x0b,0x0f,0x19,0x9f,0xd0,0xcb,0x6e,0x8d,0x26,0xb1,0x74,0xa8,0xba,0xc6, 0x76,0x1c,0x5a,0xb4,0xd4,0x16,0x02,0xce,0xf6,0x95,0xae,0xd7,0x52,0x7f,0x96,0xd1, 0x34,0x20,0x69,0x0e,0xe8,0xde,0x31,0xe7,0x0e,0x97,0xea,0x89,0x29,0x0f,0x5c,0x23, 0x43,0xb1,0xaf,0x01,0x2c,0xac,0xcc,0xac,0x2e,0xc0,0x95,0xa7,0xc1,0x68,0x5d,0xab, 0x60,0x7a,0xfa,0x83,0xd1,0x89,0x06,0xba,0x33,0x8f,0xec,0xd4,0x2f,0xf0,0x5d,0x0b, 0x92,0xb8,0xfd,0xec,0x70,0xd7,0x8a,0x8a,0x52,0x47,0x8b,0xf0,0x6e,0xc2,0x0a,0x91, 0x4c,0xbe,0x5f,0x74,0x43,0x85,0x9e,0x34,0x62,0x1e,0x68,0xe8,0x47,0x4e,0x38,0xd3, 0x5a,0xc0,0x91,0x6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0x87,0x05,0x87,0x46,0x74,0xc4,0x69,0xe7,0xdd,0xba,0x73,0x17,0xe0,0xfc,0x37, 0x8c,0x53,0x49,0x0b,0xba,0xbc,0x2c,0x9c,0xcb,0xf0,0xf8,0x6f,0xaa,0x51,0x29,0x16, 0xbf,0xa8,0xb4,0xa8,0x08,0xfb,0x70,0xa0,0x09,0xd0,0xb2,0xd1,0x6d,0xb4,0x5b,0x57, 0xe6,0x95,0xc0,0x99,0x6b,0x11,0xb2,0x4a,0x48,0xb6,0xc5,0x23,0x7b,0x91,0x71,0xd6, 0x46,0xc7,0xea,0xfc,0xfe,0xc4,0xea,0x30,0x03,0x54,0x6e,0xc7,0x2c,0x48,0xf0,0xc7, 0x58,0x51,0xa5,0xd5,0xf7,0x3e,0x94,0x0f,0x85,0xdc,0x20,0x78,0x03,0x5c,0x52,0x72, 0x7c,0xbe,0xb8,0xd6,0xb3,0xef,0x98,0xc1,0xcf,0x60,0x5e,0x8e,0x7e,0x19,0x84,0xb8, 0x18,0xe5,0xda,0xe0,0xbc,0x58,0x63,0x1a,0x0c,0xce,0xb3,0x88,0x77,0xe0,0x96,0x8f, 0x84,0x1c,0x31,0x33,0x02,0x38,0x7d,0x0e,0x82,0x7d,0x9e,0x53,0xb3,0x6c,0x16,0x94, 0xb8,0x4a,0xba,0x64,0xef,0x98,0x75,0x34,0xd9,0xae,0xa1,0xe9,0xd2,0xc5,0x60,0x4c, 0x93,0x14,0xdc,0x3d,0xfe,0x20,0x0b,0x02,0x6d,0x0a,0x15,0xe1,0x2d,0x00,0xc6,0xe0, 0x3c,0xf0,0x17,0x4b,0x1e,0xb5,0x88,0xbb,0x4a,0xc5,0xb2,0x4d,0x23,0xc4,0x54,0x9f, 0xec,0x56,0x72,0xc7,0x97,0x8f,0x6f,0x65,0x45,0xd3,0xc9,0xce,0x1e,0xb3,0x25,0xb2, 0xf8,0x07,0x26,0xa0,0xe7,0x30,0x16,0x49,0x79,0x99,0x06,0x25,0x17,0xde,0xf6,0x95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,0xba,0x03,0x9d,0x1c, 0xd3,0x4b,0xcc,0x3a,0x9c,0x72,0x6f,0x0d,0xd1,0x79,0x8e,0x2f,0x81,0x84,0xc0,0x6a, 0xf0,0x29,0xf4,0x99,0x5b,0x42,0x94,0x65,0x29,0x3e,0x83,0x2b,0x3a,0xca,0x8b,0x34, 0x1b,0x31,0x8a,0xf4,0x91,0xde,0x97,0x47,0x76,0x99,0x7e,0x58,0x4c,0x98,0xe0,0x40, 0x06,0xe2,0x0f,0xd7,0xf0,0x24,0x81,0x36,0x0c,0xfa,0xba,0x13,0xbd,0x3a,0x79,0xd8, 0x49,0x5e,0xd0,0x43,0x94,0xe9,0xf5,0x9e,0x0d,0x99,0x03,0x08,0x02,0xcd,0x52,0xe4, 0xfc,0x2f,0xb4,0xd1,0x47,0x93,0xdc,0xda,0x85,0x41,0x26,0xa5,0x95,0x83,0xc8,0xc8, 0x6c,0xd9,0x92,0x96,0xf6,0xba,0x5b,0x4f,0xd3,0x2c,0xfe,0x7e,0xbf,0xb9,0x7d,0xd1, 0x6a,0xb9,0x7a,0x17,0x77,0x6e,0x28,0x4e,0xac,0xea,0x45,0x8c,0xba,0xd5,0xbb,0xd8, 0xfd,0x5c,0xff,0xde,0xf8,0xea,0x3c,0x2f,0x00,0x62,0x01,0x04,0x92,0xc3,0xe6,0xc2, 0x87,0x33,0xd1,0x00,0xa1,0xf3,0x48,0xa9,0xf3,0x64,0x74,0x1c,0x3e,0x64,0x89,0xd8, 0x32,0x18,0x5f,0xfa,0x7f,0xbd,0xa2,0x14,0xae,0x17,0x65,0x1e,0x41,0x97,0x66,0xe2, 0x20,0x9c,0xa1,0x26,0xbb,0x38,0x1a,0x7d,0xd1,0x53,0x2b,0x92,0x19,0x49,0x08,0x66, 0x7e,0x85,0x67,0xde,0x8f,0x13,0xd5,0xc0,0x0e,0x16,0x57,0x2a,0x81,0xbd,0x14,0xde, 0x44,0x07,0xfb,0x95,0x8a,0xc6,0x73,0xc7,0xfe,0x4f,0x35,0x60,0x38,0x72,0x0a,0xcf, 0x87,0xe0,0x6e,0x77,0x04,0x98,0x52,0xeb,0x91,0x6d,0xe5,0x47,0x90,0xbd,0x7a,0x6b, 0x90,0x5c,0x92,0xd4,0x5b,0xe5,0x99,0x72,0xf1,0xae,0x45,0xfe,0x5a,0x2f,0xca,0xa1, 0xff,0x4b,0x0a,0x4c,0x7f,0x94,0x11,0x0c,0x83,0xcf,0x05,0x57,0xa6,0xaf,0x78,0x2f, 0xfb,0x8a,0x36,0x83,0x05,0x2f,0x3b,0x41,0x08,0x89,0x94,0x72,0x46,0x32,0x73,0x98, 0x1c,0x8e,0x3c,0xf9,0x1b,0x92,0x0e,0x23,0x12,0x59,0x78,0x19,0x6d,0x50,0xc1,0x20, 0x5c,0xf7,0x87,0x50,0x37,0x76,0x67,0xcb,0xe9,0x94,0x25,0x0b,0xb7,0xce,0x54,0xf4, 0x23,0x5c,0x50,0xad,0xce,0x90,0x03,0x81,0xe4,0xa3,0x09,0xf7,0xf0,0x53,0x87,0x04, 0xac,0x64,0x63,0x2b,0x84,0xcb,0x3b,0xd7,0xd3,0xe8,0xf1,0x1f,0xb6,0x24,0x42,0xdf, 0x45,0xd3,0xc7,0x97,0x79,0x42,0x60,0x5a,0x2a,0x68,0xa4,0x8d,0x83,0x87,0x18,0xae, 0x8f,0x86,0xfc,0x38,0x58,0xaa,0xa9,0x07,0xb4,0x06,0xf8,0x3c,0x9c,0xc0,0x14,0xff, 0xab,0x39,0x09,0x00,0x45,0x91,0x38,0x94,0x81,0x33,0xdd,0x04,0x33,0x24,0xa2,0x94, 0x9b,0x58,0x1e,0x8b,0xd8,0x1a,0x18,0x60,0xa4,0x75,0x9f,0x10,0xe3,0xeb,0xc2,0xb1, 0x6a,0xb2,0x48,0x50,0xf3,0xca,0xa5,0xcd,0x17,0xeb,0x9e,0xef,0xdf,0xe8,0x34,0x47, 0x9f,0x35,0x1b,0x7f,0xd9,0x1c,0x41,0x86,0x71,0x03,0x24,0x2c,0x60,0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9,0x09,0xaa,0xae,0x9d,0x44,0x12,0x78,0x35,0xd8,0xc3,0x97,0x00, 0xde,0x00,0xf5,0xc2,0x0a,0xf1,0xcc,0x70,0xde,0x25,0xea,0xf4,0xf0,0x05,0xe8,0xec, 0x5f,0x1f,0x3a,0x1f,0xe8,0xe1,0x63,0xb8,0x64,0x76,0x80,0xd5,0xbe,0x31,0x26,0x75, 0x2f,0xaa,0x2e,0xd7,0xb0,0x68,0x46,0x1a,0x16,0xb6,0xa5,0x81,0x01,0x17,0x49,0xd0, 0x52,0x82,0xa5,0xc4,0x9c,0x8b,0xd1,0x6a,0x31,0x53,0x2b,0x69,0xb5,0x35,0x55,0xea, 0x71,0xff,0xfd,0xcf,0x26,0x08,0x55,0xb6,0x24,0xea,0x87,0x8d,0xc0,0x2a,0x33,0x84, 0x86,0xa4,0x13,0xb8,0x08,0xda,0x15,0x76,0x31,0xdc,0xfb,0x37,0x67,0x8f,0x0c,0x3c, 0xc0,0x4a,0x8a,0x28,0x04,0x6c,0x90,0x9b,0x48,0x6e,0x5a,0x44,0xe3,0x4e,0x13,0x64, 0x0e,0x89,0xdf,0x3c,0x93,0x2b,0xdc,0xb4,0x3b,0x82,0xb2,0x2f,0x65,0xa8,0x37,0x01, 0xb6,0xe0,0xac,0x4e,0x75,0x78,0xc6,0x3b,0x66,0x8e,0xa1,0x0b,0xe0,0xa7,0xf2,0x72, 0xae,0xdb,0x14,0x14,0x92,0x54,0xf5,0x28,0x18,0x5c,0x3f,0x8a,0xa4,0x28,0x3c,0xea, 0xf3,0xdf,0x32,0x2d,0x15,0x00,0x95,0x9c,0x53,0x4b,0x45,0x69,0x97,0x4c,0xc8,0xe8, 0x54,0x6d,0x03,0x09,0x7b,0xde,0x55,0xd7,0x12,0xb2,0x81,0xcb,0x53,0xc9,0x26,0x33, 0xc8,0xff,0x05,0xe4,0x23,0x3b,0xda,0xeb,0x57,0xc0,0x3e,0x64,0x14,0xc9,0xb9,0xc3, 0x70,0x49,0xe8,0xf4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e,0x4e,0x4a,0x31, 0xf6,0x3c,0x80,0xa4,0x72,0x7b,0x71,0xb0,0x93,0x49,0x6f,0xfa,0xa4,0x41,0x84,0x9b, 0x8b,0xb5,0x1d,0x81,0xe5,0xd1,0xd2,0xb1,0x2a,0x79,0x9b,0x0e,0x85,0xac,0xd1,0xf0, 0xc9,0x97,0xc5,0xe3,0x32,0xd2,0x70,0x7a,0x7c,0x6d,0xd3,0x5a,0x33,0x17,0xd6,0x16, 0x58,0xf1,0xd5,0x61,0x73,0x96,0xde,0x38,0xe5,0x95,0xf6,0x42,0x53,0x7a,0xcc,0x45, 0x46,0x96,0xf3,0x61,0x93,0x91,0x2c,0x6b,0x6f,0xd1,0xe6,0xec,0xb7,0xa6,0xd3,0x2c, 0xf9,0xa4,0x78,0x78,0xdf,0xaf,0x69,0xcd,0x82,0x64,0x30,0x67,0xe1,0x92,0xf5,0x25, 0x14,0x2a,0x86,0x11,0xd8,0x80,0x86,0x40,0x16,0xf2,0x9b,0xf6,0xd2,0x1a,0x76,0x52, 0xc7,0x48,0x96,0x44,0x3c,0x51,0xd4,0x04,0x17,0xd2,0x78,0xc4,0x23,0x03,0xf5,0xb4, 0x86,0x41,0x29,0xd3,0xd5,0x6f,0xc6,0xa5,0x78,0x7f,0xe3,0x05,0x19,0x33,0xdd,0x03, 0xf7,0x06,0x3d,0x36,0x6b,0x63,0x01,0x62,0xfd,0xfa,0xc2,0xbd,0xba,0x16,0x36,0xa1, 0xa8,0x8b,0x37,0x05,0x24,0x84,0x27,0x2e,0xb5,0x22,0xff,0x1f,0x6b,0xdd,0xaa,0x3e, 0xb3,0xc6,0x08,0x03,0x5f,0x3b,0x77,0x24,0x61,0xf7,0x7d,0x97,0x24,0xb3,0xbe,0x2f, 0x25,0xaa,0xfb,0xf0,0xd7,0x6a,0x3c,0x18,0xcb,0xa8,0x9d,0x7a,0x65,0x5d,0x90,0x92, 0x12,0x03,0x4e,0x18,0xd8,0x65,0x09,0x19,0xeb,0xba,0xb2,0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x0f,0x38,0xfe,0x42,0x85,0xd7,0x24,0x38,0xd0,0x97, 0xf6,0x8e,0x95,0x63,0xda,0x18,0x43,0x27,0x91,0x36,0xd1,0x44,0x3e,0xde,0x56,0x9a, 0xe5,0xa3,0x48,0xaa,0xca,0x70,0x02,0x33,0xd6,0x11,0x4c,0x2f,0x08,0x74,0xb7,0xec, 0x54,0x8f,0x00,0x3a,0x48,0xf6,0x24,0x38,0x20,0x9a,0x90,0x84,0x34,0x0d,0x53,0xfd, 0x4f,0x07,0x3a,0x7c,0x90,0x68,0x1c,0x60,0x97,0xcf,0x71,0xeb,0xca,0x0f,0x1c,0x7b, 0x67,0xf9,0xf3,0x5f,0x82,0x7b,0x86,0xf0,0x1d,0x87,0x6a,0x65,0x07,0x72,0x43,0xeb, 0xfe,0x72,0x46,0x2e,0x92,0xe9,0x8d,0xb0,0xa6,0xf2,0x5c,0x0c,0xe6,0x20,0x01,0xf1, 0xa9,0xe0,0xf6,0xa5,0x0d,0x7a,0x35,0x7a,0xa6,0xa9,0x08,0x43,0x35,0xb4,0xee,0x68, 0x9b,0x70,0x7f,0x9e,0xeb,0x5f,0xe3,0xbf,0x50,0x1b,0x2b,0x95,0xcb,0x69,0xd2,0x12, 0x14,0xeb,0x86,0xdb,0x35,0x62,0x85,0xcc,0xdb,0x01,0x30,0x8d,0x75,0xe5,0xd3,0x42, 0x2a,0xae,0xb8,0x1b,0x12,0x30,0x58,0xcf,0xb3,0xc3,0x74,0x51,0x07,0x52,0x62,0xba, 0xb5,0xba,0x0a,0xbc,0xbb,0x01,0xf6,0xe2,0x8d,0x85,0x54,0x70,0x66,0xfa,0xf0,0x31, 0xf7,0x41,0x09,0x34,0xff,0x07,0x9d,0xfc,0x69,0x40,0x6a,0x47,0x58,0xd6,0x62,0xfc, 0x77,0x72,0x6e,0x45,0x3f,0xad,0x04,0xe2,0x59,0x48,0x49,0x7c,0x30,0xca,0xf7,0x57, 0x21,0x98,0xc8,0x40,0x7e,0x14,0x23,0xd5,0xd1,0x63,0x74,0x37,0xf7,0x41,0x54,0x6e, 0x51,0xa8,0x8a,0x02,0x89,0xc8,0x9d,0x22,0x40,0x29,0x00,0x28,0x5e,0x84,0x27,0x65, 0xad,0x94,0xcb,0xfd,0xd4,0x87,0x6b,0x9c,0xf0,0xd9,0x83,0x1f,0xfa,0x01,0xa6,0xa3, 0xa7,0x11,0xb1,0x02,0x62,0xf5,0x13,0xd0,0x0d,0x1d,0xf6,0x2f,0x6f,0xad,0x42,0x15, 0x7c,0xc7,0xd2,0x5c,0xa6,0x2c,0xd7,0x0e,0x36,0xd2,0x21,0xb9,0xa2,0x47,0x0f,0x6b, 0x3f,0x3f,0xba,0x47,0x6b,0x9f,0x47,0x12,0xef,0xcf,0x26,0xbf,0xb0,0x7a,0x26,0x59, 0x42,0x04,0xdf,0x65,0x1f,0x8d,0x8c,0x42,0xda,0xb9,0xe0,0xd3,0x5b,0x45,0x19,0x40, 0x0f,0xd4,0x0a,0x50,0xf8,0x56,0x77,0x3e,0xbc,0xd0,0xab,0xc4,0xcd,0xab,0xda,0xec, 0x69,0xdd,0x8a,0x3c,0x7a,0x99,0x45,0x9c,0x52,0xe2,0x6f,0xfd,0xc3,0xe8,0xd7,0x3c, 0xdc,0x94,0x17,0xaa,0x85,0x4d,0x6c,0x83,0x5c,0x71,0x94,0x38,0x00,0xe1,0x17,0x5c, 0x75,0x40,0xa8,0x04,0x9a,0x90,0xe2,0x06,0x02,0x04,0x22,0x6d,0x4a,0xfe,0x5e,0x8d, 0x34,0x82,0x08,0x66,0x06,0x72,0xe5,0x40,0x72,0x52,0x30,0x8a,0xc8,0xe9,0x80,0x0e, 0xf7,0x29,0x44,0xc0,0x51,0x0c,0x11,0x7b,0xff,0x69,0x27,0x77,0x84,0x29,0xda,0xb4, 0xa8,0x3e,0x14,0x9c,0xa2,0x81,0xf9,0x87,0xb2,0x78,0xcd,0xa1,0xce,0x85,0xe6,0xaa, 0x93,0x0c,0x68,0x6a,0x7b,0xe0,0x37,0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0xce,0x2a,0x47,0xa0,0x85,0xe1,0xc8,0x8f,0xdb,0x48,0x60,0x89, 0x08,0x65,0xe9,0x3f,0x0d,0xc8,0x99,0x9e,0x64,0x65,0x6d,0xb7,0x9b,0x4b,0x3a,0x0e, 0xf0,0xd1,0x3a,0x7f,0x4a,0x07,0x23,0x6c,0x86,0x33,0xd7,0xf1,0x78,0x2b,0x35,0x86, 0x81,0x6f,0x51,0x26,0xb7,0xda,0x86,0x78,0x5a,0x30,0x18,0xd2,0x94,0x0c,0x69,0x24, 0x29,0x9a,0x0f,0xf5,0x67,0x7e,0x3d,0x77,0x91,0x55,0xc3,0x27,0x09,0xfd,0x63,0x22, 0x34,0xab,0x21,0x4d,0x63,0x30,0x73,0x99,0xdc,0xfb,0x0b,0x91,0x16,0x07,0x2e,0xbd, 0x93,0xc0,0x72,0x34,0x2f,0xc7,0xf5,0x5c,0x48,0x4c,0x57,0xac,0x6a,0x77,0xdd,0x74, 0xf6,0x74,0x2e,0x4d,0xcb,0x8f,0x6c,0xe2,0x3f,0xce,0x98,0xbc,0x5e,0xe8,0x60,0xf5, 0x74,0x0a,0x44,0xf1,0xde,0x5b,0x79,0xeb,0x6f,0x06,0xd5,0x58,0x1f,0xeb,0x05,0xfd, 0x27,0x1d,0x85,0xb6,0xb7,0x20,0xa2,0xd7,0x2d,0x62,0x05,0x34,0x73,0xc2,0x38,0x1b, 0x9d,0x6a,0x33,0xda,0xd4,0xd4,0xf9,0xf8,0x5b,0x69,0x48,0xaf,0x7a,0x61,0x88,0x00, 0x27,0x39,0x3d,0x51,0xc7,0x4a,0x84,0x86,0x58,0xec,0xbb,0xff,0x01,0x5c,0x67,0x8b, 0x7c,0xd0,0x2e,0x19,0x6a,0x0f,0x24,0x51,0xab,0xf4,0x0f,0xa1,0x32,0xb6,0x26,0xf0, 0xe8,0x49,0x92,0x06,0x5a,0x11,0x5a,0x5d,0x59,0xc1,0x9d,0x39,0x17,0x9d,0xc3,0x78, 0x71,0x71,0xfb,0x9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b1,0x37,0x8f,0x71,0xae, 0x40,0x93,0x0b,0xe7,0xb1,0x0e,0xd0,0x0e,0x28,0xe0,0x32,0x13,0x20,0x13,0xfd,0xe4, 0x87,0xe4,0x9e,0x49,0xf4,0xc9,0x12,0x8f,0x6c,0x3b,0xc7,0x75,0xcb,0x06,0x7c,0xd8, 0xd4,0x18,0x66,0x0c,0xc6,0x63,0x89,0x05,0x36,0x67,0x50,0xb6,0x39,0xd9,0x9c,0xae, 0x4f,0xdc,0xe1,0xb1,0xf2,0x2c,0xc5,0xe7,0xce,0x67,0x9a,0x1b,0x3f,0x5b,0x48,0x1e, 0x51,0xac,0x10,0x01,0xf9,0xed,0x36,0x1b,0xc5,0x30,0xc8,0x8f,0xa1,0x89,0x51,0xb9, 0x36,0xd4,0xb1,0x04,0xd4,0x0f,0xcf,0x9a,0xf1,0x00,0x08,0x7b,0x58,0x68,0x8d,0x31, 0x74,0x1e,0xb2,0xbe,0x9b,0xd7,0x74,0x31,0x2f,0x23,0x92,0xa9,0x80,0x63,0x4f,0xcc, 0x5a,0x07,0x3c,0xa7,0xb6,0xb1,0xcf,0x49,0xfe,0xf3,0x7e,0x60,0x62,0x14,0x09,0xac, 0x50,0xa5,0x08,0x89,0x82,0x8f,0x3e,0x39,0x3c,0x07,0x23,0x3d,0x84,0x86,0xa3,0x67, 0xdb,0xf2,0x8a,0x86,0x52,0x13,0x63,0xae,0xa3,0x60,0x00,0x8a,0xb4,0x05,0xf3,0xda, 0x6a,0xa4,0x80,0x17,0x47,0xa7,0x61,0x1e,0x45,0x3a,0xf7,0xa7,0xb2,0x85,0xf8,0x2b, 0xae,0xa6,0x11,0x84,0xfd,0x5a,0x19,0xf8,0xca,0x45,0x75,0xcf,0x65,0xb8,0x13,0x4f, 0xa3,0x42,0xe7,0x33,0x21,0xe1,0x23,0x39,0x57,0x73,0x4e,0x9c,0xe3,0xea,0x3c,0x90, 0xf5,0x37,0x9b,0x56,0x47,0x62,0x40,0xbf,0x95,0xb5,0xbd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0x30,0xbd,0x9e,0x09,0xa1,0x1c,0xff, 0x9f,0x4d,0xb0,0x73,0x8b,0xb3,0x3c,0x5e,0x1d,0x4e,0x9b,0xdf,0x38,0xce,0xe0,0x7a, 0xe5,0xb7,0x67,0xa5,0x6a,0xa6,0x5e,0xbb,0x69,0x31,0xb2,0x79,0x38,0x7a,0x54,0x91, 0x50,0x39,0x97,0xfd,0x15,0xb2,0xc6,0x6b,0xb2,0xb8,0x92,0x49,0x12,0xcf,0x13,0xea, 0xdf,0x1c,0xc2,0xcf,0x6e,0x64,0xf1,0xab,0xd2,0x0b,0x39,0x23,0xa4,0x36,0x97,0xc1, 0x40,0xef,0x39,0x82,0x0e,0xea,0x1c,0x56,0x0c,0x4e,0x13,0x67,0x7e,0x37,0x57,0x32, 0x06,0x0b,0x13,0x09,0x53,0x22,0x14,0xef,0x6a,0x2e,0xb3,0x1e,0x0e,0x89,0x30,0x76, 0xd3,0xcc,0x54,0x27,0x04,0xb8,0x68,0x7f,0x79,0xb1,0x7b,0x7f,0x00,0x69,0xc7,0x8b, 0x27,0xbb,0xee,0xe3,0x52,0xd2,0x82,0x3d,0x39,0x5f,0xe4,0xb8,0xbf,0x09,0x59,0x7d, 0x46,0x1f,0x95,0xb6,0xb3,0x24,0xa1,0xe0,0x89,0x8a,0xcd,0x91,0x3b,0xa2,0xa9,0x1e, 0x35,0x13,0x92,0x8d,0x2b,0xb0,0xa7,0xb5,0x26,0xf9,0x47,0xa5,0x75,0xd6,0x67,0xf4, 0xc1,0xad,0xda,0x01,0x02,0x47,0xd5,0x99,0xe9,0x6b,0x77,0x72,0x84,0x12,0x87,0xdb, 0xda,0xa5,0xeb,0x4e,0x60,0xa4,0x42,0x38,0x38,0x73,0xc8,0x21,0x59,0x71,0x8b,0x23, 0x48,0x5f,0x40,0x97,0x83,0x76,0xd4,0x97,0x61,0x7a,0x6c,0x3f,0x85,0x55,0xa8,0x22, 0xc3,0x3c,0x3e,0x09,0x3e,0xd6,0xfd,0x8c,0x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,0x57,0x01,0x8a,0x65,0xd6,0xa0,0x67, 0xee,0xb1,0xc2,0xb6,0x28,0x35,0x8b,0x8c,0x61,0x65,0x01,0xdf,0xee,0x00,0xeb,0x9b, 0x36,0x2e,0xf2,0xa7,0x00,0x74,0x40,0xcc,0xf4,0x36,0x07,0x00,0x63,0x88,0x1d,0x98, 0x60,0x7e,0x44,0x18,0x81,0xba,0x11,0xc4,0x31,0x2c,0xbe,0x39,0x90,0x34,0xc7,0xd7, 0xe8,0x9f,0xea,0x9c,0x26,0x93,0x65,0xcf,0x3a,0x29,0x0a,0x5a,0x29,0xe1,0x38,0x2f, 0xd8,0xe0,0x2f,0x1a,0x3f,0xc4,0x92,0x23,0x93,0x11,0xa7,0x78,0x2d,0x91,0x2a,0xb2, 0xba,0x11,0xa0,0xa1,0x9a,0x96,0xa5,0x7e,0x8e,0x86,0x44,0xee,0xfb,0x88,0x94,0x1b, 0xef,0x8d,0x60,0xe9,0x45,0x50,0x2d,0x39,0xe6,0x38,0xd4,0xf5,0xe6,0x9d,0x34,0x51, 0x64,0x1f,0x58,0x75,0x60,0xa1,0x4b,0x03,0xfc,0xe1,0x05,0xdd,0xa2,0xa0,0xf2,0x89, 0xc6,0x58,0x21,0xf9,0x08,0x1b,0x5d,0x2e,0x19,0x0d,0x33,0x7e,0xeb,0x21,0x23,0x9a, 0x7a,0xca,0xbf,0x6b,0x6d,0xee,0xba,0xd9,0x00,0xd8,0x46,0xac,0xec,0x9b,0x1d,0x7a, 0xae,0xd9,0x93,0x1b,0xdb,0x5d,0x6e,0xec,0xc8,0x7f,0x2c,0xd5,0xc0,0x12,0x1f,0xee, 0x78,0x40,0x05,0xd7,0xd1,0x1f,0x56,0xa8,0x06,0xf7,0xf4,0xa4,0xf1,0x0a,0x15,0xab, 0xb2,0xc8,0xbd,0xe9,0xce,0x09,0x38,0x9f,0xba,0x18,0x21,0xff,0x70,0x22,0x28,0xaf, 0x4f,0xb4,0x9b,0xf0,0x6b,0x22,0x58,0xdf,0x10,0x33,0x64,0x0c,0xfe,0x39,0x65,0xc4, 0xd8,0x80,0x84,0x60,0xe9,0x2c,0x8f,0xcb,0xb2,0xca,0x4e,0x4d,0x68,0x59,0x25,0x44, 0x35,0x4b,0x17,0x1b,0x1d,0x78,0x18,0x1a,0x57,0xbc,0x14,0xfd,0xfb,0x11,0x51,0x1e, 0x93,0xcf,0x08,0x6b,0x20,0x5b,0x43,0x3d,0x31,0x7e,0xcf,0x6a,0x81,0xe4,0xb8,0x84, 0x91,0x8a,0xf0,0x66,0x0a,0xe1,0x0e,0xf9,0xef,0x9b,0x1c,0x57,0x74,0x30,0xc2,0x00, 0x6a,0x25,0x7a,0xc9,0x1c,0x8b,0x94,0x96,0x83,0x01,0x5f,0x84,0x66,0xc9,0x68,0xe2, 0x10,0x01,0xd5,0x8a,0x52,0x83,0xe7,0x79,0x79,0x35,0x41,0x52,0x95,0x7c,0x82,0x91, 0x7c,0x62,0x81,0x79,0xa7,0x8f,0x2d,0xd3,0xca,0x38,0x3c,0x7c,0x6b,0x6a,0x98,0xed, 0x8d,0x02,0x2d,0xfd,0x63,0xa0,0xa2,0xbc,0xdf,0x8b,0xc3,0x9a,0x2f,0xdd,0x10,0xe5, 0x0e,0x51,0x8d,0x02,0xe3,0xec,0x10,0x64,0xe5,0xab,0xb3,0x1a,0xe4,0x96,0x4f,0xce, 0x9a,0x4c,0xdb,0x6a,0x51,0x10,0x20,0x62,0x89,0x1a,0x93,0x00,0x43,0x82,0x52,0xe6, 0xa6,0x87,0x08,0xf4,0xc4,0xde,0xf0,0xef,0x6f,0xce,0xf9,0xc3,0xd7,0x06,0xce,0xfb, 0xbe,0xe2,0x3f,0xd7,0xa3,0x5c,0x5b,0x50,0xc2,0xb7,0x37,0xd4,0x6a,0xd2,0x06,0x3e, 0x83,0x70,0xe5,0x10,0x4e,0x13,0xec,0x89,0x9f,0x68,0x0f,0xdf,0x1a,0x5f,0x4a,0xa4, 0x5c,0xcd,0x43,0xcf,0x45,0x89,0xf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x2a,0xf7, 0x9e,0x95,0xd4,0xda,0xc2,0xc5,0x53,0x5a,0xc1,0x14,0xdd,0x09,0x77,0xd7,0xc0,0x97, 0x6b,0x5f,0x64,0x3f,0x9c,0x89,0xa9,0xee,0x93,0x23,0x3c,0xd8,0x87,0x39,0x88,0xc9, 0x30,0x6d,0xf0,0x82,0x7d,0x69,0x1b,0x6a,0xb0,0xc6,0x13,0x00,0x1c,0xcc,0x65,0x85, 0xcc,0x14,0xa4,0x5a,0x05,0x48,0x83,0xbf,0x93,0xa8,0xfc,0x37,0x4a,0x6e,0x07,0x03, 0x0b,0x99,0x0f,0xf1,0x7e,0x34,0xdc,0xbf,0x08,0x23,0x35,0xa9,0x0a,0x78,0x99,0x83, 0x79,0x75,0x61,0xda,0x04,0x60,0xeb,0xe1,0xd7,0x02,0xc1,0xf1,0x90,0x90,0xc1,0x04, 0x01,0x2f,0xf2,0x93,0x5a,0x1c,0xec,0x92,0xa6,0x27,0x20,0xaa,0xd1,0x14,0x09,0xa1, 0xf0,0x01,0xc6,0xaa,0x83,0x99,0x52,0x00,0x47,0x73,0x64,0xba,0x71,0x1a,0xb2,0xf3, 0x08,0xad,0xb0,0x2e,0x81,0x7c,0x11,0xc7,0x31,0x37,0x45,0xe9,0x44,0xdb,0xed,0xb5, 0xf5,0x00,0xa4,0xb3,0xa5,0x2d,0x42,0x7b,0x3d,0x05,0xae,0xa4,0xe9,0xc2,0xb6,0x67, 0x5a,0x5c,0xd1,0x87,0x90,0xc2,0xad,0x88,0xc8,0x86,0x16,0x20,0x3b,0x50,0x14,0x59, 0x90,0xc0,0x8c,0xd6,0xaf,0x8a,0x48,0xb0,0xbd,0x7a,0xb8,0x2a,0xc9,0xf4,0xbf,0x58, 0xaf,0xed,0xbc,0xaf,0x3a,0xdc,0x6d,0x35,0xab,0x18,0x9f,0x71,0x12,0x1b,0x8e,0x49, 0x73,0xfa,0x67,0x37,0xaa,0x21,0x24,0x0d,0xac,0x2b,0xa3,0xf6,0xa6,0x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,0x28,0x60,0xb0,0x00,0x03,0x1d,0x32,0x14,0x18,0xd8,0x3f,0x6e,0x0d,0x5c,0x11, 0xeb,0xf9,0x31,0xe4,0xbb,0x83,0x8c,0xf1,0xbf,0xb0,0xcc,0x3d,0x23,0x41,0x19,0x6f, 0x5f,0x7c,0x02,0x9a,0xed,0xa3,0x8a,0xf9,0x03,0x80,0x19,0x6c,0x6f,0xb4,0x68,0xa8, 0x67,0x82,0xd0,0x17,0x3f,0x3c,0x9f,0x90,0xf4,0x3a,0xee,0x84,0xf2,0xcd,0x1c,0xf5, 0x6c,0xd8,0xeb,0xf4,0xef,0x76,0x30,0x94,0xc7,0xe4,0x1c,0x9a,0x69,0xed,0x97,0xa8, 0x54,0x5b,0x85,0x77,0x66,0x06,0x12,0x82,0x04,0xad,0xb4,0xa0,0x43,0x17,0x21,0x3c, 0x74,0xae,0x6f,0xe2,0x0f,0x87,0xb8,0x95,0x39,0x14,0x14,0xb9,0xce,0x9d,0x16,0x14, 0xc2,0xda,0x55,0x00,0x3c,0x16,0x71,0x2e,0x2f,0x04,0xa7,0x39,0xdc,0x09,0x5a,0x5d, 0xe6,0x49,0x10,0x7c,0x08,0x15,0x1e,0x8d,0xf1,0xc6,0x49,0x04,0x52,0x88,0x62,0xe1, 0x7e,0xaf,0x32,0xdf,0xcb,0xaa,0x71,0x7e,0xd4,0x7f,0xa4,0x89,0x7e,0x55,0xf2,0x6e, 0x2e,0x13,0x5d,0x90,0x3b,0x41,0x39,0x3a,0x37,0x03,0x9b,0x27,0x00,0x46,0x0d,0x47, 0xac,0xd2,0x6e,0x24,0xef,0x82,0x73,0x7f,0x11,0x3e,0x03,0x18,0x8f,0x84,0x1d,0xbc, 0xdf,0x3e,0x05,0x85,0xb2,0x9b,0x43,0xb7,0xa7,0x34,0x2b,0x04,0xed,0xee,0xb3,0x36, 0xa5,0xb0,0x12,0x8e,0x73,0x89,0x78,0x15,0x06,0x45,0x53,0x34,0x0e,0x6a,0x83,0xc0, 0x2e,0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74,0xb8,0xf6,0x99,0xab,0x13,0x94, 0xfe,0x35,0x79,0xca,0x37,0x9c,0x69,0x05,0x35,0x12,0xaa,0x3a,0xbe,0x28,0x3e,0xac, 0xa7,0x36,0x45,0xfa,0xbf,0x7d,0xc5,0xc1,0x45,0x28,0x85,0xa1,0xd2,0xba,0x81,0x02, 0x5e,0xcc,0xfe,0x51,0xac,0xef,0x51,0x9d,0xdf,0x6c,0x28,0x20,0x13,0xc9,0x1a,0xf6, 0x8b,0xfd,0x69,0xde,0x1a,0x3a,0xd9,0x25,0xac,0x69,0xdf,0xaa,0x73,0x7a,0xae,0x94, 0x74,0xdd,0x15,0xf0,0xb4,0x6f,0xfb,0xce,0xe3,0x86,0x59,0x87,0x0a,0x72,0x44,0x7b, 0xc7,0x3d,0x57,0x0c,0x06,0x32,0xc2,0xb1,0x5c,0xa5,0x8f,0x1c,0x6d,0x00,0x29,0x87, 0xfe,0xd3,0xbd,0x32,0xc9,0x96,0xe6,0x7a,0xa3,0xb1,0xc9,0x8e,0x01,0xbd,0xee,0x43, 0x6d,0x06,0xcc,0x33,0x0d,0x60,0x2d,0x40,0x50,0xf6,0x6f,0x73,0xc5,0xb8,0x81,0xd0, 0x8a,0xc5,0xd6,0xd5,0x2a,0x51,0xd9,0x45,0x6c,0xea,0x7a,0xdb,0xf3,0x53,0xd8,0xd6, 0x78,0xcd,0xb8,0xe2,0x2c,0xcd,0x3e,0x1e,0x65,0xec,0xed,0x6b,0xda,0xfb,0x9d,0x59, 0x48,0x09,0x72,0xf8,0xed,0x1b,0x45,0x3c,0x56,0xa0,0x18,0x55,0x1a,0x59,0x70,0x24, 0xa8,0x70,0xba,0xd5,0x9c,0xdd,0x67,0x89,0xe6,0x89,0x5e,0x40,0x84,0xa7,0xb4,0x1e, 0x62,0xb9,0x66,0x0d,0x9d,0x6b,0x65,0xad,0xdc,0x46,0xec,0x21,0x08,0xf8,0x14,0x78, 0xf6,0xc9,0x85,0xc8,0xd2,0xb6,0x44,0x53,0x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0x21,0x6b,0x2d,0x55,0xf2,0x93,0x69,0x84,0x36,0x58,0x01,0xa1,0xd9, 0x33,0x82,0x2d,0xfc,0x5d,0xd3,0x28,0xd5,0xe6,0xd9,0x37,0xcf,0x97,0xbb,0x4c,0x76, 0x6a,0x46,0xff,0x38,0xa7,0xc7,0xe9,0xbb,0xb1,0xcf,0x70,0x0a,0x85,0xa3,0x09,0x9e, 0x1d,0x9b,0x68,0x9a,0x0f,0x1b,0x81,0x4e,0x63,0xc7,0xc5,0x60,0x70,0xe5,0x71,0x9f, 0xc3,0x2b,0x08,0xe9,0xe8,0x7b,0x08,0xd0,0x20,0x9b,0xba,0xc1,0xae,0xf9,0x30,0x69, 0x8e,0x04,0x89,0xe9,0x02,0xdb,0xa7,0xf2,0xea,0xf5,0x53,0x9c,0xd3,0xc6,0x6b,0x24, 0x96,0xb3,0xfd,0x21,0xa0,0xcf,0x8c,0xd1,0xbd,0xab,0x15,0x93,0x8e,0x8f,0x20,0xe5, 0x05,0x43,0xbb,0xa1,0xc6,0x4f,0x52,0x51,0xbc,0xb8,0xb0,0x7e,0x13,0x57,0x1f,0x44, 0x87,0xd3,0xb3,0x9e,0x8f,0x52,0xfa,0xa0,0xd9,0x74,0xa4,0xd1,0x70,0xea,0xef,0xcc, 0x33,0x8b,0x78,0x9e,0x0c,0xca,0x33,0x91,0x91,0x8d,0x79,0xdb,0xff,0x24,0x70,0x78, 0x78,0x61,0xca,0x67,0x44,0x08,0xa4,0x4c,0x65,0x83,0xa7,0x36,0xc7,0x20,0x30,0x8b, 0x97,0x30,0x4f,0x66,0x5a,0xc7,0x4b,0x3e,0x5b,0x03,0x02,0xdc,0x0c,0xaa,0x79,0x8b, 0xc6,0x97,0x63,0x37,0x71,0x77,0x81,0x52,0xa0,0x98,0xf9,0x58,0x13,0xef,0xfc,0xaf, 0xf8,0xd6,0x68,0x8e,0x84,0xa6,0xb9,0x53,0xe3,0xdc,0xd1,0x8f,0x12,0xaa,0xb5,0x15, 0x95,0x0b,0xd8,0x4b,0x74,0x47,0x45,0x48,0x58,0xe5,0x3e,0xb9,0x9e,0xaf,0x40,0xcc, 0x45,0x17,0x76,0x71,0xf3,0xd0,0xdc,0xb3,0xa2,0xb7,0x58,0xb0,0x12,0x17,0xd1,0x96, 0x36,0xc9,0x5d,0xe9,0x37,0x16,0x28,0x73,0x14,0x31,0x10,0x58,0xe1,0xc6,0xfb,0xc4, 0x8c,0x3a,0xeb,0xaf,0x46,0xd0,0xa5,0x06,0x1b,0x39,0x56,0x13,0x24,0x58,0x92,0x93, 0xce,0xf6,0xa7,0xfd,0xbe,0x47,0xdc,0x56,0xd1,0x68,0x2a,0x16,0xd0,0x84,0xca,0x13, 0xac,0x82,0xcf,0xc8,0x8f,0x7c,0x19,0xb4,0x91,0x02,0x6a,0x03,0x0d,0x6e,0xb5,0x7c, 0xde,0x32,0x92,0x8a,0x38,0xff,0x06,0x49,0x0e,0x38,0xe7,0xff,0xd4,0x95,0x9c,0x91, 0x56,0x8c,0xc9,0x35,0xa1,0xf8,0x80,0x32,0xb1,0x30,0x98,0x56,0x3a,0x4c,0xdb,0xea, 0x71,0x96,0x6d,0xa1,0x39,0xfc,0xc0,0x4d,0xb2,0x95,0xd2,0xb5,0xfe,0xa9,0x2c,0xdf, 0xd3,0x57,0x21,0x00,0x83,0x36,0x53,0x12,0xbd,0x23,0xb4,0xb8,0xb1,0xac,0xb6,0xa1, 0xfd,0x4b,0x14,0x80,0x7c,0x18,0x68,0x0a,0x77,0xf4,0xc1,0xde,0x4c,0x52,0x4c,0x5d, 0xc6,0x89,0xb6,0x62,0xbf,0xcf,0x43,0xd7,0x7f,0xf7,0xc0,0xba,0x98,0x14,0x19,0x2c, 0x01,0xab,0xe0,0x3c,0x21,0xa2,0x5f,0x5c,0xc2,0xce,0xe7,0x5c,0xc9,0x49,0x21,0x19, 0xab,0xff,0x31,0x3c,0xd7,0x74,0x72,0xda,0x53,0x7e,0x24,0xba,0xfa,0x53,0x86,0xf3, 0x5e,0xc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,0xce,0x8d,0x0e,0x1e,0xae,0x72,0x98,0x4c,0xaf,0xe3,0x24,0x0e,0x8e,0xee, 0x90,0x4f,0x73,0xec,0x28,0x68,0xd5,0xbe,0x9f,0x20,0xe5,0xae,0x6f,0x58,0x7e,0x18, 0x17,0x88,0xd4,0x2a,0xb8,0x16,0x28,0xcc,0x2c,0x09,0xcb,0xd2,0x98,0xf2,0x56,0x04, 0x46,0xd0,0x07,0xd4,0xb0,0x56,0x22,0x39,0x32,0x60,0x6a,0x53,0x30,0xf6,0x80,0x93, 0x13,0xda,0x6d,0x35,0xb2,0x81,0x6d,0x0d,0x89,0xa8,0xd2,0xcd,0x4a,0xa0,0x45,0x97, 0x28,0x06,0xc5,0x05,0x6e,0xc6,0xc1,0xff,0x73,0x80,0x42,0xde,0x3d,0x93,0x0d,0xad, 0x97,0x5e,0x28,0xa2,0x1a,0xda,0x5b,0x07,0x3c,0xd4,0x1c,0x5a,0x8b,0x8a,0x53,0x94, 0xa6,0xf3,0x05,0xd8,0xa4,0xba,0xf2,0x5f,0x51,0x75,0x01,0x0a,0x2d,0xd9,0x11,0x10, 0xd9,0x1b,0x68,0x69,0x81,0xc2,0xc1,0x37,0x70,0x99,0x10,0x88,0x25,0xb6,0xb6,0xa9, 0x34,0x0d,0x7e,0x0c,0xbe,0x5a,0x4e,0x52,0x60,0x11,0x30,0x43,0x8b,0x33,0x7a,0x25, 0xe5,0xb9,0x1a,0xca,0x7f,0x05,0x6e,0x18,0x2d,0x63,0x4d,0x2a,0xf5,0x67,0x7e,0xa6, 0xf4,0xb2,0x22,0x19,0xeb,0xee,0x33,0x70,0x72,0x30,0xbd,0xa5,0x07,0x4b,0xd5,0xda, 0xcb,0xdc,0xa4,0xa8,0xe3,0x67,0x41,0x4d,0xb5,0x1b,0x7a,0x89,0x2e,0xfe,0x33,0x59, 0xba,0x44,0x1c,0x1a,0xdf,0xcd,0xba,0xf5,0xa4,0x57,0xbf,0x07,0xff,0xab,0xf0,0x62, 0xf1,0x34,0xfc,0x1b,0x53,0xdc,0x69,0xc5,0x89,0xdf,0x74,0x84,0x95,0x72,0x32,0xbc, 0x80,0x29,0x1e,0x6f,0x10,0xc9,0x2a,0x34,0xf7,0x4c,0x78,0xc8,0x09,0xae,0x7b,0x05, 0xea,0x1b,0x59,0xcd,0x5b,0x12,0x5c,0x38,0xe5,0x6b,0x8b,0xce,0x29,0x5c,0x81,0xfe, 0xf9,0x47,0xc6,0xe9,0xfc,0x6e,0xee,0x56,0x6e,0xab,0x2d,0x94,0x08,0x4c,0x55,0x2b, 0x5c,0x66,0xaf,0x6f,0xdb,0x0c,0xda,0x15,0xc9,0xb0,0xcf,0x39,0x0e,0x01,0x75,0xa2, 0xca,0x9a,0xf1,0x88,0x96,0x84,0x04,0xff,0x91,0xcb,0xe4,0xa2,0xfd,0x1d,0x88,0x3b, 0xaa,0x2b,0x5f,0x80,0xc6,0x1f,0xee,0xdd,0x49,0xa7,0x2a,0xc4,0xe0,0x63,0xed,0x52, 0x3c,0xd6,0x17,0xd1,0x03,0xbe,0x8a,0x27,0x70,0x1d,0x13,0xc5,0xa3,0x88,0xc4,0x62, 0x11,0x09,0x97,0xa1,0x9b,0x06,0x95,0x31,0x0f,0x47,0x2c,0x40,0x1a,0x98,0x6f,0xeb, 0x9f,0xd0,0x47,0x92,0x98,0x3a,0x84,0x77,0xe2,0x51,0xc3,0x1c,0xbb,0xfd,0x1c,0x56, 0x07,0xa5,0x91,0xf9,0xfc,0x4e,0xb8,0x53,0x2a,0xbf,0x42,0xc6,0x63,0x61,0x31,0x45, 0xb3,0x2e,0x1f,0x41,0x9a,0x64,0xd6,0xe5,0x36,0x19,0x99,0x35,0xfe,0xb5,0x4c,0x2f, 0x65,0xd3,0x1b,0x64,0x44,0x42,0x47,0x3e,0x9d,0xa3,0x50,0x71,0x93,0x45,0xd2,0xf0, 0x99,0xb4,0x5d,0xc7,0xba,0xef,0x66,0x5e,0x99,0xd7,0x98,0xb3,0x27,0xd6,0xa8,0x6d, 0xa7,0xbc,0xad,0x6d,0x67,0x8c,0xb3,0x13,0x34,0x2f,0x49,0x7c,0x0a,0xad,0x4f,0xcd, 0x23,0x88,0x28,0xe9,0xd6,0x9c,0x08,0x33,0xa3,0x68,0x64,0x9a,0x23,0x36,0x35,0x83, 0x46,0xb8,0x07,0xec,0xaa,0x57,0x54,0xb4,0xd1,0xfc,0x6a,0x18,0xc2,0x48,0xb5,0xfc, 0x6d,0x26,0xc6,0x87,0xc0,0x34,0x7b,0x39,0x10,0xc6,0xbd,0x67,0x8f,0x7c,0xe3,0xdf, 0x9f,0xec,0x33,0x51,0x7f,0xbf,0x27,0x58,0x85,0x51,0x45,0xfb,0x6a,0x2b,0x5a,0x75, 0x81,0xca,0xd9,0xe0,0x46,0xea,0xaa,0xdb,0x29,0x67,0xcb,0x5d,0xd0,0xed,0x83,0x9f, 0x08,0x4e,0x32,0x48,0x98,0x70,0xc0,0xf8,0xf2,0xff,0xc8,0xbd,0x66,0xae,0xc3,0x59, 0x90,0x0d,0x12,0x4f,0x21,0xba,0xe0,0x26,0x13,0x5d,0x65,0x1d,0x05,0x08,0x30,0xb0, 0x03,0xa0,0x74,0x82,0x5f,0x09,0xbf,0x17,0xf4,0x3e,0x73,0xc0,0xad,0x1c,0xf7,0x70, 0x1a,0x08,0x3f,0xdf,0x04,0xdb,0x78,0xdb,0x51,0xdd,0x23,0x0e,0x06,0xe1,0x5a,0x70, 0xb0,0x72,0xb5,0x4d,0xf6,0x5b,0x35,0x27,0x39,0x28,0x45,0xb3,0xc7,0x90,0x7d,0x26, 0x59,0x6f,0xaf,0x7b,0x4f,0x5d,0x65,0x9c,0x52,0xb3,0x5d,0xb6,0x1e,0xe8,0x5f,0xca, 0x7f,0x0d,0x01,0xf6,0x17,0x93,0x0b,0x05,0x63,0x8c,0xa8,0x0d,0xe5,0xa3,0x3b,0x2c, 0x93,0xee,0x3a,0x55,0x78,0xa0,0xf9,0x4e,0x89,0x59,0xc3,0x04,0x86,0xbe,0x28,0xcf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f,0x99,0x49,0xe2,0x0b, 0xfd,0x90,0xa0,0x5a,0x19,0x57,0x1d,0x46,0x90,0x94,0xca,0xff,0x31,0x53,0x72,0x90, 0xeb,0x4e,0x47,0x9b,0x61,0x08,0x3a,0x6a,0xf3,0xcd,0x2a,0xd0,0x0b,0x44,0x1d,0x68, 0x04,0xa3,0x02,0x66,0x20,0x8b,0x46,0xa1,0x8a,0xc1,0x01,0x28,0x0a,0x53,0xde,0x5d, 0x36,0xa3,0x6a,0xcc,0x4e,0xa7,0x97,0x5e,0xb4,0x46,0xa4,0x6c,0x5e,0x52,0x79,0x62, 0x44,0x86,0xc3,0xf3,0x72,0xcb,0x3c,0x67,0x75,0x10,0xb8,0xce,0xb9,0xfc,0x9e,0x86, 0x82,0x1b,0x7e,0xa3,0x9b,0x46,0x46,0x94,0xbc,0xdd,0xde,0x3a,0x8f,0x85,0x82,0x5f, 0x9e,0x54,0x21,0xe7,0x31,0x8e,0x94,0x19,0x27,0x13,0x48,0xf8,0xf2,0xc6,0x85,0xc4, 0x5f,0x43,0xd5,0x45,0x65,0x97,0x50,0xca,0x84,0xc1,0x2f,0x45,0xc8,0x6b,0x86,0x00, 0x87,0xa9,0xf4,0x3d,0xb8,0xe6,0xd7,0xe7,0x16,0x89,0xc9,0x1d,0x75,0x8e,0xee,0x9c, 0xab,0x9a,0x8a,0x1a,0x0c,0xea,0x45,0x7b,0x8f,0xdc,0x01,0x90,0x3c,0xed,0x8f,0xe4, 0xc9,0x09,0xfa,0xee,0x10,0x78,0xe8,0xda,0x4a,0xa0,0x6a,0x72,0x8c,0x27,0xd9,0x38, 0xde,0xbb,0x2b,0xca,0xea,0x08,0xd8,0xa2,0xee,0x3c,0x6b,0xcc,0xe4,0x31,0x23,0xc2, 0x63,0x94,0xd9,0x74,0xa8,0x33,0x9b,0x9f,0x65,0x59,0xa2,0xd0,0x8f,0xcc,0x3c,0x23, 0x9f,0x4d,0x87,0x20,0x47,0xd3,0x1c,0x74,0x28,0x08,0x9a,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,0xf9,0xf8,0x41,0xc8,0x38,0x08,0xfb,0xae,0x8c,0xfa,0x51,0x83,0x1d, 0xcd,0x93,0x99,0xb9,0xd2,0xb5,0xc5,0x41,0xca,0x53,0x67,0x41,0xd7,0xf6,0x4b,0xbc, 0xe2,0xbf,0x2f,0x34,0x4b,0xe2,0x32,0xbc,0x32,0xbd,0x32,0x37,0xd7,0x6f,0x06,0x85, 0x15,0xff,0xce,0x2b,0x4f,0xe4,0x33,0x63,0xd4,0x04,0x0c,0x0a,0x76,0x49,0x82,0xb4, 0xc2,0xa5,0x39,0x8d,0xc3,0x36,0xaf,0xe5,0x2b,0xe9,0x01,0xec,0x85,0x1d,0x42,0x81, 0x0b,0xfb,0xf8,0x7e,0xd1,0xad,0x46,0x31,0x08,0xd1,0x4c,0x5f,0x2c,0x6f,0xb5,0x9f, 0x01,0xec,0xfe,0x96,0x47,0x18,0xac,0x83,0x17,0xcc,0x17,0x96,0xa3,0xac,0x74,0x32, 0xae,0xd7,0x7a,0xbd,0xc2,0xfb,0xb6,0x68,0x64,0x5a,0xd1,0xea,0x70,0x32,0xd0,0xf4, 0x09,0xb0,0x38,0x2f,0x52,0x2d,0xca,0x72,0x88,0x70,0x88,0xa7,0xa6,0x25,0xec,0xa8, 0x0c,0x93,0xef,0xf7,0xf0,0x64,0xa3,0xc1,0xe3,0xed,0x5b,0x81,0x0a,0x0c,0x1e,0x84, 0xb9,0x42,0x0d,0x78,0x5f,0x49,0x96,0xa5,0xd1,0xdc,0x4a,0x7d,0x28,0xda,0x60,0x4d, 0x86,0xfe,0xcf,0x3f,0xac,0x4d,0x76,0x14,0x91,0xc4,0xaa,0xf7,0x3e,0x69,0x6b,0x4c, 0xd4,0xb4,0x98,0x29,0xdb,0x69,0x4f,0x3b,0x1b,0xd5,0xfb,0x0e,0x31,0x5a,0x4b,0x69, 0x14,0xab,0xa4,0xfa,0x0a,0x94,0x5a,0xba,0x27,0x23,0x57,0x22,0x6e,0x77,0x23,0x1c, 0x8c,0x7e,0x40,0x54,0x13,0x6f,0x41,0xe7,0xc4,0x72,0x82,0x9f,0xfb,0xfa,0xaf,0x17, 0x5c,0x09,0x67,0x60,0x42,0x97,0x8d,0x29,0xa9,0x9c,0xa3,0xad,0x01,0xd3,0xe5,0x8e, 0x11,0x56,0xc8,0xea,0x24,0x8f,0x62,0x54,0x26,0x6d,0x02,0x89,0x80,0x03,0x32,0xc1, 0xaa,0x7b,0xd5,0xcc,0xaf,0x38,0x59,0x69,0x98,0x6e,0xe7,0x20,0x22,0xc1,0xc1,0xe2, 0x36,0x14,0xb2,0x44,0x0a,0xa0,0xfa,0x5b,0x06,0x1c,0x04,0x67,0x3c,0x4c,0x95,0x33, 0x32,0xbb,0x6a,0x06,0x50,0x88,0x32,0xe1,0x1e,0xe7,0xaa,0xb4,0x52,0x4c,0x0e,0x13, 0xc4,0x60,0xab,0x66,0xbe,0xac,0xb2,0x5c,0xae,0x94,0x8d,0xa4,0x54,0x7e,0xc9,0x72, 0x85,0x4d,0xa0,0xb6,0x44,0x52,0x26,0xd9,0x93,0xb2,0x39,0x06,0xb2,0x2a,0x67,0x91, 0x3e,0x11,0x5e,0xfc,0x2c,0x15,0x79,0x1b,0xe5,0xbf,0x03,0xc1,0x68,0xb8,0xbb,0xa1, 0xc3,0x5e,0x4c,0x0b,0x2e,0xf1,0x2f,0xd4,0xbc,0x16,0x3a,0xf8,0x9a,0xff,0x5a,0x79, 0xe8,0x29,0x19,0x3a,0x78,0x25,0x17,0x28,0xcd,0x94,0xd7,0xda,0x9e,0x35,0xae,0xd3, 0x7c,0x21,0xd2,0xd7,0x30,0x0a,0x76,0x66,0xb6,0x58,0xcf,0x83,0xe5,0x7c,0xb5,0xde, 0x0a,0xd5,0xe8,0xc6,0x91,0x30,0xb5,0x8b,0x9c,0x36,0x72,0xf1,0x3e,0x35,0x27,0x33, 0xc2,0x09,0x7e,0x44,0xd8,0x79,0x07,0x61,0x5f,0xcf,0x45,0xd2,0x29,0x08,0x55,0xb5, 0x22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0x8f,0x24,0x32,0x8e,0x2d,0x4b,0x61,0x11,0x82,0x3c,0x5a,0x25,0xfe,0xfb,0xac,0xcc, 0x53,0xcd,0xfd,0x0b,0x4f,0x59,0x9b,0x42,0x5f,0x10,0x3d,0xf2,0xad,0x30,0x4b,0xf1, 0x9b,0x2f,0x3e,0xb5,0x85,0xaf,0x0d,0xec,0x9a,0xaf,0xa6,0xae,0x6b,0x89,0x48,0xae, 0xdf,0xf7,0x1b,0x69,0x9c,0x59,0x76,0x19,0x5e,0x90,0x20,0x26,0xab,0x70,0xd6,0x7d, 0x54,0x4d,0x84,0x28,0x5d,0x37,0xcd,0xa1,0xe6,0x48,0x85,0xfa,0x22,0x92,0x97,0x4b, 0x84,0x07,0xce,0xa2,0x27,0x33,0x8b,0x4c,0x31,0x6c,0x5f,0xc2,0x0b,0xe8,0xc7,0x93, 0x1a,0x4e,0x9f,0x60,0xe2,0x54,0x24,0x7a,0xf9,0x6a,0x75,0x4f,0xf7,0x2c,0xff,0xd9, 0xbc,0x5e,0x47,0x52,0xd1,0x05,0xd7,0x89,0xcf,0x36,0x0e,0x58,0x56,0x74,0x3c,0xb3, 0xea,0x83,0x15,0xcc,0x06,0x81,0x56,0x0e,0xae,0xb4,0xcc,0x4f,0x0a,0xd6,0x31,0x75, 0xc5,0xb4,0xa1,0xf9,0x9f,0x6a,0x76,0x30,0x89,0x83,0xe2,0x06,0x64,0x6a,0x83,0xcf, 0xae,0xd6,0x2f,0x53,0x79,0xe2,0x7c,0x86,0x4a,0xe8,0x7a,0x70,0xfa,0xca,0xe6,0x5e, 0x39,0x57,0xff,0x64,0x84,0x47,0x7c,0x56,0x0f,0xdd,0x46,0x69,0x65,0xa5,0x73,0x0e, 0x1b,0x88,0xfd,0x7e,0xe9,0x15,0x67,0x9b,0x4f,0x02,0xfa,0x0e,0xfd,0x6f,0xf9,0xf3, 0x2a,0xe3,0x43,0x50,0x8f,0x52,0x34,0x45,0xb4,0x67,0x95,0x90,0xaa,0xc2,0x75,0xf7, 0xec,0x16,0x8f,0xaa,0x6f,0xea,0x4f,0x24,0x42,0x43,0x9b,0x60,0x25,0x98,0xde,0x04, 0xf6,0x7d,0x35,0xd7,0x8b,0x4a,0x97,0xa5,0xd4,0x5b,0xff,0xa0,0x9c,0x7f,0x05,0xb8, 0xd7,0xda,0x6c,0x95,0x67,0x68,0x98,0x37,0xa9,0x4e,0x74,0x79,0x6e,0xbc,0x4b,0x16, 0xe9,0xcc,0x00,0x45,0x02,0x25,0x53,0xed,0xd1,0x2a,0xbb,0x13,0xc5,0x3a,0x28,0xef, 0x00,0xf2,0x33,0x07,0x21,0x00,0x05,0x39,0xbc,0xa5,0xc2,0x99,0x0d,0x62,0x2a,0xdd, 0x07,0xec,0xc1,0x7b,0x87,0xbb,0x62,0x61,0xb9,0x6d,0x6f,0xca,0x50,0x07,0x31,0x9d, 0x52,0x2e,0xcb,0xec,0xe9,0x24,0xe6,0x4a,0xf3,0xb5,0x6b,0xdd,0x70,0x4d,0x8b,0xeb, 0x9b,0x5f,0xc9,0x33,0x71,0x86,0x22,0x70,0x07,0xef,0x72,0xfc,0x05,0xe0,0x1c,0xab, 0xa8,0x7a,0xf3,0x96,0xf1,0x5a,0x34,0x64,0xca,0xea,0xd5,0x0b,0x68,0xc0,0xa5,0xda, 0x7d,0x34,0x03,0x88,0xd6,0x93,0xee,0xe4,0x1c,0x48,0x90,0xaf,0x93,0xcf,0x25,0xb5, 0xc9,0x6f,0x6c,0x2b,0x56,0x00,0x4e,0x75,0x38,0xff,0x57,0x7e,0xfd,0x4b,0x7f,0xe3, 0xb5,0x41,0x13,0x6a,0x7a,0x67,0x6c,0x3c,0x4c,0xed,0xed,0xc4,0xb6,0xe5,0xbf,0x2a, 0x1b,0x67,0x4e,0xe8,0xf9,0xc3,0x52,0x91,0x34,0x6f,0xa7,0xe9,0x5c,0xbe,0x9e,0xaa, 0x70,0xea,0xd9,0x90,0x60,0x05,0x50,0xab,0xc3,0x2a,0xce,0x22,0x24,0x42,0x97,0x83, 0xe4,0xb9,0xd4,0xa0,0x1a,0xa2,0xfa,0x84,0xc4,0x31,0x58,0xce,0xdc,0xb3,0x24,0x8c, 0xa0,0xdd,0xe0,0x23,0xf6,0x8f,0xda,0x52,0xb0,0x6b,0x3a,0x07,0x04,0xda,0x23,0xeb, 0xc6,0x11,0x57,0xfc,0x23,0x66,0xac,0x55,0x6f,0xf9,0x85,0x34,0xca,0xfb,0xd2,0x0e, 0xf9,0xc6,0xc9,0x74,0x4b,0x12,0x06,0xf7,0xc5,0xc0,0xc5,0x14,0x4e,0xf0,0x1a,0x2a, 0x3d,0xbe,0xc6,0x16,0xeb,0x0d,0x16,0x74,0xd2,0x65,0x07,0xe4,0xe8,0x1b,0x86,0x82, 0xd5,0x4d,0xc2,0xeb,0x13,0x5b,0x79,0xef,0x6f,0x5c,0xd2,0x29,0x29,0x01,0x2c,0x11, 0xfa,0x87,0x19,0x81,0x6c,0x5b,0x5d,0x51,0xe0,0xe2,0x01,0xfb,0x53,0x8e,0x81,0x1e, 0x81,0xf8,0x2d,0x7d,0xc2,0x64,0xff,0x7f,0x8d,0x08,0x64,0x86,0xb1,0x2a,0x43,0x5b, 0xfd,0x3e,0x89,0xa1,0xef,0x0a,0x26,0x25,0x7e,0x8e,0x75,0x43,0x0b,0x1f,0x23,0x6c, 0x72,0x24,0x7f,0x16,0x0b,0xa6,0x6e,0xb4,0x53,0x76,0xa0,0x11,0x0a,0x87,0x2a,0x8f, 0x76,0xb6,0x48,0xad,0x1d,0x7e,0x45,0x58,0xb8,0x5f,0x56,0x82,0x55,0xac,0x3a,0x61, 0x5d,0x65,0x67,0x70,0x6c,0x00,0xae,0x56,0xd0,0x07,0xef,0x09,0x67,0xc3,0x2a,0xdf, 0xc3,0xd5,0x57,0x1a,0x82,0x3d,0xe4,0x1a,0xad,0xd6,0x9e,0xf7,0x8f,0x28,0x13,0xf9, 0x06,0x1e,0x00,0xb8,0x16,0xed,0x79,0xb0,0x43,0x69,0x5a,0x20,0x55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e,0x77,0xd2,0x7c,0xa7,0x12,0x82, 0x91,0x1f,0x58,0x54,0x79,0x4b,0x95,0x85,0xfe,0x8b,0x44,0xfd,0xab,0xb7,0xc6,0xd0, 0xb5,0xf7,0xbd,0x81,0xe4,0x1c,0xf4,0x47,0xde,0x5f,0x60,0xc4,0x04,0x7f,0xfd,0xa0, 0xba,0xc1,0xaa,0x2a,0x2d,0x4a,0x3d,0x56,0x0b,0xed,0x02,0x24,0xb5,0xf1,0x74,0x2d, 0x8a,0xd3,0x55,0x38,0x09,0xf0,0xf1,0xf7,0x2f,0xea,0x24,0xa6,0xb6,0x84,0x93,0x49, 0xfd,0xf7,0x58,0x48,0xc3,0x05,0x41,0x89,0x3e,0x20,0x5b,0x03,0x5f,0xbb,0x54,0xa3, 0x35,0x61,0xd2,0x28,0x23,0x33,0x3a,0x5b,0x3d,0x5f,0xfa,0xcf,0x43,0x0b,0xed,0x83, 0x83,0xbe,0x29,0x81,0x21,0x17,0x0b,0x4e,0xd5,0xb8,0xe7,0xf6,0x46,0xb9,0xdd,0xbe, 0xb4,0xde,0x84,0x4c,0x3e,0x70,0xbf,0x89,0xd8,0x8f,0x12,0x28,0x8e,0xf7,0xf4,0x88, 0x03,0xc5,0x7d,0x01,0x54,0x4f,0xa1,0x2d,0x62,0x05,0xef,0xcb,0xab,0x23,0xa1,0x61, 0x74,0xd4,0x75,0x52,0x3a,0x46,0x98,0x34,0x01,0x4b,0xa6,0x31,0x84,0x70,0xc9,0xac, 0x05,0x1b,0x5f,0xee,0x6c,0xaa,0x46,0x0c,0xf3,0xb2,0x76,0x16,0xb3,0xec,0x30,0xcd, 0x69,0x04,0xbc,0x2b,0x7a,0xf7,0xde,0x34,0xc2,0x2a,0x98,0x25,0x11,0x91,0xf8,0x20, 0x33,0x56,0x0b,0x53,0x39,0xd1,0xd3,0x95,0x58,0xf2,0xb6,0x31,0x76,0x6d,0x82,0xba, 0x74,0x31,0xa8,0x62,0xe5,0xae,0xe6,0x16,0x91,0xe2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x22,0x42,0x3d,0xa0,0x86,0x68,0xec,0x81,0x23, 0x28,0xa6,0xfd,0x57,0x81,0x2b,0x86,0x43,0x22,0xa3,0x54,0x14,0xb4,0x35,0xb9,0x0e, 0xba,0x49,0xd7,0x30,0xef,0x34,0xd1,0xdb,0x03,0xf3,0x7b,0xba,0xbe,0x4d,0x9e,0xff, 0xc1,0x42,0x64,0x7c,0x9f,0x70,0xdc,0x74,0x36,0x64,0xb4,0x22,0x17,0x6c,0x74,0x47, 0x42,0x95,0xd0,0xd9,0x51,0x90,0x3e,0xe5,0x46,0x8e,0x34,0x28,0x4c,0x8d,0x68,0x22, 0x31,0xbe,0x5a,0x13,0xd3,0x5d,0x8f,0x6e,0x6b,0x3b,0x6a,0xf4,0xef,0x7d,0x1b,0x30, 0xcd,0x8c,0x38,0x09,0x78,0xd6,0xf1,0xcf,0xf7,0x25,0x17,0xa8,0x9c,0x21,0x73,0x2e, 0xaf,0x33,0x5a,0x50,0xf1,0x92,0x94,0xba,0xd3,0x72,0xec,0x87,0x29,0x54,0x1b,0x4e, 0xef,0x39,0x10,0xdb,0x66,0x87,0xec,0x7f,0x11,0x79,0x8e,0x35,0x4e,0x62,0x4a,0xe4, 0x53,0xfe,0x4f,0xeb,0xdf,0x68,0x71,0x54,0x57,0x7e,0x67,0xcd,0x1e,0xa1,0x36,0x4f, 0x8c,0xd8,0x9b,0x73,0xb1,0xa8,0x4f,0xc3,0x10,0xf0,0x35,0xd8,0xec,0x80,0xcf,0xc3, 0x51,0xd4,0xe8,0xa5,0x9b,0xbd,0x9a,0xdb,0x99,0x49,0xf8,0x4d,0xed,0xb0,0xe8,0x09, 0xde,0x35,0x14,0x73,0x08,0xd7,0xa9,0xc1,0x14,0x8f,0xc2,0x44,0xe8,0x74,0x81,0x2f, 0x99,0x02,0x57,0x12,0x99,0x71,0xe1,0x30,0x25,0x00,0x35,0x7e,0x18,0xcb,0xe3,0xcc, 0x91,0x38,0x6b,0xc7,0xd7,0x93,0xd4,0xd3,0x5d,0xcb,0xf1,0x10,0x89,0xbc,0x9d,0x51, 0x60,0x8f,0x87,0x01,0x95,0xb0,0xf7,0x43,0xa0,0xb9,0x8f,0xb8,0xa8,0xde,0xaf,0x01, 0xda,0x96,0x1e,0xb3,0x51,0x47,0x53,0x8d,0x96,0x23,0x39,0xad,0x5e,0xd7,0xc5,0x81, 0xbe,0x76,0xcc,0x6f,0x53,0x4b,0xc3,0xc4,0x4f,0xa4,0x3f,0xdb,0x3e,0xa3,0x31,0xc6, 0x18,0x71,0x30,0x15,0x98,0x43,0x1a,0xcb,0x62,0x6c,0x89,0xc4,0x1e,0xd5,0x30,0xf5, 0xb8,0x3c,0xfa,0xce,0x86,0xcf,0x80,0x78,0x81,0xa5,0x8d,0xd0,0x98,0x43,0x50,0x7f, 0x6e,0xb1,0x64,0x1c,0x61,0x10,0x5a,0xa0,0xd9,0x3c,0x40,0x8e,0xf6,0x3f,0x0c,0xd7, 0xac,0x5e,0x34,0xcd,0x3d,0x9b,0xab,0xf4,0xd4,0x17,0x90,0x5c,0x43,0x10,0x57,0xa0, 0x4f,0xaa,0xed,0x78,0xfa,0x35,0xdf,0xcb,0x8f,0x0e,0x08,0x46,0x79,0x83,0x5d,0x56, 0xe0,0xe4,0x0d,0x4a,0x3c,0x96,0x72,0x2a,0x37,0x8d,0xe6,0xcc,0x9f,0x61,0x50,0x34, 0x26,0x98,0xe8,0xa2,0x30,0xd8,0xd9,0x68,0x94,0xe1,0xa8,0x56,0x68,0x09,0x23,0xcb, 0x37,0x29,0x04,0x98,0x3a,0x19,0x21,0x66,0xfa,0xdb,0xc4,0x67,0xeb,0xe2,0x19,0x0f, 0xf3,0x4f,0xbb,0x6a,0x83,0x10,0x4b,0x84,0x88,0x63,0x93,0x26,0xc1,0x8e,0x3b,0x78, 0x84,0xd2,0x1b,0xed,0x68,0x86,0x53,0xbc,0x15,0x58,0x1c,0x04,0xe3,0x24,0xb9,0x88, 0x2b,0x95,0x85,0x88,0xed,0x68,0x2e,0x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,0x85,0x78,0x9f,0x87,0x79,0x24,0x32,0x40, 0xce,0xcc,0xe9,0x1d,0xa2,0x35,0x0a,0x3d,0x40,0xce,0x76,0xba,0xd3,0xb6,0xa2,0x13, 0x28,0x62,0x42,0x8a,0x81,0x76,0xe3,0x7f,0x97,0x6b,0xdf,0x53,0xcc,0x56,0xa7,0x89, 0x0d,0x4a,0x85,0x7e,0x44,0x8b,0x23,0xf6,0x51,0xd1,0xb1,0x40,0x36,0x3b,0x3f,0x54, 0x43,0x56,0xe6,0x34,0x56,0xc6,0xd5,0xba,0xa3,0x55,0x3b,0x02,0x7b,0xc1,0x51,0x29, 0x56,0xf7,0xfd,0xdc,0xcc,0x12,0x3b,0x69,0xc1,0x34,0x5a,0x70,0xc0,0xcb,0x86,0x46, 0x39,0xa5,0x5f,0x22,0x01,0xe3,0xe8,0xdb,0x13,0x3f,0xaa,0x83,0xbd,0xe9,0x0c,0xda, 0xb9,0x19,0xaa,0x6c,0x10,0xde,0x10,0x83,0x50,0x67,0xea,0x2d,0xa9,0x7f,0xba,0x07, 0x9c,0x72,0x73,0xef,0x99,0x59,0x0d,0xb3,0xd7,0xef,0xfc,0x2c,0xe8,0x36,0xa5,0x5b, 0x72,0x9b,0x63,0x11,0x26,0xcc,0x14,0x8f,0xa0,0x91,0x6e,0x33,0xdb,0x8a,0x92,0xf3, 0xdd,0xa8,0x22,0x9e,0xc8,0x12,0x44,0xf2,0x8e,0xdd,0x3b,0x7f,0xfd,0xfd,0xf8,0xf5, 0x47,0x6b,0x8e,0x6a,0x99,0x14,0x59,0x34,0xe1,0xec,0xe0,0x21,0x1a,0x02,0x2f,0xe3, 0xa8,0x59,0xa9,0x32,0x50,0x16,0xf9,0x26,0xc9,0x31,0x70,0x4b,0xaa,0x91,0x8f,0xe7, 0xc5,0xe0,0xa3,0xf4,0x01,0xa1,0xd5,0xfa,0xb9,0x3c,0xad,0xaf,0xd7,0x27,0x24,0x80, 0x4b,0x7e,0x27,0x2c,0x78,0x57,0xa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0xf9,0x0d,0x12,0xe7, 0x27,0xdb,0x9e,0x5d,0xbe,0x07,0x08,0x96,0xa0,0x32,0xd0,0xba,0x93,0x96,0x29,0x3d, 0x8b,0x61,0x2d,0x54,0xc7,0x70,0x73,0x2b,0x13,0xd8,0xd9,0x4e,0xc0,0x05,0x56,0xe5, 0x0c,0x88,0x08,0x42,0x86,0x48,0x26,0x08,0x5e,0x59,0xb8,0xa1,0x34,0xc1,0x62,0xf9, 0x71,0xcc,0x2d,0xb7,0xc2,0x54,0x33,0x7b,0xba,0x67,0xc6,0xe2,0x2e,0x3a,0x69,0x84, 0xbb,0x34,0x87,0xf2,0xe4,0xaf,0x48,0xee,0x10,0xf5,0x9f,0x72,0x3a,0x8d,0xc3,0x15, 0xab,0x85,0x2b,0x2b,0x09,0xe1,0xa4,0x1f,0x28,0xec,0xab,0xe1,0x19,0x55,0x67,0xda, 0x98,0x62,0x27,0x89,0x18,0xd0,0x04,0x5e,0xff,0x12,0xed,0x7e,0x96,0xc0,0xd8,0x03, 0xc9,0x4c,0x20,0x8f,0xa1,0x67,0x85,0x8e,0x8d,0xf0,0xbf,0x58,0xc0,0x2a,0xef,0x96, 0x94,0xf2,0xfd,0x3d,0x53,0x78,0x23,0x77,0x53,0x33,0x48,0x09,0x67,0xdb,0x4b,0x7d, 0x2c,0xe1,0x29,0xaa,0x42,0xf4,0xaa,0xf2,0x8f,0xa2,0x38,0x95,0xcb,0xbb,0x6e,0x5b, 0x6d,0x76,0x37,0xbd,0x22,0x52,0xf3,0x11,0x51,0x17,0xd4,0xfa,0x2b,0xbd,0x47,0xbf, 0x20,0xc2,0xa6,0xd8,0xa3,0x38,0x4d,0x3b,0xb3,0x8e,0x96,0x4f,0x8b,0x58,0xe3,0x5a, 0x1e,0xa8,0x7d,0xb2,0xae,0x8a,0x55,0xa7,0x4d,0xa2,0x2c,0x3f,0x0e,0x11,0xfc,0x38, 0x6e,0x9f,0x66,0xe2,0xd7,0x60,0x30,0x56,0x91,0xba,0xe0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b,0x81,0x27,0x31,0xbe,0x87, 0x06,0x12,0xa0,0x5c,0xb2,0x91,0x90,0xcd,0x19,0x87,0xae,0x92,0x50,0x43,0xf2,0x9d, 0x9d,0x5d,0x1e,0x64,0x2a,0xcf,0x02,0x29,0x81,0xf0,0x11,0x1b,0x8f,0x21,0x39,0xbb, 0x1f,0xe2,0xfe,0x6e,0xbb,0x0b,0x05,0xa3,0x2b,0xb3,0xc2,0x79,0xad,0x82,0x06,0x93, 0x16,0x7c,0x9e,0x88,0x62,0x88,0x13,0x92,0x5b,0xd4,0x18,0x83,0x79,0xe6,0xec,0xae, 0x60,0x07,0x3e,0x70,0x2c,0x2e,0xe1,0x8e,0x9f,0x9c,0x0e,0x25,0xc4,0x5e,0x1a,0xf6, 0x23,0xfa,0x3f,0x50,0xd9,0x0e,0x84,0xac,0x93,0x74,0x80,0xdc,0x81,0x0c,0xbd,0xfc, 0x3c,0xd9,0xe5,0xe8,0x3c,0xc2,0xfe,0xcf,0xf3,0x17,0x95,0x31,0xcb,0x31,0x09,0xb1, 0xb3,0x49,0x56,0x39,0x4c,0x38,0x0a,0x1b,0x51,0xaa,0x4c,0x64,0xef,0xc2,0xeb,0x54, 0x79,0x73,0x3c,0x87,0x5c,0x60,0xb9,0x98,0x04,0x82,0x35,0x55,0x8b,0x2c,0x09,0x4b, 0xb0,0x94,0xab,0x29,0xd7,0xcd,0x47,0x41,0xfb,0xe6,0xce,0x78,0x64,0x8f,0x75,0xdd, 0x1f,0x26,0xdf,0x26,0x06,0x64,0x56,0xe6,0xc1,0xcf,0xf1,0xc1,0x2d,0x6b,0xcf,0x65, 0x91,0x55,0x77,0x19,0x68,0x3d,0x28,0x41,0xd3,0x70,0xe0,0x9d,0x14,0x6d,0xd7,0xb0, 0xf2,0x5c,0xb1,0xd5,0x0d,0x41,0xff,0x9d,0xfd,0x9c,0x76,0x73,0x8c,0x48,0xfa,0xc1, 0x7d,0x72,0x1e,0x19,0x44,0x15,0xa8,0x5e,0xbc,0x3b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xb1,0xc5,0xfa,0x6a,0x88,0x44,0xff,0x19,0xff,0xfe,0x5a,0x24, 0x4d,0xb5,0x20,0x08,0x47,0x95,0x74,0xaf,0x73,0x85,0x8a,0x33,0x5e,0xa9,0x27,0x55, 0xc2,0x30,0x26,0x26,0x3d,0xa0,0x19,0x47,0x5b,0xf9,0xbb,0x0c,0xe6,0x90,0xe4,0x12, 0xb7,0x42,0x79,0x3b,0x42,0xfa,0xc7,0x52,0xc8,0x46,0xb8,0x8e,0x4b,0x3f,0x4e,0x95, 0x93,0x52,0x92,0x21,0xb7,0x7a,0x1e,0xbe,0x7f,0x08,0x00,0x82,0x8a,0x43,0x7d,0x27, 0xae,0x19,0x2a,0xdb,0xb9,0x05,0x80,0x73,0x15,0x37,0xfc,0x5c,0x4c,0x60,0x20,0x23, 0xc8,0x2c,0x7c,0xf0,0x83,0xc7,0xba,0x76,0x71,0xa0,0xf2,0x79,0xc6,0x2d,0x28,0x24, 0x31,0x7e,0x8f,0xb9,0x08,0x0c,0x7a,0x2d,0x04,0x16,0x84,0x0c,0x44,0xf2,0x63,0xa6, 0x0f,0x55,0x70,0x7b,0xe8,0xa8,0x05,0x9e,0x9d,0x8f,0xbd,0x90,0xa8,0x16,0x2f,0xc0, 0x14,0x3f,0xc4,0x72,0x18,0xfd,0x51,0x58,0x7c,0x56,0x4d,0x48,0xcf,0x28,0x6c,0x77, 0xbb,0xb0,0x1b,0x53,0x0b,0xcf,0x52,0x49,0xc5,0x90,0x9d,0x55,0xe4,0x53,0x7d,0xe5, 0xce,0x78,0x4e,0xf1,0xa8,0x70,0x2e,0x39,0xd9,0xf5,0xa5,0x08,0x70,0x8b,0x33,0x24, 0x75,0x7c,0xdb,0x5e,0x03,0xee,0x60,0xe2,0x44,0xc5,0x63,0x3f,0x6a,0xae,0x64,0x5a, 0x91,0x14,0xd4,0x7f,0xa3,0xce,0x01,0x7c,0xef,0xa1,0x11,0xe3,0x81,0x43,0x71,0x44, 0x5d,0xa1,0x91,0xbe,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x05,0x0b,0x25,0x1c,0xfa,0x02,0x60,0xff,0x6e,0x55,0x86,0xc9,0x91,0x88,0x65,0x5d, 0x92,0x50,0x91,0x7a,0x53,0x05,0x84,0x32,0x21,0x42,0x6d,0xe6,0x99,0xde,0x70,0xf8, 0x34,0xcf,0xbd,0x22,0xb9,0x4b,0xa3,0xf4,0xa5,0x33,0x7b,0xd8,0x7f,0xb8,0xf3,0x1f, 0xf6,0x41,0xa3,0x8a,0x2d,0xc7,0xb9,0xb7,0xdc,0xbe,0x69,0x8d,0x3e,0x53,0x0f,0x9b, 0x4d,0x19,0x79,0x97,0x5d,0xa2,0xfd,0x98,0x86,0x55,0x29,0xe5,0x58,0x9d,0xf9,0x3b, 0x52,0x46,0xfb,0x7c,0x1d,0xaa,0x2b,0x41,0x60,0xfa,0x7b,0xd3,0xa2,0xac,0x76,0xed, 0x22,0xa5,0xf9,0xac,0x46,0x55,0xd0,0x72,0x25,0xd6,0xb1,0x75,0xd4,0xa6,0x00,0x8d, 0xdc,0x2e,0xad,0x6a,0xb5,0xf3,0xa5,0x5a,0xd6,0xfc,0x71,0x83,0x7b,0xf5,0x62,0x05, 0x1e,0xf1,0x17,0xb1,0xd4,0xfd,0xa2,0x0b,0x01,0x69,0x89,0xcb,0xbe,0x54,0xe1,0x11, 0x18,0x43,0xf7,0x09,0xea,0x99,0x93,0xce,0xfa,0xc9,0x46,0x42,0x97,0x6e,0x08,0x52, 0xc6,0x41,0xd4,0x66,0x0e,0x52,0xc5,0x00,0x8c,0x2e,0x01,0x6f,0x57,0xb1,0x13,0xc9, 0x45,0x9a,0xb5,0xde,0xed,0x25,0x1d,0x4f,0x9d,0xd7,0x64,0xfc,0x93,0x88,0x23,0x65, 0xba,0xa1,0xdb,0x68,0xae,0x2b,0x45,0x05,0x98,0x02,0xaf,0x70,0xb2,0x66,0xe2,0x03, 0x06,0x67,0xb7,0x00,0xce,0x79,0xaa,0xa1,0xa3,0x00,0x50,0x01,0x05,0x70,0x67,0x28, 0x4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x13,0x15, 0x2c,0x52,0xe7,0xc3,0xc3,0xec,0xc9,0x96,0x29,0xae,0x62,0xf6,0x67,0x28,0x2d,0x73, 0x81,0x74,0xac,0x72,0x11,0xe8,0x62,0x31,0x09,0x61,0x45,0x18,0x44,0xb7,0xf0,0xf0, 0xfc,0xdf,0x16,0x45,0x54,0x76,0x86,0x4d,0xe3,0x8c,0x0f,0x0b,0x84,0x11,0x3f,0xba, 0x3c,0xc6,0x9d,0xd2,0xb1,0x30,0x9b,0xa4,0x81,0xdc,0xe1,0x94,0x00,0x33,0x77,0xbf, 0x79,0xe1,0xc2,0x12,0xb7,0x69,0xdc,0x55,0x19,0x7d,0xe8,0x79,0x74,0xc8,0x75,0x0b, 0x32,0xe7,0x81,0x2b,0x9a,0xd3,0xbf,0x3f,0x8d,0x35,0x27,0xab,0x91,0x6b,0x3b,0xda, 0x41,0x73,0xac,0xe7,0x7f,0x95,0x7c,0x8a,0x64,0x40,0xa8,0x0c,0xc2,0x14,0x74,0x64, 0x14,0x9f,0xc5,0x14,0xce,0xff,0x9c,0x14,0x6d,0xe0,0x04,0x66,0x08,0xde,0x20,0xe5, 0x77,0x20,0x97,0xec,0xa1,0x91,0x94,0x27,0x04,0x86,0x3c,0x63,0xbe,0xff,0x47,0x0d, 0x3c,0x4a,0x62,0x35,0x68,0x9e,0xa4,0x84,0x34,0xc2,0xb4,0xb4,0x0b,0x30,0xf2,0xc5, 0xd5,0xf7,0x56,0xfb,0xa7,0xdf,0x3f,0x43,0x49,0x5b,0x33,0x66,0xb8,0x6a,0xbb,0x82, 0xeb,0xe2,0xbe,0x50,0xde,0xc8,0x45,0x6b,0x2f,0xc6,0xe9,0x6a,0x3c,0x5f,0xd7,0x75, 0xae,0xd6,0xc7,0xe0,0x95,0x1d,0xf3,0xd2,0x8a,0x1f,0x2d,0x6c,0xb1,0x20,0xb1,0x5e, 0x4d,0x87,0xf9,0xa3,0x70,0x17,0x16,0x75,0xa8,0x34,0x4c,0x90,0xf1,0x6f,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,0x97,0xb4,0x52,0x73,0x3d,0x54,0xbc,0x26,0x11, 0x49,0x41,0x08,0x0b,0x5b,0xb5,0xeb,0xd3,0x47,0x96,0x62,0x2a,0x98,0xcd,0x92,0x9f, 0xe8,0xba,0xf5,0x06,0x95,0xba,0x9c,0xab,0x07,0x4f,0x10,0xc7,0xdc,0xe4,0x09,0x04, 0x94,0x40,0x9c,0x38,0xbd,0x7a,0x12,0x76,0x50,0x32,0x29,0x0d,0x3d,0x20,0xa6,0x6d, 0xcc,0xeb,0x3d,0x54,0x89,0xc7,0x11,0x5d,0x46,0x71,0x3e,0xd8,0x11,0xbe,0xe0,0x29, 0x0f,0x3c,0x4b,0x2d,0x8f,0xbb,0x0b,0x6d,0xe4,0xf0,0xbb,0x7b,0xdd,0x03,0x82,0x2e, 0x77,0x5d,0xa7,0xb5,0x5e,0xf9,0xb1,0xd5,0x95,0x20,0x75,0x0e,0x7a,0x55,0x3c,0xce, 0x3d,0x6d,0xd6,0xa2,0x34,0xc0,0x4f,0xf5,0xa4,0x25,0x44,0x35,0xef,0x4c,0x50,0xd4, 0xb1,0x85,0x95,0xcb,0x9d,0x61,0x0b,0xee,0x47,0x45,0xae,0x84,0x6c,0x64,0x13,0x08, 0x5a,0x04,0xa1,0xde,0x4f,0xbf,0x64,0xd8,0x2d,0x93,0x51,0xe5,0x4c,0x38,0x18,0xcd, 0x70,0x62,0x0c,0x9d,0x63,0xcc,0x9c,0x5d,0x7e,0x09,0x5c,0x65,0xe4,0x3a,0x5b,0x5d, 0xd8,0x52,0x5f,0xd4,0xa3,0x12,0x59,0x17,0x85,0x4e,0x01,0x8a,0x11,0x1d,0xde,0x14, 0x9a,0x96,0x8b,0xd9,0x7f,0x21,0x99,0xb7,0x40,0xca,0x39,0x42,0xd1,0x19,0x12,0x21, 0x77,0xc4,0x09,0x61,0x5f,0x1e,0xf6,0x15,0x06,0xb7,0x48,0x47,0x1f,0xe0,0xe7,0xb5, 0x85,0x85,0x24,0x2f,0xcd,0x07,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0xee,0xe5,0x0a,0x24,0x17,0xd8,0xbe,0xe3,0xd0,0xac,0xc6,0x79,0x60, 0x4f,0x05,0xd3,0xef,0x2e,0x34,0x9e,0x34,0x13,0x52,0xe5,0x57,0xe7,0x0c,0x79,0xc1, 0xb7,0xd9,0xe8,0xb3,0x75,0x5f,0xb0,0x4a,0x3d,0x49,0xd4,0x5a,0xd9,0x93,0x74,0x58, 0xd8,0x6e,0xc6,0x6f,0x54,0xc8,0xcd,0x4a,0x02,0x69,0xaf,0x71,0x47,0x78,0x2f,0x4d, 0x64,0x0a,0x96,0x61,0x5e,0x21,0xb2,0x9d,0x77,0xe9,0x55,0x03,0x35,0x3a,0x7b,0xd8, 0x06,0x9b,0x36,0x5e,0xea,0xc7,0x88,0x28,0xdd,0x4e,0xed,0x57,0xd8,0x2a,0xf2,0x30, 0xe6,0x27,0xf1,0xe8,0x84,0x3d,0xdf,0x59,0xac,0x20,0x08,0x92,0x70,0xf4,0xa4,0x0a, 0xb3,0x75,0x46,0x1a,0x88,0x12,0xd8,0xf8,0x2a,0xba,0xfd,0x71,0x40,0xfe,0x1d,0xf4, 0x76,0x06,0x6b,0x07,0x75,0xd0,0x64,0x65,0x02,0x56,0xfa,0x08,0x12,0xaf,0xf5,0x90, 0x8f,0x13,0x08,0xce,0x97,0x1b,0xc7,0x0e,0xae,0x25,0x12,0x13,0x3c,0x72,0x77,0x2c, 0xc7,0xb3,0x35,0x1b,0x69,0x8f,0x60,0x93,0x3a,0x77,0xdf,0x78,0x99,0xe3,0x68,0x2e, 0xe6,0x57,0x47,0xd9,0x13,0xb8,0x15,0x31,0x58,0xa9,0xef,0xb0,0x1c,0x11,0x62,0xda, 0x79,0x3c,0xac,0xa2,0x1e,0xa7,0xdd,0xb9,0x55,0xe5,0x4d,0xca,0xa1,0x4f,0x78,0x2b, 0x68,0x35,0x20,0x8b,0x67,0xf6,0x4f,0x49,0xbd,0x14,0x85,0xf7,0xef,0xf0,0x0a,0xaf, 0xbd,0x48,0x74,0xcd,0x16,0xee,0x7c,0x96,0xf9,0xb1,0x63,0x38,0x42,0x70,0x1c,0xa0, 0x0d,0xb6,0x6b,0xeb,0x76,0x31,0xd7,0xea,0x13,0x40,0xdb,0xb1,0x75,0xf9,0xd0,0xa1, 0x53,0x45,0xf0,0x3c,0x7a,0x01,0xa2,0x94,0xc9,0x77,0x49,0x99,0xeb,0x25,0x1e,0x5a, 0x82,0x81,0x0a,0x54,0x72,0x78,0x3d,0x3b,0xb1,0x81,0x35,0xc6,0x99,0x38,0x91,0x8f, 0x07,0xc5,0xa1,0x98,0x18,0xaf,0x70,0x19,0xbf,0x6f,0x72,0x03,0x3a,0xb1,0xc1,0x29, 0xb9,0x69,0x59,0x1c,0x28,0xc6,0xe4,0x80,0x21,0x30,0xea,0xdd,0x95,0xcd,0x5a,0x72, 0xa8,0x66,0x63,0xef,0x85,0x99,0xff,0x12,0x0f,0xb4,0xe4,0xac,0x89,0x1e,0x5c,0x04, 0xb2,0x3d,0xe5,0xfd,0x51,0x69,0xdd,0x11,0xbd,0x3e,0x4d,0x27,0xfa,0x68,0x66,0x04, 0x4a,0xb6,0x4d,0x7e,0xd8,0xdb,0x0b,0x9a,0x8b,0xf5,0xc8,0x14,0x1f,0x42,0xa9,0x93, 0x5b,0x46,0x75,0xeb,0x04,0x17,0x54,0x51,0x16,0xce,0x2a,0xee,0x48,0x7f,0xbf,0xac, 0xae,0x36,0xba,0x81,0xe4,0x04,0x0b,0x38,0xd4,0x8f,0xa3,0x07,0x90,0x62,0xfc,0x1f, 0x5f,0x44,0x58,0x48,0xfd,0x26,0x98,0x44,0x2b,0x14,0x73,0xa4,0xfd,0x33,0x1c,0x85, 0xc5,0x3d,0xc7,0x35,0x59,0xd2,0x1a,0xff,0xe4,0x3a,0x87,0x86,0xaf,0xe8,0x7b,0xb0, 0x0f,0xe7,0xd0,0xd6,0xe4,0x82,0x01,0x61,0x8c,0x69,0x89,0x22,0x8e,0x98,0xf6,0x87, 0x50,0x1c,0xc4,0x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xc3,0xd2,0x2f,0xc4,0x74,0x68,0xab,0xb0,0xb9,0xf1,0xf6,0x0f,0x3b,0xaa,0xac, 0x72,0xd7,0xb6,0x3e,0x9c,0x7d,0xa0,0x42,0x54,0x49,0xff,0x79,0xd0,0x57,0x4c,0x95, 0x2e,0xfe,0xf1,0xba,0x52,0x44,0x60,0xfb,0x8b,0x32,0x03,0xbe,0x4e,0x79,0x77,0x00, 0x24,0x42,0xb7,0xe5,0x45,0xb1,0x14,0xd7,0x9a,0x37,0x1e,0xfe,0xdb,0x9d,0x7d,0x41, 0xa2,0x70,0x93,0x51,0x49,0xe5,0x5d,0x8f,0x5a,0x01,0x99,0xb2,0xde,0x3e,0x7b,0x8b, 0x4f,0x5e,0x29,0x4b,0x3f,0x0e,0x4e,0x7a,0x11,0x96,0x21,0xdd,0x17,0xf6,0x7b,0x0e, 0x76,0x19,0xa4,0xbd,0x23,0x8e,0xcb,0xb7,0x48,0x17,0x3f,0xca,0x20,0x25,0x68,0xd5, 0x3d,0x70,0x2c,0x24,0x2f,0x3b,0x95,0xb9,0x22,0x8d,0xbe,0xe0,0x05,0x7c,0x04,0x4e, 0x7f,0xb1,0x74,0x12,0x93,0xad,0xd4,0x8e,0x76,0x50,0x45,0xec,0xd7,0x31,0xda,0xf7, 0x5d,0xc6,0xc6,0x18,0x29,0xda,0x27,0x72,0x8a,0xd1,0x37,0xcc,0x5c,0x06,0x53,0x2a, 0xc0,0x16,0x95,0x32,0x56,0x20,0x90,0x57,0xe2,0x2f,0xe4,0x5c,0x35,0x69,0x7d,0xfd, 0x20,0x8a,0x6e,0x24,0x0d,0xed,0xb9,0x40,0xcd,0x93,0x6d,0x7b,0x4f,0x54,0x0a,0x42, 0x93,0x72,0xd4,0x0b,0x66,0xa1,0x7c,0xa5,0xb1,0xed,0x8d,0x92,0x2c,0xdc,0x9a,0x45, 0xf4,0x6b,0x31,0x46,0x31,0x1a,0xbd,0xbf,0xc2,0x77,0x57,0xe8,0xde,0x62,0x09,0x43,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0x06,0x3b,0x07,0xac,0x77,0xd9,0x2f,0xb9,0x4e,0x9c,0x98,0x2d,0x52,0x54,0xb9, 0x58,0x50,0x8e,0x79,0x92,0x6a,0x6e,0xb7,0xc1,0xf6,0x34,0xf5,0xdd,0xfa,0x55,0x4f, 0x07,0xbb,0x03,0x1f,0xac,0xbf,0x8e,0x71,0x99,0xa5,0x60,0x36,0x74,0xe8,0xc3,0x2f, 0x09,0x53,0xd1,0xdd,0x37,0xc7,0x94,0x10,0x41,0xbf,0xf3,0xe4,0xd4,0xc9,0x18,0xf6, 0x7d,0x8d,0x56,0x79,0x94,0x9e,0xca,0xbc,0x2e,0x40,0x0c,0x67,0x7d,0x40,0xea,0x27, 0x6e,0xba,0x72,0x87,0xb4,0x1d,0xa8,0x7d,0x70,0x1b,0x2a,0x73,0x63,0x40,0x3f,0x89, 0x0d,0x5f,0x6b,0x34,0x07,0x20,0xda,0x56,0x7e,0x47,0x4c,0x00,0xe3,0x63,0x59,0x66, 0x52,0xa9,0x64,0xfc,0x35,0x90,0xce,0xf4,0x75,0x06,0x05,0xdf,0x2b,0x7e,0xef,0x05, 0x04,0xfd,0xcf,0x55,0x57,0x63,0x31,0x47,0x5d,0xb4,0xdb,0x44,0x60,0x68,0x81,0xbd, 0xc8,0x10,0x75,0xdc,0x71,0xec,0xb8,0xff,0xab,0x84,0xa5,0xc4,0xbb,0xf8,0x44,0x21, 0x21,0x94,0xee,0x89,0x50,0x06,0x7a,0x6c,0x71,0x87,0x38,0x75,0x1a,0x9f,0x70,0x90, 0xc4,0x87,0xd7,0xc7,0x01,0x04,0x39,0x4d,0x24,0xa9,0x2a,0x8e,0x3c,0xb9,0xf8,0x25, 0xbf,0x1c,0xe9,0x9d,0x7a,0x17,0x96,0x29,0x0d,0x3b,0xcf,0xd6,0xeb,0x92,0x63,0xda, 0xbe,0xd8,0xfd,0x9a,0x7e,0x23,0xac,0xfb,0xf0,0x57,0xf9,0x1c,0x57,0x68,0xf9,0x67, 0x1f,0xcf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x51,0x98,0x88,0x50,0x85,0x41, 0x8f,0xde,0xa3,0xe6,0x9e,0x8e,0x2e,0x4c,0xc0,0xdf,0x1a,0x67,0x5c,0xb2,0x95,0x5b, 0xca,0x65,0xdc,0xaf,0x8c,0x55,0xaf,0x1c,0xfd,0x5a,0x11,0xae,0x7d,0x1e,0x77,0x01, 0x7c,0x2f,0x42,0xd5,0xcd,0x09,0xf4,0x7c,0x70,0xfa,0xad,0x1d,0xcc,0xf2,0xa1,0x8b, 0xaa,0x51,0xcc,0x93,0xeb,0xe3,0xaa,0x30,0x13,0x4d,0xa8,0x4a,0xaa,0x67,0xda,0x47, 0xe9,0xf5,0xc2,0x83,0x5b,0xfe,0x28,0x0d,0x76,0xee,0x18,0x21,0x2a,0x6a,0xb7,0x71, 0xc5,0x55,0xd9,0xf1,0xc8,0x0f,0xdb,0xbb,0x30,0x74,0xa9,0x4d,0xbe,0x15,0xba,0x7b, 0x24,0x95,0xb7,0x47,0xda,0xd8,0x45,0x28,0xb6,0x08,0xa0,0x4b,0x5b,0x1d,0x9c,0x0e, 0x0c,0xe1,0x5d,0xef,0x35,0x9e,0x4c,0xad,0xd5,0x24,0x1f,0xc1,0x30,0x37,0x49,0x8d, 0x5f,0xff,0x46,0xd7,0x96,0x6e,0x2d,0xcb,0xc1,0x11,0x87,0x60,0x79,0x5d,0x79,0x84, 0xe0,0x7d,0xb0,0xaf,0xba,0x12,0xf6,0x71,0x5e,0xa5,0x70,0xb5,0xdf,0x68,0xa2,0x57, 0x31,0xb6,0x6e,0x82,0x00,0x13,0x66,0xb7,0x38,0x72,0x95,0x00,0x70,0xeb,0x24,0x68, 0x0c,0x4b,0x95,0xc2,0xb1,0x5e,0x62,0x72,0x0e,0x55,0x02,0x4d,0x90,0x81,0x64,0xb4, 0x46,0xa5,0xe0,0xf1,0xcc,0x42,0x93,0xef,0x96,0x60,0x99,0x54,0x13,0xcc,0x45,0xad, 0x1f,0xfe,0xc5,0xa8,0x82,0x51,0xe5,0xad,0xef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18,0x49,0x1c,0x14,0x8a,0x0e,0xc5,0x00,0xaf, 0x69,0x74,0xee,0x28,0x31,0x98,0x15,0x9a,0x3b,0xba,0x28,0xa3,0x16,0xb7,0x17,0x30, 0x44,0x30,0xe8,0xff,0xa6,0xaa,0xe7,0x85,0x0a,0xf5,0x50,0x6d,0xd9,0x4b,0x1e,0x6b, 0x7d,0x72,0x2e,0x66,0x06,0x49,0x57,0xd1,0x45,0xae,0x6f,0x9f,0x41,0x04,0x5f,0x51, 0xbd,0x49,0xd3,0xe9,0xde,0x04,0xa6,0xe6,0x78,0x5c,0x8b,0xfe,0x70,0xe8,0xd1,0x9e, 0x17,0xc2,0xed,0x67,0xef,0x2f,0xd5,0xae,0xd7,0xb2,0xd1,0x75,0xf5,0x24,0xd1,0xfd, 0x9c,0xfe,0xaf,0xfb,0x73,0x76,0x2f,0x0d,0xc6,0x3f,0x8f,0xe6,0x9f,0x7b,0xe4,0x75, 0xcf,0x6d,0xf0,0xf5,0x5d,0x27,0x39,0x61,0x0c,0x29,0x0c,0x11,0x87,0xc7,0x1b,0xee, 0xe4,0x5b,0x18,0x0b,0x33,0xa2,0x5e,0x45,0x2f,0x3f,0xf8,0xbc,0xa3,0xc8,0x84,0x41, 0x5e,0x32,0xc6,0x4f,0x0d,0xae,0x38,0x5c,0x96,0x3a,0x59,0x0d,0x65,0x70,0x45,0x6c, 0x44,0xb9,0x03,0xbd,0xec,0x60,0x99,0xc1,0x57,0x23,0x4c,0x21,0x6d,0x0d,0xfa,0x20, 0x56,0x7b,0x45,0x02,0xc9,0x83,0xd9,0x5f,0x5f,0xd4,0x8f,0xcd,0xea,0xbe,0x0b,0x72, 0xad,0x76,0xca,0xad,0xbc,0x05,0x57,0xff,0x02,0xab,0xcc,0xd2,0x93,0x36,0x2b,0x61, 0x9d,0x94,0x05,0x58,0xd5,0x9f,0x04,0x8b,0xa0,0xdd,0x20,0xa4,0x69,0x6f,0x28,0xa9, 0x7c,0x77,0xa3,0x73,0x03,0x7a,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x6d,0xd1,0xac,0x54,0xb5,0xc1,0x30,0x86,0x1e,0x6c, 0x96,0x80,0xa2,0x3a,0xcb,0x7c,0xc6,0x80,0x3f,0x06,0x91,0xe6,0x27,0x15,0x6c,0x56, 0x45,0xda,0xcc,0xc4,0xe8,0xdd,0x36,0x7e,0xb3,0x47,0xcb,0x35,0x15,0x53,0x88,0x92, 0x00,0x4e,0xbf,0x49,0xa0,0x07,0x33,0xca,0x23,0x08,0x65,0x88,0xd1,0xdf,0x65,0x31, 0x39,0x85,0x5a,0xac,0x88,0xf7,0x28,0x1e,0xcc,0x6b,0x63,0x17,0x74,0x2d,0x30,0x42, 0xeb,0xdd,0x1f,0x20,0x0c,0x42,0x17,0x98,0x9c,0x2e,0x3c,0x64,0x9c,0x66,0x72,0x99, 0x2f,0x98,0xbc,0xf5,0x36,0x30,0x34,0x59,0xc2,0x01,0x99,0x30,0xcb,0x4b,0x74,0x35, 0x69,0xd0,0xc2,0x14,0x71,0xf7,0x53,0x32,0x74,0x2c,0x0c,0x3b,0x5d,0x0e,0xe0,0x3e, 0xb3,0xd9,0x0c,0xd5,0xf3,0xfe,0xb1,0xf0,0x50,0x7a,0x7b,0xa2,0xae,0xe4,0x15,0xcc, 0xad,0xc0,0x59,0x83,0x57,0x28,0x69,0xf1,0xab,0xe6,0x66,0xa8,0x74,0xfd,0x90,0x2e, 0xa2,0x1c,0xe3,0x2a,0x3e,0x95,0x41,0xba,0xde,0x38,0x09,0xdc,0x69,0xea,0x38,0x16, 0x7d,0xf3,0xb5,0x56,0x4c,0xf2,0x83,0x5b,0x74,0x88,0xee,0xf5,0xe3,0xdb,0xba,0xd1, 0xe7,0x80,0xe0,0x4e,0x3a,0xd6,0x20,0xbd,0xa6,0xde,0x27,0x12,0x4b,0x3a,0xd4,0x34, 0xd3,0x42,0xdb,0x93,0x94,0x06,0x3b,0xfb,0xe7,0x99,0xb2,0xfe,0x13,0x40,0x1f,0x25, 0x3c,0xcb,0x9c,0x9c,0x60,0xd5,0x4e,0xef,0x6a,0x5c,0x7d,0x27,0x1b,0xe7,0x62,0xd1, 0xb5,0x78,0x9c,0x96,0x51,0xad,0x2c,0xff,0x6c,0x8c,0x32,0x96,0x5a,0x56,0xb1,0xcc, 0x7b,0x01,0xe7,0x38,0xc4,0x04,0x03,0xdc,0xec,0xb1,0x90,0xc5,0xe0,0x47,0xe6,0xd3, 0x01,0x87,0xc5,0xa4,0x43,0xba,0x16,0x3f,0x0e,0xb3,0xff,0x7f,0x14,0x16,0x72,0x9c, 0x0e,0xae,0x61,0x34,0xec,0x25,0x63,0x8c,0xf8,0x9b,0x76,0x57,0x59,0xa3,0x0c,0xb5, 0x04,0x6c,0xc8,0xcb,0x25,0xd4,0xd0,0x72,0xc0,0x73,0xce,0xfa,0xea,0x21,0xa8,0x37, 0x0a,0x04,0x81,0x27,0x00,0x43,0xbb,0x56,0x02,0x4e,0x6a,0xaa,0x32,0x31,0x8a,0x8b, 0xcf,0xed,0x0e,0xfe,0xb6,0x24,0x67,0x08,0x29,0x10,0xf7,0x80,0x10,0x81,0x06,0xc4, 0x2e,0xcf,0x8f,0xcf,0x64,0x39,0xa2,0xb2,0xd9,0xa0,0x33,0x81,0x74,0xe3,0x0c,0x13, 0x91,0x56,0xb1,0x21,0xea,0xd5,0x5f,0x11,0xed,0x31,0x5a,0xdd,0x08,0xcb,0xc5,0x08, 0x4c,0xb5,0x04,0x61,0xbf,0x0d,0x1f,0xda,0xcf,0xcc,0x8a,0x6d,0x41,0xdb,0xa4,0x57, 0x27,0x37,0x6b,0x3b,0xd4,0x81,0xff,0x40,0x38,0xad,0x80,0x0e,0xef,0x3b,0x62,0x29, 0x77,0xe0,0x54,0x8a,0x66,0xb7,0x38,0x05,0x57,0x31,0xdc,0x1c,0x7b,0x2b,0x3f,0xa5, 0x88,0xf7,0x79,0x53,0x5e,0x35,0xab,0xc2,0x0c,0x0b,0xfd,0x3e,0xa5,0xc7,0x59,0xd4, 0x65,0x16,0x53,0xe1,0xc5,0xbf,0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0x96,0x8b,0xa4, 0x04,0x92,0x68,0xf1,0x1c,0xcb,0xfa,0x60,0x69,0x75,0x71,0x12,0xe5,0x33,0xc0,0xe9, 0xb4,0xc0,0xa7,0x69,0x27,0xf0,0xc7,0x03,0xc8,0xe4,0x64,0x51,0xb1,0x07,0x5b,0x5d, 0xc1,0x68,0x1d,0x3e,0xea,0x04,0x09,0x86,0x92,0x92,0xda,0xec,0x78,0x65,0x52,0x27, 0xbf,0xa2,0x15,0x8e,0xa4,0x88,0xbf,0xce,0x95,0x06,0xec,0xb3,0x14,0x72,0x60,0x49, 0x11,0x61,0x14,0x8c,0xd5,0x56,0x73,0x2f,0x87,0xe6,0xbe,0x09,0xb9,0xd5,0x58,0x85, 0xe7,0x88,0x7f,0x1a,0x9c,0x0b,0xa6,0x4c,0x41,0x5b,0xc2,0xac,0x17,0xb8,0x85,0x70, 0xe8,0xab,0x67,0x10,0x5d,0x63,0xf1,0xee,0x91,0xba,0x3c,0xd1,0x7a,0xff,0x83,0x01, 0x8e,0x0b,0x85,0x3f,0xcd,0x71,0x0a,0x9a,0x65,0x98,0xab,0x7a,0xb4,0xf5,0xfb,0x14, 0xf1,0x94,0x4a,0xda,0x3e,0x8c,0xce,0xb5,0x77,0xc9,0x15,0xab,0x9a,0x37,0x09,0x55, 0x82,0x44,0x4d,0x1f,0x8a,0xa8,0x99,0x15,0x22,0x3d,0xd7,0xce,0x41,0x75,0x76,0xb6, 0x32,0xa7,0x20,0x11,0x77,0x54,0x4a,0xac,0x5e,0xb7,0x84,0x19,0x23,0x12,0x86,0x47, 0x8c,0x41,0xac,0xe1,0xa0,0x62,0x8d,0x4b,0x11,0x90,0x4f,0x99,0xd0,0xdb,0xf4,0x4a, 0x41,0x31,0xb3,0xc7,0xfe,0x9b,0x0b,0x6b,0x77,0x3c,0x3c,0x3f,0x58,0x2c,0x6b,0x36, 0x27,0xad,0x0d,0xcf,0xc4,0x0e,0xd8,0xb2,0xa2,0x7c,0x28,0xce,0x3e,0xfa,0x4e,0x13, 0xc7,0x3b,0xfc,0x4b,0x0c,0x5d,0xbf,0xca,0x01,0x45,0x33,0xab,0x48,0xbf,0xe4,0xca, 0x39,0xf0,0x8c,0x8c,0xf8,0x81,0x3c,0x07,0x26,0x2e,0x10,0xb8,0x1d,0xc2,0x69,0xe1, 0x51,0x80,0xae,0xdf,0xf1,0x1c,0x29,0x94,0xec,0xa4,0xed,0x6d,0xaf,0xe8,0x1a,0x84, 0xc8,0x7e,0xe6,0x69,0xa8,0x0e,0xe3,0xe4,0xd0,0x94,0xf5,0xe0,0xce,0xac,0xb7,0x6c, 0x0a,0x4d,0xb7,0x3a,0xc7,0x84,0xac,0x29,0xec,0xd6,0x89,0x1e,0x3d,0x87,0x86,0x5a, 0xe8,0x6a,0xa0,0xb6,0x3f,0x89,0x5e,0x8a,0xdf,0x86,0x9f,0x53,0x68,0x87,0x78,0xed, 0x41,0x4e,0xb9,0xf1,0x81,0x88,0xea,0x1a,0x34,0x7e,0x2e,0x53,0xdf,0x52,0x72,0xb3, 0xf3,0x94,0x17,0x55,0x14,0x1d,0x09,0x47,0xff,0xd7,0x30,0xf1,0xbe,0x7e,0x53,0xff, 0xf8,0xb4,0x2f,0xff,0x03,0x49,0x13,0x70,0x16,0xb2,0xad,0x42,0xc0,0x95,0xef,0xc6, 0x64,0xab,0x31,0x0d,0xf1,0xee,0xbf,0xf2,0x53,0x8f,0x5d,0x60,0x30,0x4f,0x19,0x43, 0xab,0xde,0x57,0xad,0xa0,0xc9,0x69,0xf6,0xa9,0xd6,0xa4,0x87,0x51,0xd6,0xf4,0xa9, 0x06,0xf7,0xee,0xd4,0x86,0xe0,0xca,0xfa,0x2b,0xb1,0x45,0xa2,0xbb,0xe1,0x82,0x31, 0x77,0x05,0xd4,0x27,0xce,0x6d,0x33,0x23,0x55,0x91,0x19,0x91,0xd5,0x30,0xf5,0x10, 0x37,0xf4,0x11,0x4a,0x52,0x35,0x71,0xd9,0x11,0xcf,0xb2,0xc3,0x31,0x61,0x29,0xfc, 0xc0,0x68,0xc0,0x67,0x88,0x6c,0xdc,0xdc,0x1c,0x2a,0x4f,0x7f,0x23,0x4b,0x55,0x28, 0x05,0x39,0xea,0x1b,0x66,0xe8,0xae,0xea,0x51,0x84,0xec,0xac,0x6f,0x81,0x70,0xf2, 0xd5,0x17,0xd5,0xf7,0x83,0xee,0xd0,0x4d,0x14,0xc4,0xe4,0x99,0x86,0x72,0x3f,0x1f, 0x4c,0x32,0xe8,0x8d,0x4c,0xb2,0x4d,0xc5,0x82,0xb7,0xd1,0x9d,0x38,0x2d,0x8b,0xe9, 0x4d,0x94,0x6a,0xa6,0xe2,0xa5,0xe0,0xf9,0x35,0xe2,0xc3,0xc1,0x25,0xdb,0x2b,0x85, 0x54,0x6a,0x9b,0x87,0x9d,0xc2,0x0f,0x20,0xab,0x93,0xb4,0x82,0x5c,0x6c,0x23,0x56, 0x8e,0x4a,0xde,0x57,0x7c,0x50,0x20,0x6f,0x8b,0x3d,0xa2,0x02,0xa1,0x96,0x5e,0x47, 0x90,0x54,0xdd,0x50,0x9b,0xfc,0x81,0xa7,0x4f,0x4a,0x79,0x35,0x82,0x50,0x39,0x70, 0x94,0x24,0x7c,0x24,0xbd,0xbe,0x21,0x92,0xc6,0xe5,0xed,0xa1,0xec,0x90,0xbf,0x74, 0xe1,0xe9,0x25,0x1b,0x70,0xd0,0x88,0xcc,0x42,0xf5,0x03,0x2c,0xed,0x76,0x9f,0x44, 0x68,0xef,0x7e,0x3d,0x67,0x33,0x67,0xb0,0xee,0xbf,0xf6,0x32,0xc1,0xae,0xba,0x1a, 0x54,0xf6,0xb3,0xa2,0x50,0x2e,0x09,0x7b,0x45,0x08,0x4a,0xb2,0x0f,0x12,0x78,0x2d, 0xbc,0x92,0xb9,0x2c,0x43,0x66,0x64,0xd5,0x94,0x8e,0xd3,0xee,0x58,0xcf,0xa8,0x9c, 0xc1,0x64,0xad,0xcb,0x94,0x47,0xbb,0x83,0x70,0xb0,0xfb,0x2a,0x63,0xf2,0xaa,0xe4, 0xe2,0xed,0x4d,0x30,0xfa,0xd1,0xdc,0x0a,0x5b,0x69,0xb7,0xb2,0x5f,0x8f,0x9e,0x1b, 0xa8,0x84,0x56,0x37,0x96,0xf9,0x77,0x47,0xe5,0xa8,0x7d,0x50,0xe6,0xd4,0x75,0xa8, 0x7a,0x31,0xa5,0xbf,0xfd,0xcf,0xad,0x23,0x90,0x4a,0x2c,0xf4,0xb4,0x9c,0x23,0x86, 0x08,0x39,0x6e,0x76,0xa6,0x7e,0xf8,0x7e,0x19,0xf6,0x97,0xfb,0x18,0x13,0x67,0x99, 0xff,0xff,0xa9,0xb6,0x18,0xf3,0x4e,0xdd,0x71,0x34,0x9e,0x28,0xce,0xde,0x89,0xd5, 0x88,0x65,0x43,0x64,0xaa,0x2d,0xde,0x95,0x2a,0xc8,0xfc,0x46,0x19,0x1e,0xc8,0x46, 0x0d,0xca,0x81,0xfa,0x0c,0x6a,0x64,0xf3,0x29,0x56,0xd1,0x53,0xa7,0x44,0xa6,0x01, 0x7a,0x66,0xe8,0x5d,0x6e,0x92,0xd2,0x65,0xa6,0xaa,0x7e,0x38,0xe2,0x8a,0xda,0x1f, 0x0b,0x64,0x05,0x1a,0x07,0x41,0x03,0xf4,0xb2,0x37,0xb2,0xf1,0x98,0x9c,0x63,0x08, 0xc9,0x30,0x25,0x79,0x08,0x88,0x82,0xac,0x20,0x0e,0x0e,0x64,0x4e,0x0d,0x32,0x6d, 0x23,0x07,0x02,0x5d,0x9d,0x28,0x41,0x40,0x67,0xe6,0xe5,0x26,0x85,0xab,0xec,0x2f, 0x0d,0x77,0x99,0x3f,0x7e,0x24,0x73,0x69,0x5f,0x28,0x56,0xcf,0x16,0x28,0x23,0x46, 0x7d,0x7f,0xbf,0x0b,0x32,0xc0,0xf1,0xe3,0x99,0x78,0x68,0x94,0x41,0x03,0x14,0xb6, 0x07,0xef,0x81,0xb0,0xfd,0xcb,0x8f,0xc3,0x52,0x48,0xf3,0x26,0xac,0x22,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d,0x72, 0xa7,0xfa,0x48,0x13,0x1f,0x46,0x80,0x7e,0x7c,0x82,0x50,0x3a,0xff,0x83,0x2b,0xde, 0x30,0xb1,0x16,0x55,0x3a,0xcf,0xb2,0x41,0xcd,0x11,0xf8,0x51,0xc7,0xb4,0xa7,0x57, 0xb6,0x57,0xd2,0x4b,0x8d,0x49,0xc7,0x57,0x73,0xbe,0x62,0x1c,0x05,0x69,0x07,0xb7, 0x34,0x70,0xa3,0xbb,0x71,0x08,0xd3,0x99,0x41,0x0f,0x86,0x66,0x46,0xc0,0xc0,0xab, 0xaf,0x41,0x1a,0x37,0xfb,0xb7,0x82,0xc1,0xba,0xfd,0x12,0x54,0xa8,0x2e,0x21,0xb1, 0x17,0xa1,0x1d,0xd4,0x34,0x7e,0xd1,0x7f,0xd3,0xb1,0xcd,0x42,0x31,0x2f,0xed,0xd4, 0xed,0x34,0x02,0xb8,0x70,0xa4,0x6f,0xb7,0x08,0x67,0x61,0xe2,0x35,0x47,0xf1,0xf1, 0x5d,0xb0,0x1c,0x55,0x6f,0x5a,0x18,0xe9,0xfa,0x77,0x9c,0xf8,0x41,0x8f,0x85,0x40, 0xde,0x48,0x7b,0x47,0x02,0xda,0xc9,0x08,0xcd,0x0a,0xa0,0x2a,0xd0,0xd0,0xf1,0x85, 0x9c,0xfd,0xf2,0x10,0x0f,0xe4,0x98,0xd6,0x02,0xef,0x75,0x21,0x29,0xe0,0x75,0x0e, 0xaf,0xbe,0x50,0x15,0x84,0x42,0x9a,0x18,0xff,0x98,0xa3,0xa4,0x2f,0x0c,0xa9,0x89, 0x5e,0x98,0x17,0xc0,0x00,0x7a,0x12,0xdb,0x9d,0xe7,0x13,0x58,0x75,0x80,0x00,0x39, 0x82,0x83,0x8d,0x0c,0x5f,0x54,0x66,0x64,0x70,0xfb,0x94,0xf6,0xc1,0xb8,0xda,0x7d, 0xac,0x4f,0x2a,0xd6,0x93,0x69,0xbf,0x7d,0x20,0x7a,0x89,0xcc,0x18,0xf3,0x92,0xce, 0xa6,0x14,0x45,0x68,0xe1,0x7f,0xaf,0x1c,0x18,0x84,0x3f,0xee,0x33,0x07,0xe7,0xe3, 0xb9,0x84,0x75,0xe3,0xea,0xff,0xef,0x22,0x1d,0xed,0xd0,0x94,0x2d,0x03,0xd5,0x46, 0xb2,0x8e,0x1e,0x27,0x33,0x66,0xcf,0x05,0xd5,0x67,0xff,0xf4,0x92,0xd4,0xcc,0xfb, 0x63,0xf3,0xc2,0x71,0xb2,0x82,0x11,0x55,0x17,0x6e,0xb3,0xb1,0x68,0x76,0x0e,0x6b, 0x79,0x64,0x74,0xbc,0x64,0x97,0x53,0x60,0x41,0x66,0x27,0x6f,0x01,0x49,0x77,0x58, 0x14,0x24,0x39,0xff,0xeb,0x50,0xd0,0x68,0x81,0x99,0xeb,0x1b,0xb2,0x47,0x13,0xce, 0x5a,0xd5,0xdf,0x7b,0xfb,0xcb,0x5a,0x63,0xf9,0x85,0x46,0x47,0xb1,0xee,0x99,0x94, 0xee,0x7d,0xcc,0x3b,0x5c,0xe1,0x2d,0x06,0xdb,0xa4,0xe1,0xf5,0x77,0x0e,0x33,0xbb, 0xc4,0x60,0x55,0x13,0x4c,0xac,0x3f,0xf8,0xae,0xf3,0x32,0xf6,0x15,0xa4,0x1f,0x42, 0x04,0x54,0xc0,0x55,0x29,0xc6,0xf6,0x4c,0x07,0xdc,0x28,0x4f,0x3a,0xa1,0x15,0xf5, 0xb2,0xd2,0xea,0xf5,0x14,0x65,0x98,0x2e,0xd6,0x22,0x2f,0x7d,0x9f,0x31,0x03,0x64, 0x93,0x4c,0x16,0x1a,0x74,0xcf,0x93,0xc9,0x78,0x19,0x8e,0x16,0xae,0x3f,0x2e,0xe9, 0xbe,0x06,0x3c,0x0f,0xc1,0x1d,0xcc,0x71,0x54,0x74,0xff,0x12,0x54,0xe8,0x9e,0x9e, 0x99,0xb0,0x72,0x0f,0xeb,0xb8,0x04,0x1a,0xeb,0xc3,0xa8,0x78,0x82,0xba,0x09,0x76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xc5,0x20, 0xb1,0x2b,0x9c,0xf1,0xb0,0xc2,0x2c,0x85,0x61,0xcc,0xe2,0x78,0x89,0xa7,0x60,0x05, 0x48,0x78,0xd1,0x4a,0x18,0x6a,0x62,0xb5,0xc3,0x3f,0x84,0x2f,0x50,0xfc,0xa3,0x24, 0x58,0x27,0x4d,0x90,0xed,0xa4,0xd8,0x24,0x48,0x91,0x22,0x5a,0x59,0xf0,0xc8,0x6a, 0x18,0x8a,0xe3,0x7e,0xd5,0x4e,0x59,0x67,0xa4,0x16,0x4b,0xc1,0xdd,0x37,0x40,0x44, 0x97,0xaa,0x25,0x76,0xc8,0x51,0x5f,0x8d,0xa9,0x45,0x8e,0x8e,0x27,0x10,0x64,0x62, 0xb5,0x57,0x21,0x87,0x67,0xff,0xcb,0x60,0xf0,0xd3,0x4d,0xea,0xe1,0x9d,0xe0,0xba, 0x43,0xa9,0x0f,0x08,0x3f,0x0a,0x7b,0x16,0x61,0xcc,0x0e,0x37,0xf2,0x78,0x6e,0x75, 0x62,0x9e,0x40,0x77,0x7f,0x75,0xb3,0xca,0xc6,0x79,0xb9,0xd9,0x29,0x39,0xc1,0x9b, 0x4b,0x35,0xeb,0x44,0xf0,0x7a,0xa4,0x23,0xd9,0x09,0x33,0x38,0xb1,0x7e,0xbf,0x0f, 0x78,0xff,0xec,0x85,0x3e,0x38,0x99,0x64,0xf0,0xef,0x66,0x7f,0xaa,0xac,0xf2,0x4f, 0x0e,0x0b,0x03,0x62,0x19,0x65,0x62,0x18,0x1f,0xa8,0x1e,0xbd,0x01,0x0b,0x4b,0xdb, 0xe8,0x19,0x28,0xcc,0xc1,0xb6,0x40,0x21,0x39,0x9b,0x3f,0x1d,0x2d,0x19,0x98,0xc5, 0x9e,0xc5,0xbe,0xc9,0x38,0xae,0xd3,0xab,0xfa,0xbb,0x13,0xfe,0xf9,0x21,0xcd,0x93, 0x5b,0xce,0x3a,0x69,0xfb,0x32,0xe3,0x94,0xdc,0x55,0xb0,0xf4,0x2f,0xed,0xf1,0xc3, 0x04,0x55,0x3d,0xdc,0xeb,0x64,0x19,0x79,0x6b,0xd7,0x33,0x91,0x37,0x1e,0x56,0xd5, 0xf4,0xcd,0xd2,0xdc,0x69,0x24,0xfd,0x3d,0xe1,0x32,0xb4,0x1a,0xeb,0x9e,0x01,0x0a, 0x88,0x92,0x7b,0x96,0xd8,0x35,0xa7,0x6a,0x2d,0x5f,0x39,0x43,0x57,0x51,0xf8,0x0a, 0x59,0x0b,0x0a,0x93,0xd8,0x73,0x9f,0x56,0xfb,0x14,0x8c,0x31,0x95,0xac,0x6f,0x07, 0x7d,0x02,0x33,0x44,0xbf,0xe0,0x3e,0xf0,0x5f,0x78,0x8d,0x4a,0x37,0xab,0xf0,0x79, 0x09,0x7d,0xe5,0x58,0xbb,0x51,0xeb,0x23,0x52,0x59,0x73,0x13,0x77,0xf7,0x4a,0xda, 0xef,0xf1,0x1e,0x74,0x39,0xac,0xb3,0xb4,0x30,0x8a,0xb2,0x4d,0x4e,0x40,0xe9,0x13, 0x37,0x23,0x4d,0x1a,0xca,0x42,0xa7,0x81,0xc3,0x34,0xf4,0xd0,0xe1,0xe2,0x58,0x6c, 0xe7,0x14,0x2f,0xce,0xfc,0x6f,0x83,0xe2,0xff,0xb2,0x4e,0xaa,0xa1,0x72,0x34,0xac, 0x10,0x3e,0x95,0x39,0x5f,0x89,0xec,0xeb,0xda,0xb6,0x97,0x28,0x56,0x28,0xc7,0xe7, 0x1f,0xb9,0xa2,0xbd,0x99,0x12,0x4f,0x96,0x06,0xb1,0x55,0x61,0xd9,0x6a,0x3c,0x61, 0xca,0x16,0x4c,0x84,0x35,0xbd,0xb3,0x35,0x7f,0xec,0xd2,0xce,0xf0,0x61,0x64,0xb4, 0x19,0x05,0xae,0xac,0x40,0xd9,0xa5,0x07,0x66,0xdd,0xc3,0xad,0x99,0x5d,0xac,0xa7, 0xa8,0x60,0x2d,0x6e,0x29,0x00,0x53,0x41,0x05,0x4f,0xb8,0xff,0x3d,0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xb7,0x72,0xff,0x58,0x88,0x3f, 0x0a,0xce,0xd8,0x7c,0xbf,0x77,0x60,0x37,0xd6,0xd1,0x69,0xbc,0x64,0x5b,0x0d,0x74, 0x02,0x31,0x59,0xac,0x21,0x73,0x59,0x87,0x07,0xc6,0xad,0x28,0x26,0xfa,0x0c,0xe3, 0x19,0xb8,0xc0,0xa2,0xcd,0x6f,0x65,0xdd,0x8f,0x92,0xce,0x58,0xe2,0x6f,0x2a,0x14, 0xd4,0xa7,0xa4,0xd4,0xc4,0x18,0x72,0xf6,0xec,0x17,0xab,0x2f,0x47,0xc0,0x87,0xfb, 0x00,0x4e,0x94,0xe6,0x59,0xec,0xef,0x77,0x0b,0xda,0xec,0x87,0x40,0x94,0x36,0xc9, 0x08,0xcd,0x3c,0x8b,0x59,0x11,0xa2,0xaa,0xc3,0xfe,0xe8,0xe2,0xc8,0x9f,0x66,0x2c, 0x44,0x0a,0xe4,0xf2,0xa3,0xc9,0x66,0xd7,0x7c,0x60,0x92,0x37,0xf6,0x24,0xd1,0x01, 0x79,0x90,0x75,0x67,0x8c,0x62,0xb1,0xfb,0x77,0x3a,0x27,0x38,0xde,0x02,0x90,0xb3, 0x57,0x18,0xe3,0x2f,0x18,0xd0,0x99,0xa7,0x2c,0x8f,0x60,0x0d,0x23,0x98,0x2c,0xcb, 0x90,0xb8,0xb7,0x29,0x8b,0x6c,0x64,0xc6,0x30,0xae,0xa4,0x65,0xe1,0x8d,0x19,0x05, 0xe9,0xba,0xbb,0x17,0x6d,0x01,0x92,0x50,0x76,0xd9,0x30,0x56,0x92,0x95,0x91,0xdb, 0xdb,0xf9,0xdd,0x28,0xf2,0xf5,0x99,0x08,0x13,0x20,0x73,0x01,0x55,0xee,0x05,0x7b, 0xb2,0x96,0xd7,0x77,0xfa,0xa3,0x06,0x84,0x03,0xd9,0x76,0xf8,0x86,0x10,0x06,0xfe, 0x0e,0xe5,0xa8,0x5e,0xef,0x44,0x49,0x77,0x41,0x9f,0x67,0x52,0xf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54,0xed,0x2d,0x8d,0x56,0x3e,0xb8,0x97,0xee, 0x69,0x52,0xe4,0x9d,0x41,0xe7,0x76,0x1b,0x42,0x4f,0x9b,0x8a,0x72,0xff,0x43,0xd2, 0x82,0xa2,0x95,0x78,0xe6,0x52,0x9d,0x69,0xa2,0xb1,0xa6,0x7b,0x18,0x6b,0x76,0x23, 0x2a,0x93,0x1c,0x1a,0x69,0x1b,0x72,0x18,0xa3,0x68,0x67,0xfb,0xc8,0x29,0x75,0x56, 0x98,0x13,0x0f,0x4d,0xea,0x3f,0xe6,0xf8,0xfb,0x9d,0x2d,0x80,0x65,0x49,0x64,0x40, 0xab,0xdc,0x3f,0x2a,0x2d,0xba,0x5e,0x07,0xc9,0xf6,0x9f,0xdf,0xcc,0xf1,0x93,0x43, 0x8e,0x02,0x2c,0x48,0xa9,0x61,0xf4,0x7c,0x9f,0x43,0xff,0x39,0x35,0xb4,0x2a,0x15, 0x04,0x95,0x98,0x65,0x1a,0xc1,0x51,0xe9,0x01,0x3a,0x08,0xff,0xf2,0x55,0xb3,0x6d, 0x17,0xa9,0x5d,0xe4,0x23,0x38,0x37,0xf1,0x48,0xd1,0x6e,0xed,0xc7,0x32,0x0c,0xeb, 0x8f,0x7e,0xec,0xd7,0xc7,0xce,0xc5,0x89,0xb5,0x6f,0x41,0x93,0x43,0xe1,0x5a,0xe7, 0x5e,0xb0,0x31,0x31,0x04,0xff,0x04,0xef,0x07,0x58,0x9c,0xfe,0xcd,0xb8,0xcc,0x2a, 0xc1,0xa0,0x3d,0x10,0x90,0x0f,0x7e,0xf1,0x84,0x7d,0x85,0x4d,0x68,0x89,0x46,0x4f, 0x83,0xe0,0x93,0xf6,0xbf,0x97,0x40,0xae,0x6d,0x09,0xe7,0x39,0xa6,0x6a,0xd2,0x3f, 0x74,0x50,0x21,0x44,0xe4,0xdd,0xd7,0x10,0xd8,0x48,0x3f,0x3c,0xb7,0xde,0xd1,0x60, 0x0a,0x69,0x8c,0x4f,0xd3,0x2c,0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38,0x11,0x52, 0xe0,0x9f,0x43,0x73,0xa7,0x0d,0x09,0x68,0x58,0x44,0x82,0x99,0x42,0x14,0x36,0x64, 0x6e,0xb1,0xf7,0xb7,0x4f,0x51,0x89,0x12,0x36,0xa8,0x24,0xcc,0xca,0x49,0xda,0x82, 0x4a,0xd9,0x84,0x30,0x6e,0xf1,0xa2,0xe9,0xff,0x7a,0xf0,0xd3,0x48,0x2e,0x6c,0xbd, 0xe4,0x1c,0x2c,0x39,0x12,0x8a,0x90,0x5d,0x87,0xa4,0x4d,0x52,0x73,0xad,0x52,0xf4, 0xb6,0x95,0x54,0xff,0xe6,0xf6,0xc4,0xc1,0x31,0x15,0x0d,0x96,0x08,0x69,0x72,0x87, 0x3d,0xef,0xc1,0xd4,0x7a,0x3a,0xb6,0xc3,0x3b,0x2b,0x6c,0xb3,0x36,0x9b,0xfd,0x20, 0x53,0x13,0x3e,0x85,0x2f,0xc1,0xa3,0x0c,0xcd,0x03,0x46,0xf1,0xc2,0x1b,0xc5,0x69, 0x93,0x8c,0x22,0x56,0xe6,0x9c,0xf8,0x05,0x5e,0x13,0xe1,0x0e,0x6d,0x31,0x95,0xd2, 0x54,0x51,0x15,0xf7,0xb2,0x04,0x96,0xf4,0x67,0x0c,0x0a,0xe7,0xac,0x1a,0x9a,0x7e, 0x53,0x9a,0x54,0xa5,0x1c,0xb3,0x23,0xc6,0xee,0x36,0x0b,0x07,0x44,0xb0,0xa0,0x84, 0x43,0x15,0x33,0x74,0xa1,0xb6,0x93,0x9a,0xcc,0x7f,0xa0,0x92,0x53,0x4e,0xef,0x3d, 0x0d,0xb4,0x6e,0x5d,0x8c,0x37,0x7a,0x07,0x8a,0xbe,0x21,0x14,0x3c,0x36,0xcd,0xfa, 0x8a,0xa0,0x53,0xd6,0x7a,0x42,0x55,0x86,0x4c,0x37,0x6f,0xd3,0x89,0x48,0xe3,0x44, 0x13,0xa9,0xa8,0x29,0xee,0xd0,0x10,0x92,0xbb,0x07,0x5b,0xc1,0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xb8,0x54, 0x0e,0x64,0xb7,0x12,0x02,0x18,0xe3,0x4c,0x17,0x6b,0x62,0xd0,0x7d,0xb1,0xc8,0x9e, 0x66,0x16,0xcd,0x5e,0x68,0xab,0x70,0x5e,0xce,0xd3,0x6f,0x95,0x91,0x54,0xfe,0x31, 0x28,0x9a,0x22,0x57,0x1e,0xe6,0x73,0xee,0xb5,0x30,0xfe,0x0c,0x43,0x71,0xaa,0x39, 0x04,0x01,0x90,0x1e,0x78,0xc4,0x69,0xc0,0x38,0xd3,0xa7,0x9b,0x86,0xab,0x4e,0xdf, 0x53,0xb6,0xbb,0x2f,0xb8,0xd1,0x1b,0x38,0x68,0xdf,0xe0,0x4b,0x86,0x44,0x3b,0x43, 0x10,0x57,0xdc,0xa0,0x03,0xcb,0x96,0x21,0x71,0x49,0x7c,0xac,0xcf,0xfe,0x2f,0x2e, 0x4d,0x12,0x89,0x0f,0x29,0x90,0x12,0xe9,0x20,0x30,0x02,0x81,0xa4,0xc3,0xc6,0x61, 0x4d,0x41,0x75,0x9b,0xa2,0x5b,0xca,0xfb,0x09,0xbe,0xfc,0xb5,0x0e,0xf7,0x49,0x76, 0xf0,0xed,0xdb,0x6e,0x25,0xd4,0x04,0xa2,0x53,0x93,0xd0,0xfe,0xb5,0xf9,0xcd,0x13, 0x45,0x96,0x35,0x79,0xd7,0x58,0x26,0xe5,0x14,0xde,0x54,0x18,0x10,0x05,0x42,0xaf, 0xfe,0x1c,0xa6,0x15,0xb5,0x07,0x2a,0xe0,0xa3,0xef,0x3f,0xdc,0x08,0xc9,0x29,0xdd, 0x0d,0x5e,0x29,0x9d,0xcf,0xaa,0xdc,0x04,0xfe,0xfd,0x8d,0xb8,0xa1,0xa7,0x64,0xf5, 0x3d,0xd9,0x82,0x4a,0x3a,0x83,0x77,0x37,0xcb,0x22,0x31,0xf5,0x4c,0x50,0x3c,0x31, 0xcd,0x03,0xb4,0xaa,0xed,0x02,0x0f,0x13,0x2e,0xe7,0xfb,0x66,0x65,0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2,0x7d,0x89,0x07,0x71,0x93, 0x95,0x6a,0x85,0xd1,0xde,0xc2,0xf4,0xb8,0x16,0xc0,0x1a,0xb1,0x42,0x5b,0x93,0x96, 0x6d,0xfd,0xfc,0x64,0xbe,0x75,0xe4,0xb0,0x90,0x8a,0xe1,0xbb,0x93,0xd7,0x3a,0xc2, 0x66,0x44,0x3b,0x54,0x1b,0x76,0x8a,0x5d,0x71,0x59,0xa2,0x1f,0x38,0x64,0xf6,0xf7, 0x4f,0x3d,0xd9,0xcf,0x8e,0x77,0xb3,0x07,0x28,0x22,0xe5,0xe1,0x9d,0x46,0x88,0x2a, 0x66,0x1f,0x5e,0xf3,0x12,0xdd,0x8b,0x21,0xb9,0xb8,0x67,0x6a,0xe1,0xd1,0xf1,0x0e, 0xb3,0xb4,0xb3,0x7f,0x9b,0xff,0x4b,0x47,0xa0,0xaa,0x44,0x87,0x9c,0xac,0x9f,0xb0, 0x89,0x99,0x13,0x84,0x27,0x6b,0x8f,0x61,0xbb,0x3d,0x44,0x56,0xf0,0x0d,0x18,0xd0, 0x49,0x75,0xf0,0x70,0x4f,0xed,0x5c,0xeb,0x09,0xf7,0x5a,0x48,0x14,0x42,0xec,0xf4, 0x06,0x01,0xbc,0x82,0x93,0xd1,0x99,0x08,0xb0,0x4b,0x17,0x0b,0x3e,0x54,0x89,0x48, 0xec,0x3f,0x22,0xfa,0x86,0x21,0xc2,0xaa,0x67,0xae,0xb2,0x67,0x86,0xf0,0x9c,0x0c, 0x4c,0xd8,0x16,0x04,0x21,0xf2,0xa7,0x0d,0xaf,0xda,0x84,0xfd,0x94,0x8a,0x38,0xb7, 0x46,0x0b,0x27,0xf6,0x3f,0x82,0xaa,0x78,0x39,0xbf,0x19,0x6e,0x42,0x9d,0x19,0x0f, 0xfc,0xcd,0xf4,0x0a,0x36,0xaa,0xec,0x26,0x60,0x60,0x87,0xee,0x91,0x55,0x9a,0x09, 0x7e,0x87,0x0d,0x33,0x6d,0x1b,0x70,0x56,0xdd,0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b,0x7d,0x07,0xca,0xe9,0xa5,0xab,0x34,0x95, 0xbd,0x3b,0x97,0x4a,0x5c,0xbc,0xe6,0xdc,0x89,0x1d,0xfa,0xfd,0xa8,0xed,0x62,0xc4, 0x9f,0xa5,0x93,0x28,0x5a,0x63,0x99,0x1b,0x61,0x67,0x81,0x33,0x35,0x3b,0x69,0xf1, 0x05,0xab,0xab,0x16,0x57,0xa1,0x71,0x70,0xbb,0xbd,0x74,0xb1,0x37,0xdb,0x20,0x14, 0x03,0x47,0x75,0xe5,0x40,0xfd,0xfb,0x30,0x9e,0xab,0x74,0x26,0xbb,0xdb,0xaa,0x17, 0x4a,0xe0,0x0f,0x6e,0x34,0xe8,0x47,0x90,0x32,0xfd,0x1a,0x0a,0xa0,0x59,0xbb,0xaa, 0x86,0xce,0xa0,0x02,0x95,0xb5,0xc4,0x84,0xf6,0xa4,0xf8,0x36,0x58,0x6b,0x20,0x64, 0x97,0x84,0x8e,0x5b,0xb8,0x8e,0x65,0x13,0x90,0x80,0xe9,0x22,0x0d,0x19,0xe9,0x8c, 0x69,0xea,0x0f,0x3f,0xa7,0x13,0x56,0x20,0x71,0x68,0x9c,0x5e,0xfd,0x34,0x17,0xb2, 0x56,0xfc,0x7f,0xf5,0xe4,0xd6,0xb8,0xc9,0xbf,0x42,0x2c,0x09,0x9b,0x97,0x93,0xa3, 0x7b,0xbd,0xde,0x17,0x05,0xeb,0x9b,0x19,0xbf,0x6a,0x7b,0xf1,0xc2,0xf0,0x8b,0x3b, 0x0b,0x1e,0x20,0x1e,0x1d,0xd9,0xab,0x7e,0x58,0xc3,0x78,0xa1,0xeb,0xec,0xcf,0x86, 0xd6,0x24,0xc9,0x0c,0x55,0xa4,0xdd,0x6c,0x2b,0x36,0x38,0x38,0x6a,0x54,0x1c,0x91, 0xb7,0xa1,0x57,0xb8,0x0f,0x71,0xaf,0xaa,0x91,0xab,0x92,0xdc,0xd6,0xdf,0xa4,0xed, 0x08,0xae,0x79,0x6a,0xff,0x78,0x80,0xb3,0x69,0xfb,0xa5,0x46,0xff,0x60,0xa3,0x0a, 0x88,0xd0,0x87,0x3a,0xf2,0x00,0x7b,0xfd,0x3c,0x8a,0x7e,0x92,0x86,0xc2,0x36,0x0a, 0x22,0xbf,0x49,0x40,0xca,0xc1,0x5f,0x7e,0x11,0x30,0x83,0x6e,0x1d,0x06,0x62,0xa1, 0x96,0x36,0xb6,0x55,0x17,0x58,0x49,0xa9,0x82,0xc8,0x1f,0x69,0x94,0x40,0xfa,0x9f, 0x92,0x0d,0x7d,0x7c,0xdf,0x39,0xd6,0x00,0xa4,0x8d,0xac,0xb0,0x4c,0x75,0xd3,0xd2, 0xb6,0x2f,0x98,0x5c,0xab,0x62,0xc5,0x51,0xf1,0xff,0x03,0xf4,0x4c,0xf5,0xc3,0xe4, 0x06,0xee,0xe4,0xa2,0xda,0x5f,0x43,0xb4,0x35,0x23,0xd6,0x97,0x13,0x7e,0xb2,0x46, 0xda,0x2d,0x1b,0xee,0x64,0xd9,0xed,0x7c,0x61,0x68,0x5e,0x65,0x88,0x6d,0x0c,0x27, 0x12,0xb9,0x65,0x9f,0x24,0x99,0xe1,0x96,0x8f,0x32,0xcc,0x5c,0x34,0x6a,0xf0,0x14, 0x0b,0x08,0x4f,0x79,0xd1,0x5b,0x25,0x90,0xa7,0xfe,0x21,0x98,0xa8,0x85,0xd0,0x16, 0xc0,0x1a,0x05,0x15,0x69,0xdd,0x29,0xe3,0x53,0xff,0x39,0x5c,0xc4,0x21,0x31,0x06, 0xb4,0x0a,0x20,0xdc,0xdf,0x62,0x7f,0x80,0xd9,0xd4,0x53,0x0e,0x3d,0xdc,0x8f,0x61, 0x11,0x9c,0x7a,0xb4,0xb7,0x61,0x58,0x37,0x63,0x12,0x5f,0xbd,0x24,0x36,0x02,0xb8, 0x2c,0x1a,0xa1,0x4c,0x90,0x4d,0xaf,0x41,0xd9,0x1e,0xbf,0x08,0x77,0xd6,0x49,0x2a, 0x6d,0xfd,0x75,0x40,0x9f,0x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,0xea,0x79, 0x36,0x5b,0x5a,0xd5,0x95,0x1b,0x47,0xdb,0x88,0x20,0x20,0x38,0xf2,0xb4,0x78,0xc9, 0x6f,0x8e,0x34,0x0e,0xf3,0x34,0xd7,0x84,0x67,0x09,0x46,0x91,0x94,0x5a,0x3b,0x5d, 0xb2,0x78,0xe9,0xf3,0x33,0x80,0x89,0x8a,0xab,0x51,0x63,0x54,0xc4,0x09,0x1a,0xbf, 0xcb,0x2d,0x71,0x0b,0x94,0x42,0xb0,0x1d,0x07,0xee,0x6c,0xc0,0x9f,0x04,0xda,0xf8, 0xc6,0x80,0xdf,0x25,0xe2,0xbd,0x1d,0x96,0x2e,0xb8,0x16,0x91,0x6f,0xb6,0xfc,0xde, 0x01,0x14,0x91,0xdc,0xe5,0x59,0xaf,0x62,0xc8,0x90,0x11,0x97,0xf9,0x98,0x03,0xc0, 0x06,0xa2,0x7f,0xfb,0xa7,0x5c,0x9c,0xbb,0x7a,0x54,0x42,0xb5,0x03,0xde,0x22,0x3c, 0xe7,0x80,0x7e,0x68,0x0d,0x85,0xcb,0x75,0x1f,0xe0,0x11,0x75,0x34,0x52,0xf5,0x02, 0x05,0xcf,0x06,0xf5,0x77,0xe6,0xc2,0xd2,0x38,0x3f,0x77,0x4f,0xa6,0x30,0x4d,0x7c, 0x2b,0xe6,0x62,0x4e,0x52,0x45,0x3f,0xd5,0x5d,0x0a,0x78,0x6f,0xed,0x0f,0xd4,0x39, 0x68,0x22,0xcb,0x91,0x74,0x8a,0xc2,0x40,0x4c,0xad,0x9c,0xdc,0x3e,0xff,0x5d,0xa8, 0x74,0x3e,0x7a,0x98,0x1f,0x31,0x78,0x30,0x9e,0x91,0x62,0xaf,0x97,0x14,0x81,0x5c, 0x09,0xc7,0x04,0x36,0x10,0x96,0xec,0x08,0x60,0x99,0x31,0xbe,0xb9,0xd5,0x33,0x7d, 0xac,0xe8,0xde,0x00,0x41,0xac,0xf5,0xd2,0x1a,0xfb,0x15,0xdc,0x1c,0x07,0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6,0x60,0x72,0xf0,0xbd,0x9a,0x0e,0x12,0x0d, 0x7e,0x98,0x1c,0xab,0x5f,0x51,0x1c,0xe6,0x89,0x15,0x1d,0x01,0x90,0x90,0xc3,0x1a, 0xb0,0x60,0xd3,0xe9,0x3c,0xc2,0x79,0xec,0x99,0xc2,0x28,0xed,0x2c,0xd1,0xa7,0x76, 0xcb,0x12,0xe8,0x21,0x8c,0xd1,0x14,0xff,0xaf,0xce,0xb5,0xe0,0xb4,0x2f,0x58,0x81, 0x2f,0x92,0x18,0x55,0x36,0x41,0x11,0x40,0x24,0x1f,0xb5,0xc0,0xd6,0x35,0xcb,0xa9, 0x45,0x10,0x10,0xee,0xaf,0x4a,0x49,0xc9,0x77,0x73,0x8a,0xe3,0xf3,0x89,0x63,0x22, 0xa8,0x00,0x5c,0x90,0xe2,0xba,0x86,0xff,0x87,0xe2,0xc3,0xa1,0xf3,0xf7,0xe2,0xb7, 0xcb,0x73,0x53,0x70,0x93,0x45,0x4c,0x5c,0x68,0x06,0xc4,0x96,0xe9,0x7c,0xbe,0x3e, 0xef,0x0d,0x60,0xca,0x95,0xff,0x5b,0xe5,0x03,0xbf,0xdd,0x82,0x54,0x66,0x24,0x8c, 0x78,0xd3,0xe8,0xe6,0xed,0x27,0x00,0x56,0x9c,0xdb,0x73,0x94,0x27,0x5c,0xba,0x4c, 0x6a,0xf4,0xb3,0x9e,0x22,0xd1,0x99,0x50,0x48,0xca,0x1d,0x3a,0x0f,0x9b,0x38,0xe2, 0x79,0x6f,0x4a,0x4b,0xce,0x2f,0x54,0x8e,0xc1,0xf8,0x0f,0x32,0xa4,0xb3,0x90,0x61, 0x70,0x12,0xc2,0xe8,0xa6,0xc1,0x8b,0x56,0x8c,0x50,0xea,0x04,0x80,0x5a,0xe2,0xca, 0x7f,0x3c,0x36,0x04,0xfc,0x59,0xe1,0x8c,0x8e,0x14,0x2e,0x63,0x0a,0x09,0x3f,0x0a, 0x5e,0x09,0xfa,0x3c,0x66,0xa0,0x58,0x20,0x25,0x73,0xef,0xb7,0x5d,0xfb,0x11,0xa5, 0x7c,0x04,0x38,0xf2,0x54,0xec,0xe1,0x60,0x9b,0xb9,0x34,0xc8,0xe4,0x46,0xf3,0x3e, 0x66,0x4c,0xea,0xf6,0x94,0x96,0xfd,0x07,0xb1,0x56,0x25,0x05,0xf4,0x37,0xfd,0x79, 0xb9,0x33,0xc2,0x90,0x2d,0x91,0x83,0xbb,0xb4,0xe4,0x6b,0xe8,0x84,0xb2,0xec,0xc5, 0xb1,0x76,0x74,0x5b,0x83,0x72,0x5d,0xaf,0xb7,0x20,0x90,0x9e,0xab,0xbc,0x51,0x01, 0x5f,0x8b,0xb7,0x83,0x03,0x36,0xbd,0x94,0x4b,0xcc,0xd2,0xe3,0xcc,0xe7,0xa2,0xd4, 0x2c,0x88,0x6b,0x55,0x91,0xc1,0x10,0xb6,0x8b,0xcf,0x6d,0x44,0x1a,0x2b,0x22,0xcb, 0xc4,0x2c,0x75,0x50,0x52,0x01,0x5c,0xe1,0xc3,0xbc,0xbc,0x18,0xb6,0xb8,0xd6,0xa4, 0x10,0x9e,0xb1,0xda,0x15,0x0c,0xb0,0x9e,0xd5,0x66,0x26,0xba,0x43,0x40,0x95,0xfe, 0x8a,0x43,0x47,0x36,0xe4,0x1b,0xe1,0x43,0x7f,0xe7,0xa8,0x00,0x3b,0x76,0xe5,0xd1, 0xb3,0xac,0xe9,0x3b,0x44,0xf1,0xea,0x63,0xa0,0xba,0x95,0xf8,0x91,0x30,0x81,0xa0, 0x99,0x11,0x2b,0x3d,0x30,0x6d,0xa5,0x79,0x07,0xf8,0x0e,0xf7,0x15,0x39,0x38,0x36, 0xea,0x0a,0xad,0x6e,0x42,0x28,0x71,0xc4,0x3f,0xfb,0xba,0xec,0xd2,0xdf,0x46,0x28, 0x13,0x5d,0x7e,0xfe,0x17,0xae,0xd8,0x6d,0x6c,0xf5,0xd1,0x74,0x51,0x7f,0xa0,0x42, 0x23,0x89,0x7c,0xa5,0x08,0x4d,0x0b,0xf6,0x57,0xeb,0x07,0x0a,0x77,0x27,0xc7,0x9a, 0x37,0xb5,0x2f,0x45,0xe5,0xed,0x8f,0xae,0xd2,0x23,0xb3,0xbe,0xa5,0x7e,0x25,0x49, 0xa0,0x91,0x06,0x72,0x03,0xc3,0xe4,0x6a,0xde,0x53,0x18,0x58,0xe0,0x34,0xa1,0x19, 0x26,0xf0,0x92,0xb2,0x3b,0x86,0xd6,0xc6,0x49,0x7b,0xc0,0x42,0x17,0xe8,0xe5,0x87, 0xe9,0x9e,0x0c,0x36,0xdf,0xa4,0x5c,0x97,0x14,0x74,0xfa,0xb7,0x05,0xd1,0xc2,0x0f, 0x3f,0xab,0xcf,0xbb,0x30,0xeb,0xed,0x25,0xe5,0xda,0x9b,0x55,0x91,0xd9,0x98,0x0f, 0x21,0x08,0x94,0xfa,0x34,0x48,0x77,0x6c,0x4c,0xae,0xd7,0xdd,0x42,0x22,0x78,0xb4, 0x81,0x95,0x9a,0xd7,0x24,0x56,0x40,0xf8,0x0c,0xd2,0x46,0xce,0xd2,0x00,0xb0,0x7e, 0xc9,0xd2,0xfa,0xa1,0x58,0x97,0x0d,0xe1,0x24,0xe5,0xf0,0x39,0x8f,0x70,0xf4,0x88, 0x2a,0xfa,0x0d,0x4e,0x6e,0xe6,0x88,0x8d,0x30,0x1c,0xba,0x37,0xb4,0x52,0x9e,0x5f, 0xbb,0x90,0x2b,0xf1,0x6d,0x22,0xd8,0x41,0x10,0xc1,0xf3,0xe1,0x3e,0xc3,0x37,0xea, 0xc1,0x30,0x87,0x72,0x42,0x25,0x73,0x62,0x60,0x5d,0x35,0x97,0x4b,0x89,0x9a,0xe7, 0xc1,0x84,0x0d,0x47,0x02,0xee,0x92,0x35,0xab,0xe9,0xcc,0x47,0x0c,0x1f,0x8e,0x67, 0x60,0x6d,0x2f,0x3e,0x17,0x8b,0xf5,0x1e,0xe8,0x51,0xef,0xbe,0x75,0x6f,0x7f,0xa7, 0xf7,0x58,0x21,0x25,0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,0xd0,0x3a,0x5c,0x19,0x0f,0x0d,0xfd,0x12,0x09,0xa6,0x7e,0x98,0x80,0xfe, 0x19,0x79,0x4f,0x36,0xa1,0xd8,0x43,0xa4,0x1f,0xd2,0xd8,0xa9,0x36,0x61,0x70,0xe8, 0x8e,0x2c,0x92,0xdd,0xda,0x9f,0xe4,0xfb,0x86,0x91,0xfd,0xce,0x65,0x4a,0x30,0x0a, 0xe3,0x43,0x90,0x1d,0x99,0xc2,0xe1,0x27,0x4b,0x26,0x89,0x73,0xdd,0x99,0xe7,0x25, 0xcb,0xac,0x59,0x85,0xc3,0x63,0x2d,0x69,0x13,0xc9,0x78,0x0b,0xb8,0xde,0x4c,0xa1, 0x84,0x40,0x65,0x05,0x1b,0x3f,0x79,0xe7,0xf7,0x92,0x65,0x92,0x78,0xc3,0xdf,0x60, 0x7b,0x49,0xda,0x65,0xb6,0xe7,0xaa,0xff,0xcb,0x4a,0x7a,0xb6,0x0d,0xa9,0xbe,0x81, 0x68,0x4a,0x08,0x40,0x8d,0x7e,0x27,0xd2,0xef,0x19,0x00,0xec,0x66,0x9d,0xda,0x5b, 0x57,0xf2,0x88,0x4e,0xa3,0x27,0x84,0x36,0xa7,0x7e,0x08,0x1c,0xf5,0x3b,0xf0,0x5f, 0xbd,0x12,0x62,0x92,0xb2,0xa6,0xe0,0x22,0xce,0x7d,0x26,0x79,0x22,0x5c,0xfa,0x23, 0xc1,0x2a,0x19,0x78,0x31,0xcb,0x21,0x2b,0xd4,0xfd,0x04,0x45,0x4b,0x7d,0xc7,0xb5, 0x66,0x4f,0xbc,0xb6,0xc7,0x2b,0xf7,0x11,0x81,0x78,0x17,0xd6,0xbf,0x41,0x77,0x7e, 0x39,0x90,0xb8,0x51,0x15,0x52,0x85,0x05,0x36,0x0b,0x91,0x5d,0x66,0xfe,0x16,0x2b, 0xbe,0x4f,0xc3,0xac,0xa9,0xb8,0xe5,0x59,0x7f,0x82,0xc7,0x3f,0x44,0x17,0xde,0xde, 0x85,0x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d,0x8a,0x40,0xce,0x09,0x7f,0x92, 0x2a,0x63,0xd1,0xcf,0xc3,0x49,0xb9,0x22,0xd0,0x78,0x91,0x65,0x7e,0x56,0x1f,0xdc, 0xd9,0xc0,0x6c,0xac,0x55,0xf8,0x4a,0x07,0xdc,0xc7,0x0b,0x4f,0xe2,0xea,0xc2,0xd3, 0x32,0xff,0xa3,0x2a,0x48,0x61,0x81,0x9b,0xe0,0x94,0x4a,0x7a,0x56,0x24,0x86,0x76, 0xe2,0x44,0xf9,0x7e,0x77,0xa1,0xd7,0x39,0x53,0x60,0xd1,0x06,0x74,0x37,0xfc,0xc4, 0x21,0x4e,0x85,0x66,0x56,0xd1,0xd7,0x25,0x3f,0x94,0x7a,0xf5,0x7e,0x24,0x45,0xfb, 0x18,0xf9,0xcc,0x06,0x6a,0x06,0x56,0xb6,0xc3,0x28,0x2c,0xdf,0x97,0x17,0x84,0xc7, 0x04,0x98,0x26,0x5f,0xcf,0xa8,0xff,0x1d,0xa4,0xc2,0xcc,0xc9,0xb4,0x6d,0x1d,0x75, 0x14,0xf2,0xee,0xb9,0xfa,0x06,0xd8,0xf7,0x8f,0xb0,0x9c,0x7a,0x69,0xc9,0xe7,0x1d, 0x12,0x5a,0x2f,0xee,0xd2,0xef,0x8e,0xee,0xdf,0x51,0x82,0x89,0x71,0xfa,0x70,0x1c, 0x32,0xd7,0xda,0x61,0x59,0x66,0x13,0x62,0x78,0x56,0xef,0xb5,0x7e,0x44,0xe2,0xdf, 0xd1,0x84,0x03,0xbf,0x96,0x4d,0x1b,0x2c,0x3d,0x86,0xac,0x6b,0x4e,0x27,0x0e,0xcb, 0x05,0x42,0x78,0x0b,0x5b,0xc1,0x36,0xc9,0x6d,0x74,0xf9,0xaf,0xb5,0x3b,0x39,0x48, 0x54,0xb5,0x8f,0x16,0x3c,0x56,0x67,0x1e,0x8b,0xe4,0xc8,0x12,0x10,0x15,0x6c,0xd0, 0x16,0xfa,0x97,0x4a,0x79,0x25,0xd0,0x85,0xac,0x7f,0x23,0x7f,0x09,0xd0,0x3f,0x05, 0xf3,0xfc,0xd9,0x62,0x48,0x67,0x93,0xa6,0x21,0xff,0x0c,0xff,0xd9,0x02,0xc8,0x64, 0x9a,0xe2,0x80,0xfc,0xc8,0x63,0xed,0x61,0x13,0xf0,0x51,0x1c,0xfb,0xa9,0xfa,0xec, 0xc3,0x94,0x79,0x59,0x26,0x83,0x9f,0x57,0xbb,0x27,0xc6,0xc3,0xa1,0xc7,0x76,0x8a, 0x58,0xcc,0xc4,0xcd,0x2f,0x22,0xee,0xac,0x37,0xb7,0x0f,0x5a,0x8d,0x10,0x6f,0xbf, 0xac,0x0e,0x8d,0x7e,0xe1,0x8e,0x40,0x60,0x52,0x45,0x47,0x03,0xd9,0x9a,0x14,0x24, 0x87,0xbf,0x15,0x96,0x1c,0xee,0x46,0x28,0x9b,0xeb,0x1b,0xb2,0xfb,0x7e,0x9f,0x71, 0xd3,0x4b,0x7d,0x00,0x38,0x6b,0x20,0x50,0xad,0xa9,0x39,0x86,0x9a,0x88,0xf2,0x96, 0x3e,0xbd,0x59,0x85,0xa9,0xeb,0xf4,0x2a,0x52,0xae,0x9b,0x18,0x1b,0x3d,0x09,0x40, 0xd5,0xb0,0xe6,0x26,0xa3,0x14,0x92,0x68,0xfd,0x9e,0x42,0xbd,0x00,0x8e,0x3f,0x7c, 0x2d,0x48,0x9b,0x9e,0x55,0xfb,0x9c,0xf9,0xa7,0x1f,0x5b,0x87,0x28,0x10,0x77,0x37, 0xa5,0x33,0xea,0xec,0x23,0x40,0x21,0xa9,0x55,0x46,0x95,0xd5,0xbe,0xea,0xba,0x9c, 0xf6,0xd7,0xbc,0xd8,0x52,0xe9,0x42,0xb3,0x7e,0x84,0xec,0x55,0x92,0x0d,0x29,0x29, 0xca,0x22,0x55,0x67,0x30,0x5a,0xba,0x98,0x42,0xbe,0xb6,0x47,0xaa,0x04,0x0d,0x6b, 0xa7,0x0c,0x22,0x0f,0x0e,0xda,0xb4,0x98,0x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1a,0x8d,0x95,0x05,0x92,0x15,0x87,0xcd,0x4d,0xf0,0x3c,0x10,0x3f, 0xb2,0xfe,0xb7,0xe4,0x86,0x22,0x9f,0xe8,0x5e,0x35,0x7d,0x17,0x42,0x11,0xdb,0x09, 0xf2,0xee,0x47,0xc3,0xaa,0x4b,0x36,0x87,0x09,0x13,0xb4,0x61,0x6f,0x34,0x12,0xa5, 0xef,0x3f,0xc3,0x67,0xbb,0x2c,0x61,0x2a,0x55,0x22,0x90,0xe7,0x98,0x81,0x27,0x18, 0xee,0x0d,0x36,0xd7,0x0d,0x4a,0x97,0x41,0xbf,0xad,0xf9,0x38,0x2a,0xdd,0x94,0xd3, 0xc5,0xf6,0x48,0x27,0x17,0xa6,0xef,0x03,0xab,0x59,0xef,0x28,0x0a,0x9b,0x9f,0xdc, 0x0c,0xae,0x64,0x9b,0xc0,0x81,0x61,0x46,0x58,0x7d,0x21,0x05,0x52,0xd2,0xcb,0x34, 0x6c,0x98,0xc2,0x7d,0x86,0xf9,0x2c,0xd1,0xe1,0xa3,0x51,0x15,0x47,0x30,0x33,0x9a, 0xb4,0x20,0x49,0x7d,0x4a,0x65,0x70,0x7f,0xe7,0x1f,0x24,0x65,0xa6,0xcb,0xe9,0x7c, 0x44,0xc3,0x74,0xa0,0xff,0xe3,0xec,0xe7,0xf9,0x6d,0x7f,0x11,0xfb,0xd9,0xbe,0x66, 0xbf,0x0e,0x60,0x43,0xa8,0x8c,0x30,0x64,0x26,0xea,0x8e,0xbb,0x21,0x31,0x58,0xb2, 0xf4,0xdb,0x2c,0x17,0x91,0xa3,0xfb,0xce,0x34,0xbb,0xd4,0x61,0x7b,0xba,0xbd,0x3e, 0xaa,0xf7,0x3d,0xd9,0x87,0xc6,0x75,0x2a,0x80,0x97,0x9c,0xfb,0xac,0x14,0x8c,0xae, 0xe3,0xac,0x35,0xb6,0xc5,0x66,0x74,0xb4,0x8f,0xad,0xe1,0xd1,0x94,0x84,0x40,0x85, 0x34,0x13,0xe6,0x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b4,0x53,0xa9,0xb0,0x74,0x81,0x48,0xbd,0xa0,0x35, 0x41,0x4d,0xd1,0xa0,0x9a,0x98,0x5e,0x15,0x1b,0x90,0xb5,0xf6,0xae,0x9f,0x7c,0x67, 0x30,0xf1,0x88,0x67,0xf0,0x68,0x21,0x15,0x5d,0x4c,0x44,0x39,0xf7,0xc5,0x20,0x2e, 0xea,0xbd,0x61,0x4d,0x74,0x35,0xba,0x2e,0x4d,0x9c,0x97,0xe9,0x65,0x5a,0xb7,0x9e, 0xe0,0x19,0x72,0x59,0x93,0xc5,0xb3,0x69,0xa6,0xd8,0xe4,0xab,0xc8,0x7e,0x11,0x5f, 0xbe,0x9a,0xfe,0x85,0x27,0xea,0x70,0x6c,0x66,0xf3,0x9e,0x64,0xb3,0x00,0xa4,0x15, 0x60,0x24,0x92,0x52,0x6c,0x6d,0xba,0x6e,0x9a,0x8a,0x99,0xd4,0x0e,0xb5,0x57,0x7f, 0x56,0x9e,0x50,0x22,0xfb,0x98,0x0f,0x20,0x87,0x80,0x3c,0x9a,0x2c,0x2b,0x70,0x07, 0xac,0xb1,0xcf,0x6d,0x13,0xfb,0xe0,0x51,0x41,0xc4,0x32,0x03,0x39,0x05,0x37,0x28, 0x30,0xfb,0x12,0xae,0x69,0x9b,0x88,0xa3,0xb7,0x76,0xc5,0x56,0xfd,0x73,0x7b,0x5e, 0x86,0x85,0xe8,0x09,0x43,0xfb,0x1a,0xbd,0x94,0x34,0x2f,0x72,0xd1,0xef,0x49,0xcb, 0x2c,0xe7,0x14,0xb8,0x9d,0x33,0xe3,0x01,0x5a,0x76,0x38,0x52,0xcf,0xc0,0x7a,0x06, 0x61,0x8a,0xe5,0x98,0xe1,0xce,0x8c,0x08,0x25,0x52,0xea,0x78,0x71,0x74,0x59,0xc0, 0x3b,0xdc,0x42,0xe9,0xbf,0x61,0x1a,0x79,0x62,0x93,0x44,0x27,0x3f,0x42,0xe1,0x58, 0xd4,0x9c,0x27,0x65,0xf4,0xa1,0x49,0x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c,0xac,0xbc,0x91,0xb6,0x39,0x50,0xe2,0x92,0x23,0x33,0xef,0x3a,0x32,0xbf, 0x4e,0xdc,0xd5,0x9e,0xf1,0xd4,0xc6,0xf5,0x45,0x7b,0xc8,0x18,0x10,0xc1,0xf3,0xe8, 0xb4,0x32,0xa3,0x6e,0xa3,0xf4,0x83,0x46,0x6a,0x79,0xc8,0xf7,0xde,0xfc,0x7f,0xb9, 0x81,0x81,0xac,0xfb,0x8c,0x54,0x35,0xbb,0x34,0x03,0x05,0x02,0x77,0x39,0x73,0x88, 0x96,0x89,0x6e,0xab,0xdb,0x29,0x9c,0xd3,0xd7,0x02,0xfe,0x4c,0xcd,0x17,0x60,0x52, 0x6e,0x77,0x57,0x9a,0x9b,0x82,0xf8,0x61,0xb3,0xa7,0x82,0xe5,0xb2,0xfe,0x8d,0x65, 0xac,0x29,0xff,0xd5,0x63,0xda,0xcb,0x89,0xaf,0x88,0x90,0xd2,0xe7,0x93,0x37,0xb4, 0x9e,0xe4,0x7c,0x44,0x0b,0x06,0x37,0x26,0x22,0x54,0x5e,0xfa,0x68,0x44,0x20,0xe1, 0x85,0xff,0x6b,0x42,0x0a,0x20,0xc8,0x5d,0x73,0x38,0xa2,0xd2,0x2d,0x84,0x15,0x26, 0x1a,0x83,0x85,0x0b,0x87,0x74,0x3d,0x00,0x4a,0x52,0x7a,0x09,0xc8,0xa1,0x00,0x65, 0xfa,0x69,0x88,0x7f,0x50,0xba,0x33,0xe9,0x76,0x0c,0x6d,0x15,0xb7,0x67,0x21,0x75, 0x90,0x57,0x86,0xe4,0x13,0x18,0xe4,0x45,0x77,0x4a,0xd6,0x9f,0xfb,0x24,0x1e,0x25, 0xe8,0xa7,0x76,0x7e,0x12,0x19,0x4f,0x26,0x2a,0x3a,0x91,0xfb,0x42,0x8b,0x24,0x2c, 0xf7,0xf9,0xd4,0x8d,0x4c,0x8f,0x86,0xe9,0x25,0x7c,0x42,0x8e,0xad,0xb5,0xe5,0x98, 0x59,0x19,0x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c4,0xc3,0x4e, 0x3d,0x7d,0xb2,0x36,0x59,0x88,0x67,0x46,0x72,0x87,0x7a,0x29,0x94,0x2f,0x5e,0x67, 0xf3,0x26,0x2d,0xe0,0xa9,0x32,0x50,0xb6,0xaf,0xf1,0x41,0xf5,0x74,0xe1,0xfc,0x89, 0x81,0x16,0x88,0x14,0x3c,0xe2,0xe7,0x63,0xf0,0xbe,0x9f,0xc2,0x55,0x58,0x99,0x5a, 0x5a,0x29,0xe5,0x70,0xba,0xf0,0x1f,0xa4,0x87,0x76,0xde,0xf4,0x6f,0xa7,0xeb,0x0e, 0xde,0xe6,0x42,0x43,0x36,0x9c,0x6f,0xc4,0x65,0x91,0x96,0x5f,0xd8,0xed,0x01,0xce, 0xf9,0x03,0x6f,0x74,0x21,0x20,0x8c,0x00,0x93,0xc5,0xee,0x06,0x61,0x4a,0x2a,0x7a, 0xdd,0x6a,0x39,0x1d,0x86,0x8e,0x8b,0x42,0xd2,0xc3,0x7f,0x4a,0xe5,0xcd,0x3f,0x99, 0xf0,0x45,0x83,0x86,0x22,0xe7,0x9e,0x02,0x75,0x40,0x19,0x63,0xb7,0x98,0xc5,0x21, 0xd6,0x16,0x96,0x2e,0x18,0xc5,0x0a,0xec,0x98,0xaf,0xad,0xe3,0x8b,0xdd,0x29,0xab, 0xac,0xed,0x05,0x8e,0x01,0xda,0x0c,0x7c,0x2d,0xa3,0x0a,0x38,0x29,0x80,0xbf,0x35, 0xad,0x9d,0x93,0xe9,0x5c,0x50,0x1f,0x9d,0x42,0x50,0x4a,0x0f,0x6c,0xe3,0xee,0xac, 0x6b,0x82,0x79,0x50,0xab,0x79,0xd3,0xd7,0x02,0x73,0x0a,0x67,0xa8,0xa1,0x69,0xac, 0x37,0xd2,0xc2,0x5a,0xde,0x80,0xa6,0xd9,0x55,0xed,0x90,0x49,0x79,0xf4,0x2c,0xbc, 0x9d,0xd0,0x6f,0x67,0xb2,0x90,0x8c,0x58,0x28,0xe5,0xa5,0x36,0x16,0x61,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xc5,0x98,0xca,0x45,0x2e,0x4a,0xfa,0x2f,0x87,0xd1, 0x79,0x34,0x80,0x12,0xfa,0x6c,0x91,0x81,0x6d,0x91,0x1f,0x87,0x9f,0x20,0x80,0x09, 0x9c,0x21,0x99,0x07,0xaf,0x3c,0x50,0x7c,0xb8,0xca,0x86,0x6d,0x39,0x96,0x0a,0x37, 0x3b,0x88,0xa0,0x2c,0x33,0xce,0x07,0xa7,0x71,0x22,0x1d,0xf2,0x89,0x51,0x61,0xeb, 0xed,0x82,0xe6,0x02,0xe6,0x49,0xa0,0x27,0x63,0x1a,0x6d,0xe3,0x6b,0x56,0xb8,0xe4, 0x0e,0x32,0xb4,0x16,0xe0,0xd4,0x23,0x2f,0x5e,0xd1,0x01,0x7f,0xc4,0x38,0xbb,0x6b, 0x25,0xb2,0x7c,0x89,0xc9,0x9c,0xc4,0xb5,0xf9,0xc6,0x00,0xaa,0x7a,0xe2,0x9e,0x9e, 0x7f,0x67,0x93,0x21,0xc0,0x41,0x19,0x21,0x5e,0x6d,0x9a,0x67,0x55,0xe9,0x5f,0x16, 0xf7,0x75,0xd0,0xe1,0xb0,0x9c,0x08,0x8a,0x28,0xb3,0x44,0x13,0x7a,0x98,0xc3,0x74, 0xe4,0xf0,0xb7,0x00,0x50,0xfc,0xa4,0x60,0x9e,0x1c,0x98,0x58,0x93,0x0f,0x20,0x92, 0xcf,0x26,0x75,0x60,0x53,0x6b,0x8c,0x68,0x51,0xa0,0x32,0xd1,0xa9,0x83,0xc1,0xc1, 0xb9,0xa5,0xd4,0x77,0x29,0x8b,0xc2,0x65,0x1d,0x35,0x3e,0x49,0xe2,0x05,0xa0,0xbf, 0x06,0x98,0x01,0x58,0xd8,0xb4,0xa7,0x57,0x94,0xd6,0x99,0x55,0x56,0x1f,0xfa,0xf4, 0x59,0x20,0xa4,0x68,0xdf,0xb8,0xc0,0xce,0x4f,0x59,0xc2,0xc0,0x69,0x89,0xf3,0xd2, 0xc8,0x73,0x36,0x8b,0x4a,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x07,0x45,0xf0,0xdc,0x6f,0x68,0xc7,0xd0,0x7d,0x7f,0xae,0xf4,0x20, 0x24,0x45,0x78,0x34,0x12,0xce,0x51,0xd0,0x21,0x68,0x73,0x83,0xdd,0x00,0xc7,0xdd, 0xc2,0x99,0x26,0x0c,0xd0,0xbe,0xcd,0x92,0x1e,0x16,0x2a,0x06,0x48,0x1a,0xcf,0x0f, 0xda,0x28,0xf4,0xb1,0x63,0x14,0x1d,0x99,0x41,0xf9,0x04,0x7e,0x0e,0xfe,0x10,0x7d, 0xfa,0x88,0x61,0x08,0xd6,0x88,0xea,0x04,0xa3,0x7a,0xd1,0xa7,0xa1,0x92,0x32,0xab, 0xd3,0x3a,0x13,0x05,0x95,0x43,0xb2,0x74,0xef,0x48,0x68,0x64,0x40,0x90,0x1f,0x29, 0xac,0xda,0x22,0x89,0xf2,0x08,0x60,0x5c,0x7e,0xbf,0x38,0xb7,0xfa,0xf8,0x9f,0x37, 0xb7,0xb3,0x18,0xa8,0x0b,0xc1,0x62,0x82,0x61,0xf7,0xa3,0x90,0x0d,0x29,0x1c,0x5b, 0x49,0xc4,0x4b,0x21,0xf7,0x9f,0x6c,0x95,0xaf,0xf5,0x62,0xfe,0xca,0x1e,0x32,0x2c, 0x09,0x49,0x9f,0x0c,0x33,0x14,0xbd,0xe5,0xa0,0x52,0x11,0xf0,0xb7,0x2a,0x0e,0x15, 0xe1,0xe2,0x34,0xe8,0xcf,0x84,0x91,0x60,0x9b,0x81,0x25,0xce,0x78,0xba,0xe3,0x9d, 0xeb,0xd6,0xb9,0xb5,0x1b,0x3d,0x57,0x4e,0x24,0x4b,0x60,0x7b,0x69,0x99,0x6f,0x78, 0x2a,0x04,0x5c,0x87,0x6f,0x3e,0xdc,0xa6,0x24,0x8e,0xac,0x02,0x38,0x2c,0xf4,0xb2, 0x19,0x84,0x65,0x2a,0x52,0x13,0x8c,0x72,0xaf,0x16,0x0c,0xf6,0xc1,0x95,0xb9,0xfe, 0x3f,0x83,0x4a,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0x1a,0x5e,0x47,0x1b,0xc7,0x51,0x89,0x60,0x2b,0x95,0x7b,0xab,0x66,0x7b,0x0a,0x2e, 0xcd,0x80,0x6c,0xa1,0xac,0xe0,0x89,0xd4,0x4d,0x27,0x27,0x2c,0x82,0xdb,0xc2,0xb6, 0x84,0xf8,0x9d,0xc6,0x5d,0xc1,0x54,0x36,0x13,0x9c,0xec,0xc7,0x15,0x54,0x13,0xac, 0x98,0x34,0xac,0xa4,0xa2,0x21,0x38,0xee,0x35,0xeb,0x58,0x10,0x57,0x6b,0x06,0xa3, 0x6f,0x6a,0x32,0x13,0xb4,0x7f,0x20,0x19,0x67,0x48,0x81,0xd3,0xa5,0xa6,0x42,0x8d, 0x3e,0xc1,0x91,0x41,0xe9,0x34,0xe7,0x47,0x93,0x1f,0x56,0xc8,0xad,0x8f,0x52,0x58, 0x0b,0xd4,0xe5,0x53,0x8d,0x82,0x43,0x97,0x8b,0x05,0x43,0xe8,0x36,0xf2,0xc0,0x3a, 0xab,0xcc,0xac,0xa7,0x70,0x79,0x46,0xd9,0xcc,0x86,0xdb,0x90,0x33,0xf1,0x4c,0x42, 0x46,0xa8,0xca,0xe3,0x17,0x18,0xe5,0x47,0xea,0xc7,0x5c,0x40,0x0a,0x71,0xf0,0x5c, 0x68,0x81,0x29,0x9e,0x88,0x46,0xe8,0xbd,0xc0,0x8e,0xae,0x1d,0x5c,0x41,0xd6,0x7f, 0x67,0x33,0x13,0x64,0x6a,0x09,0x80,0x4a,0x91,0x7d,0x3b,0x8e,0x9b,0x84,0x4d,0x6b, 0x02,0x1b,0x55,0xff,0x09,0x0e,0x6a,0xa4,0x83,0xfc,0xa3,0x34,0xce,0x12,0x46,0x95, 0x9a,0x1f,0x0b,0x63,0x65,0x33,0x6e,0xfb,0xbe,0x4b,0xf2,0xd8,0xb7,0x7c,0xf9,0x32, 0x1c,0x02,0x50,0x60,0x86,0x54,0xdb,0x42,0x09,0x29,0x42,0xcc,0xd7,0xe2,0x69,0x69, 0x40,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51,0x66,0x49,0x8e,0x46,0xc3,0x8f, 0x19,0xb4,0x3f,0xc6,0x4f,0x56,0xec,0x6f,0xba,0x8e,0x82,0xb1,0x17,0x4d,0xd4,0x47, 0x35,0xf0,0x0a,0xec,0x15,0xd0,0x38,0x67,0xce,0xe8,0x3f,0xd4,0xba,0x8f,0x4a,0xc9, 0x30,0x96,0xb0,0xe3,0x53,0xe3,0x9a,0xc1,0xee,0xbc,0x18,0xd1,0xc7,0xe4,0x4c,0xc1, 0xe1,0x22,0x36,0x66,0xc7,0x95,0xfd,0x28,0xa4,0x1c,0x3d,0xc2,0xea,0xf6,0x8c,0x96, 0xba,0x72,0xc9,0x54,0xaf,0x64,0x65,0x5c,0xb7,0x7d,0x2f,0xbc,0x10,0x3d,0x77,0xe8, 0x62,0x22,0xc3,0x29,0x0d,0x65,0x11,0xf4,0x7f,0x93,0x16,0x30,0x83,0x33,0x59,0x53, 0xe6,0xd3,0x24,0x74,0x18,0x58,0x8e,0xce,0x38,0x68,0xf3,0xd0,0x50,0xae,0xda,0x34, 0x55,0x9b,0xbc,0x54,0x54,0xe1,0xe1,0x84,0x62,0x03,0x78,0xe1,0x54,0x62,0xb0,0xc4, 0x27,0x4f,0xb5,0x20,0x22,0x8e,0x4d,0xa7,0x50,0x32,0xc8,0x95,0x9c,0x42,0xbb,0xd6, 0xd5,0xba,0xa6,0x53,0xdf,0x92,0x41,0x06,0xb9,0x13,0x60,0xfe,0x1d,0xc7,0xf7,0x06, 0x64,0x08,0xee,0x3b,0x33,0x16,0xd2,0x4b,0xca,0x15,0x81,0x66,0x25,0x24,0x08,0x6a, 0x01,0x52,0xc8,0xe0,0xff,0xd8,0x39,0x78,0x51,0xfb,0x00,0x84,0x5e,0x06,0x4a,0xdf, 0xc2,0xed,0x36,0x65,0x27,0x4e,0xb0,0x6c,0x87,0x3b,0xb6,0x62,0xc3,0xf8,0xd5,0x35, 0xcd,0xff,0x79,0x66,0x62,0xe9,0xe3,0xff,0xb8,0x32,0xd6,0x3e,0x79,0x09,0xcb,0xaa, 0x8d,0x0a,0xa7,0x69,0x6d,0xcc,0x20,0xf8,0x57,0x1c,0xa9,0xfa,0xc0,0x97,0x35,0xd7, 0x0b,0x6c,0x28,0x9f,0xac,0x35,0xb8,0x6c,0x26,0x60,0x75,0x1d,0xd7,0xec,0x6c,0x65, 0xa2,0xcf,0xa7,0x54,0x89,0xf4,0xa8,0xbe,0x7d,0xf3,0x14,0xa0,0x98,0x92,0x4f,0x47, 0x90,0xa2,0xea,0xf1,0x61,0xad,0x70,0x47,0x03,0x63,0x94,0x2e,0x73,0x02,0x8f,0x63, 0xdb,0x84,0x94,0x08,0xdc,0xdb,0xad,0x98,0x56,0x53,0xd0,0x4d,0x91,0xf5,0xa0,0x80, 0x06,0xf5,0x37,0x52,0xc9,0x29,0x57,0xe7,0x01,0x72,0xf2,0xec,0x97,0x33,0xcf,0x69, 0xbd,0x40,0x10,0xcd,0x2c,0xe7,0x7e,0x3b,0xd5,0x79,0xae,0xe3,0x30,0xf5,0x66,0xd0, 0x2f,0xde,0xa7,0x6f,0x19,0xa1,0x4e,0xc6,0x25,0x17,0x82,0xaa,0x67,0xe6,0x9b,0xc0, 0xd6,0x2c,0xa8,0xfd,0x13,0x7f,0x1c,0xe5,0x9f,0x06,0x79,0xa4,0xe3,0xb8,0xbe,0x66, 0x31,0xf4,0x74,0xec,0xcd,0xf0,0xcf,0x12,0x89,0x98,0x65,0xe2,0xf5,0xa4,0x9a,0xa0, 0xf8,0xc4,0xe1,0x15,0x7a,0x84,0xa3,0x5d,0x58,0x67,0xd0,0xab,0xba,0xf0,0x38,0xf9, 0xb1,0xad,0xd0,0xc7,0x3f,0x77,0x83,0x47,0x01,0x56,0x31,0x33,0x48,0xf7,0xe1,0x9a, 0xae,0x3f,0x68,0xde,0xf0,0x54,0x48,0x7e,0xcd,0x60,0x38,0xf1,0x06,0xae,0xc5,0xa2, 0xc1,0x63,0x64,0xef,0x97,0x3f,0x24,0xcc,0xb4,0x63,0x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5,0x54,0xf5,0x91,0x8b,0x71,0x49,0x57,0xcd, 0x1b,0x80,0x10,0x92,0x21,0xb2,0xd0,0x5c,0x85,0x93,0x75,0x31,0xdf,0x0f,0x1d,0x12, 0x0d,0x54,0x78,0x9d,0xc4,0x30,0xdb,0xf9,0xc1,0xfc,0x77,0xb4,0xae,0x07,0x00,0x33, 0xee,0x9c,0xf3,0x59,0x05,0xbd,0x1c,0x9f,0x2f,0xcb,0xd0,0x6f,0x8c,0x5b,0xe5,0xaa, 0x04,0xef,0x05,0x65,0x06,0x6b,0x81,0x0c,0x54,0x9b,0x8f,0xe7,0xc5,0x9a,0x37,0x18, 0x60,0xf8,0xcd,0xb7,0xc7,0xef,0x89,0x00,0x4c,0xcf,0x4a,0x45,0x5d,0xe5,0x86,0xfa, 0x91,0x1c,0x6c,0xb1,0xc6,0x4c,0x90,0x60,0x5c,0x97,0x8b,0x21,0xc3,0x20,0x61,0x80, 0x5b,0x31,0x31,0xa9,0xd6,0x61,0x34,0x1a,0x67,0x18,0x86,0x6e,0x7c,0xf5,0xc2,0x99, 0x64,0xe0,0x38,0xfd,0x3e,0x21,0x9e,0x3d,0x74,0x1e,0x9d,0xa7,0xf2,0x4f,0xf2,0xc9, 0xfa,0x54,0xdd,0xfb,0xeb,0xe3,0x2d,0xe6,0x17,0x9f,0x29,0xe6,0x79,0xd2,0xbe,0x91, 0xc1,0xb3,0x9e,0x33,0xfd,0x04,0x8d,0x53,0x40,0x90,0x16,0x59,0x84,0xc0,0x0d,0xc3, 0x22,0xae,0x3e,0xff,0x59,0xca,0x2f,0x49,0xf9,0x29,0xc6,0x85,0xe2,0x0d,0xc1,0xa3, 0x09,0x84,0x48,0x32,0x97,0xb1,0x8f,0xba,0xa7,0x74,0x39,0x64,0x11,0x83,0x2b,0xfc, 0x62,0x22,0x5e,0xfe,0xef,0x90,0x55,0x76,0x7a,0x65,0xbf,0x3a,0xa8,0x89,0xda,0x0f, 0x84,0x5f,0x6c,0x3a,0x65,0x1b,0xe4,0xcc,0x5d,0x37,0x4d,0xf2,0xae,0x3a,0xf2,0xca, 0xf1,0x46,0x20,0x07,0xa1,0x94,0xcd,0xa4,0x17,0xe4,0x35,0x13,0xa0,0x09,0xce,0x61, 0x51,0x97,0x3e,0xe0,0xa3,0x98,0x6e,0x3e,0x33,0x88,0x56,0xe5,0x53,0x60,0x04,0x7f, 0x71,0x0d,0x81,0x87,0x5d,0xcb,0x3f,0xf6,0xd8,0x6d,0x1e,0x71,0xea,0xf3,0xe6,0xaf, 0x89,0x55,0xa8,0xb2,0x96,0x4d,0xda,0xb0,0xed,0xc3,0x69,0x27,0x1e,0x61,0x67,0xb7, 0xec,0xae,0x8a,0x98,0xd7,0xaf,0x61,0x8e,0xfa,0x22,0x83,0xfc,0xf4,0xda,0x68,0x78, 0xf4,0x81,0x89,0x2a,0x8c,0x67,0xa4,0x25,0xb2,0xa7,0x15,0x5c,0x79,0x25,0xbd,0x16, 0xa5,0x77,0x60,0x1b,0xd5,0x5b,0x99,0xb7,0x1b,0x83,0xb3,0x56,0x69,0x9a,0xf8,0x06, 0x1e,0x7c,0x98,0x50,0x38,0x60,0x60,0x98,0x0d,0x4e,0xa2,0xac,0xaa,0xcc,0xe9,0xf7, 0xf6,0x11,0x1a,0x16,0x72,0xc0,0xda,0x96,0x74,0x78,0x37,0x6d,0x2b,0xaa,0x99,0xe2, 0xc2,0x88,0x79,0xad,0x17,0xf7,0x10,0xfe,0x3e,0xb4,0x3e,0x3e,0x77,0x76,0xcf,0x8f, 0x77,0x88,0x9d,0xef,0xa7,0x22,0x26,0x1d,0xa5,0x05,0x8a,0x52,0x11,0xd0,0x65,0x17, 0x22,0x3a,0x7c,0xd2,0x12,0x1b,0x97,0x8b,0xf2,0xa7,0x91,0xe7,0xb6,0xe0,0xca,0xb3, 0x74,0xa7,0x13,0xc8,0xfd,0x7d,0x40,0xcf,0x7e,0x58,0x4a,0x92,0x95,0x42,0x7c,0xc9, 0xd1,0x4c,0xc0,0xca,0x69,0x8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0x3e,0x05,0xd6,0xa5,0x1f,0x01,0xc5,0x69,0x94,0xef,0x05,0xee,0x22,0x86,0x02, 0x30,0xae,0x16,0x26,0x85,0x2a,0x68,0xd7,0x87,0x5d,0x80,0x56,0xe9,0x03,0x38,0xfd, 0x9d,0x23,0x45,0xff,0x36,0x16,0xf9,0xfe,0xc0,0x5d,0x50,0x0a,0x1d,0xb3,0x3a,0xd9, 0xe2,0xd1,0xec,0xa6,0x8d,0xf2,0x30,0xa7,0xc6,0x84,0x73,0xd0,0xf8,0x3a,0xbf,0x53, 0xc0,0x30,0x61,0xce,0x93,0xf0,0x01,0xaa,0x50,0x79,0x42,0xb6,0x6c,0x2f,0xd8,0x6f, 0x31,0xe4,0x1e,0x7f,0xf5,0xe3,0x21,0x24,0x13,0x2d,0xab,0xc8,0x29,0xb6,0xb2,0x9b, 0x18,0x77,0xa5,0xf7,0x87,0x87,0x51,0x40,0x49,0x81,0xfd,0x65,0x64,0xa5,0x1c,0xa6, 0x55,0x3e,0x36,0xfb,0x83,0xad,0xa1,0xf8,0x0d,0x66,0xad,0xe8,0xc9,0x84,0x59,0xee, 0x4b,0x5e,0xc2,0xff,0xc9,0x01,0x5c,0xc7,0xf8,0x49,0x47,0x55,0x08,0x84,0xf0,0xf5, 0xe3,0x3f,0x50,0xf1,0xe2,0xdf,0x29,0xe4,0xc7,0x81,0xf2,0x3b,0xcb,0xb1,0xb7,0x50, 0xf4,0x3d,0x61,0xb6,0xcf,0x60,0xa4,0x66,0x8d,0x5b,0x85,0xa3,0x88,0x55,0x5b,0x85, 0x10,0x9c,0x60,0xa5,0xbe,0x00,0xc8,0x99,0x58,0x2d,0xd6,0x6f,0x61,0x8b,0x51,0xc0, 0xa2,0x7d,0x87,0x99,0xb0,0x96,0x48,0xc6,0xd7,0x0a,0xf5,0x3e,0xa4,0xa9,0xc7,0x94, 0x3c,0x69,0x2d,0x00,0x46,0x49,0x1e,0xee,0x78,0xaf,0x94,0x24,0x6d,0xb4,0xe7,0x14,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,0x30,0x83, 0x87,0x5b,0x33,0x40,0xeb,0x13,0x1e,0xd0,0x28,0x4d,0xc6,0x2a,0x17,0x2e,0x80,0xec, 0xeb,0xd2,0x89,0xc4,0xf0,0x3f,0x81,0x7f,0xfd,0x14,0xc1,0x63,0xe2,0xe4,0xe5,0x0f, 0x96,0x9f,0x6a,0xe4,0x02,0x53,0xa9,0xa8,0x8b,0xe1,0xdd,0x1a,0x92,0x7c,0x7e,0xce, 0xc7,0x78,0x37,0x03,0xfb,0x77,0x2c,0x49,0x33,0x10,0x94,0xa7,0xd9,0x91,0x95,0xca, 0xba,0x19,0x34,0xdf,0xb8,0xa7,0xcb,0x91,0xf4,0x56,0x89,0x03,0xc7,0xb2,0xb5,0x8a, 0x81,0x9d,0x6f,0x59,0x68,0x82,0x19,0xa5,0x41,0x01,0x65,0xca,0x30,0x9c,0x92,0xa8, 0x41,0x6f,0x36,0x8d,0x0c,0x82,0xf6,0xf2,0x46,0x7a,0xa0,0xf9,0x30,0xb3,0x97,0x04, 0x2f,0xb5,0x1e,0x57,0x63,0x3f,0x26,0x59,0x65,0x93,0x40,0x1f,0xf8,0x8a,0x28,0x3b, 0xce,0xe6,0xf3,0x8a,0xb8,0xb4,0x85,0x45,0x38,0x05,0x4e,0x59,0x52,0x85,0xf1,0x8b, 0x1f,0x74,0xf7,0x67,0x07,0xce,0x60,0xf0,0x39,0xc1,0x63,0x15,0x35,0xca,0x5f,0x79, 0x37,0x05,0x01,0x47,0xcb,0xa0,0x4e,0x23,0x64,0x63,0x56,0x5a,0xa0,0x79,0xa0,0x41, 0x60,0x6b,0x80,0x11,0x40,0x33,0x08,0x98,0x80,0x71,0x73,0x22,0x8c,0xd3,0x84,0xba, 0x31,0xb2,0xb5,0x23,0xf6,0xd1,0x28,0x90,0x38,0xe7,0xb0,0x23,0xd3,0x77,0x8b,0x18, 0xca,0x9e,0xfa,0x0f,0xea,0x5f,0x99,0x99,0x09,0xc2,0x3d,0xfa,0x10,0x0d,0x72,0x07, 0xc7,0xe0,0xb5,0xc2,0xe7,0x9f,0x84,0x45,0xbd,0x6a,0x63,0x92,0xbf,0x56,0xe5,0xee, 0x06,0x3e,0x74,0x4c,0x54,0x4e,0xda,0x0d,0x00,0x82,0x86,0xdc,0xd0,0xe3,0xfa,0x47, 0x63,0xf6,0x5f,0x5d,0xec,0x6f,0x54,0x27,0xf0,0x54,0x45,0x49,0xa6,0x90,0xd5,0x73, 0xc2,0xee,0xba,0xf1,0x4b,0xeb,0x20,0x78,0xd5,0x44,0x26,0x31,0x6a,0x65,0x19,0xab, 0xdc,0x27,0x5b,0xfe,0xeb,0x2f,0x6d,0x6d,0x99,0x9d,0xcd,0xb7,0x81,0xc1,0x54,0x37, 0xdd,0x06,0x80,0xd9,0xd6,0x85,0x25,0x50,0x91,0xcd,0x11,0xab,0xf5,0xf0,0x01,0x88, 0x4d,0x70,0x29,0xdd,0x61,0x2f,0x3b,0xa1,0x8c,0x98,0x8b,0x1f,0x30,0x4d,0xe4,0xce, 0xb8,0x9a,0x30,0xde,0xa0,0x99,0x0b,0x66,0x9c,0x3a,0x58,0x0e,0x9d,0x25,0x4b,0x7f, 0x9d,0xd9,0x13,0x6c,0xf0,0x74,0x81,0x46,0xf5,0x98,0x65,0xb0,0x44,0xf1,0xe9,0x77, 0x46,0xf5,0xc5,0x7c,0x4a,0x3d,0x41,0x23,0x3c,0x50,0x16,0x12,0x9b,0xb0,0xd6,0x7b, 0x1f,0xab,0xe7,0x6d,0xcd,0xf5,0x53,0xab,0xe7,0x10,0x86,0x26,0xc8,0x24,0x9f,0x47, 0x56,0x8e,0xd5,0x01,0x40,0xce,0xac,0x45,0xc0,0x02,0x64,0xb2,0x81,0xe0,0x8d,0xc9, 0xf8,0xb7,0x52,0x4e,0x48,0xd9,0xe6,0xae,0x53,0x16,0xfd,0x97,0xc6,0xe6,0xa5,0x68, 0xad,0x63,0x16,0x66,0x95,0xcb,0x57,0x44,0x69,0xc5,0x18,0x70,0x27,0x25,0x57,0xc9, 0x51,0x62,0x09,0x10,0x1a,0xa8,0xd2,0x12,0x82,0xff,0xe3,0x8a,0x4d,0xa5,0xa3,0x23, 0x06,0x4c,0xe7,0x24,0xb3,0x17,0x47,0xe3,0xaa,0xdc,0xce,0xa3,0x43,0x8e,0xfd,0x11, 0x2b,0x4c,0x70,0x18,0x78,0x10,0xc7,0x43,0x77,0x83,0x5b,0x8b,0x61,0x57,0x2d,0xc8, 0xea,0xa6,0x4e,0x6e,0x43,0xf9,0x08,0x37,0x05,0x2d,0x8c,0x81,0x98,0x53,0xf2,0x31, 0x84,0x58,0x21,0x61,0x64,0xfa,0xd7,0x9f,0x62,0x23,0xdf,0xf5,0x68,0x6e,0x86,0x28, 0x5d,0xb9,0x5d,0xd7,0xf2,0x3d,0xa9,0x66,0x9f,0xfa,0xdb,0x94,0x79,0xa9,0x42,0xd9, 0xf7,0x21,0x9b,0x4a,0xb8,0x90,0x06,0xb9,0xc7,0x96,0xe1,0x19,0x6e,0x3e,0x2b,0x26, 0x8f,0xd1,0x87,0xb3,0xb4,0xed,0xa7,0x7e,0x11,0x76,0xfb,0xca,0x97,0x98,0x84,0x1d, 0x16,0xc7,0x8e,0xf2,0x91,0x6e,0x94,0x84,0xb3,0x8c,0xba,0xe0,0xe1,0xec,0x7f,0xd3, 0x49,0x37,0xec,0x60,0xc1,0xe0,0x0a,0x8e,0xd2,0xff,0x52,0x1f,0xa7,0xbf,0x4a,0xb5, 0xf5,0xf8,0xbf,0xff,0x56,0xa4,0xc7,0x25,0x7b,0x4f,0xb7,0xdc,0x21,0x64,0x7f,0x31, 0x97,0x08,0x15,0x79,0x85,0x00,0xb4,0x1e,0x11,0x0a,0x38,0xbc,0x27,0x7e,0x3a,0x37, 0xd1,0x97,0xd0,0x59,0x52,0x0b,0x37,0x84,0x44,0x4b,0x32,0x89,0x41,0x35,0x6f,0x6a, 0x35,0x96,0xe6,0x93,0x24,0x8f,0x25,0x61,0xa7,0xeb,0xff,0x98,0x8c,0xe7,0xe8,0xe9, 0x28,0x0a,0x11,0xd2,0x5a,0x1d,0xe5,0x34,0x62,0x95,0xf1,0x96,0xdb,0x65,0xdf,0x51, 0xe4,0x81,0x56,0xe3,0x59,0x04,0x15,0x5a,0x96,0x59,0xf7,0x21,0xa5,0x58,0xfd,0x80, 0xd0,0x57,0x7d,0x39,0x36,0x92,0x62,0x10,0xd6,0xbf,0x0c,0x4b,0x36,0x92,0xdf,0xda, 0x3d,0x72,0x1c,0x58,0xe8,0xae,0x2c,0x19,0xd9,0x82,0xd4,0xf8,0x0e,0x54,0x92,0x33, 0xb6,0x88,0x3e,0x2b,0x71,0xf5,0xb4,0xe6,0x1a,0x89,0x74,0x32,0x7f,0xf6,0x5e,0x9c, 0xba,0xb0,0x31,0xb8,0x6f,0xdb,0xfd,0x25,0x78,0xe9,0x90,0x4e,0x25,0xa9,0x37,0x88, 0xee,0x3a,0xce,0x54,0xd6,0x30,0xb0,0xd2,0xb5,0x20,0x2c,0x18,0x5c,0xd7,0x26,0xee, 0x68,0x33,0x9b,0x75,0xca,0xb0,0x16,0x78,0x1e,0xac,0x07,0x86,0x8e,0x2d,0xd5,0xc0, 0xc5,0x25,0x58,0xb2,0x19,0xf9,0x31,0x1d,0xe1,0x1b,0xc1,0xed,0xda,0xc9,0x70,0x63, 0xaf,0xaf,0x28,0x1a,0x15,0x77,0x5e,0x51,0xc6,0x35,0x8f,0x1e,0x16,0x66,0x1a,0x2e, 0x50,0x8f,0x04,0xfb,0x90,0xc3,0xaa,0xf1,0xd0,0xf7,0x12,0x9e,0xb8,0x81,0x00,0xaf, 0x07,0xe1,0xe6,0x35,0x10,0x67,0x92,0x50,0xed,0xe7,0x5b,0x64,0xc9,0x6b,0x9f,0xff, 0x77,0xfb,0x7e,0xf8,0x1b,0xd6,0x21,0xf1,0xbb,0xae,0x48,0xb3,0x39,0x5d,0x7b,0x0d, 0xcf,0xc0,0x35,0x78,0xc2,0x10,0xaf,0x82,0xce,0x34,0x11,0x15,0x9a,0x9d,0x3a,0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x08,0xae,0xe1,0xc3,0x1b,0x9f,0xdc, 0xb4,0x0c,0x46,0x4b,0x9e,0x75,0xca,0xed,0x9b,0x0b,0x8b,0x8a,0x0c,0xb6,0xba,0x70, 0xae,0x58,0xec,0x2a,0xf8,0xb8,0x83,0xb7,0x5e,0xf3,0x6c,0x40,0x35,0x1a,0xba,0x4e, 0xa7,0x88,0xf5,0x30,0x11,0xfe,0x7c,0x6d,0x0e,0xf6,0xff,0x09,0xc8,0x65,0xdb,0xe4, 0x3e,0x67,0xd2,0xb8,0x3b,0xd8,0x02,0x60,0xca,0xda,0x35,0xf8,0xf7,0xc2,0xc5,0xb2, 0xcf,0x87,0xeb,0xcd,0xc1,0x86,0x22,0xe1,0x43,0x6b,0xb8,0x3f,0xd7,0x57,0x27,0xad, 0x2f,0x18,0xaa,0x13,0x3e,0xea,0x92,0x3f,0xc2,0x34,0x1c,0xbe,0x7d,0x82,0x9d,0x96, 0x0d,0x04,0x5a,0x80,0x12,0xd4,0x9f,0x83,0xee,0x2e,0x86,0x71,0xb9,0x7e,0x7d,0xab, 0x67,0xc1,0x26,0xcf,0x05,0xd3,0xf5,0x07,0x51,0x50,0xb2,0x8d,0xc6,0x40,0x0c,0x1b, 0x99,0x16,0x11,0xff,0xe3,0x44,0x4f,0xfa,0x80,0x59,0x36,0x61,0xd5,0x51,0x64,0x3d, 0xe2,0xfe,0x02,0x68,0xea,0x08,0x25,0x09,0x76,0xee,0xd9,0x47,0x48,0x99,0x65,0x68, 0x19,0x4c,0x2f,0x70,0x11,0x53,0x95,0xa6,0xc3,0xa4,0x83,0x0f,0xcc,0x35,0xb8,0xd2, 0x05,0x9a,0xb2,0x78,0x81,0x36,0x5a,0x9c,0x53,0x04,0x80,0xeb,0xfe,0x15,0x13,0x75, 0x02,0x02,0x0f,0x3e,0xae,0xbc,0x8f,0x9c,0x0c,0x8a,0x18,0x84,0x44,0x84,0xf3,0x67, 0xc2,0x02,0x2a,0x69,0xe6,0xac,0x44,0xc4,0xe0,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x1e,0xfa,0x02,0x24,0xd2,0x27, 0xf8,0x2c,0xd4,0x29,0xa3,0x02,0x53,0x18,0x02,0x6a,0x42,0x2b,0xfe,0x1a,0xb3,0x9e, 0xc8,0xec,0xf7,0x84,0x4a,0xae,0x8a,0xbc,0xac,0xfb,0x3b,0x7f,0x9d,0x63,0xcd,0xe1, 0x41,0x56,0xd1,0x19,0xe0,0xcf,0x78,0xd7,0x36,0x10,0x80,0x87,0xa8,0x03,0xd3,0x94, 0x81,0xc6,0x46,0x87,0x46,0x32,0xc9,0x48,0xa6,0x10,0xf4,0x54,0x31,0x83,0xab,0x00, 0x8c,0xf5,0x14,0x82,0x8b,0x6a,0x2b,0x33,0x6d,0xd4,0x79,0xdf,0x70,0x9d,0x98,0xb0, 0xca,0x8b,0xf4,0x4c,0x4c,0x02,0x05,0x82,0xf9,0x23,0xb0,0xf6,0xc1,0x92,0xe1,0x66, 0xfd,0x90,0x93,0xac,0x1b,0xd7,0x1e,0xc8,0xb1,0x61,0x59,0xe6,0xc9,0x41,0x56,0x48, 0x68,0x3e,0xc5,0x69,0x40,0x13,0x8c,0x6b,0xeb,0x3e,0x76,0x29,0xc5,0xd8,0xff,0x3c, 0x14,0xb9,0x65,0x22,0xe2,0x0c,0x44,0xed,0xe6,0xc6,0x9c,0x85,0xd4,0x48,0x14,0xb8, 0x0f,0x68,0x9d,0xa6,0x73,0xde,0xa1,0x96,0x24,0x18,0x36,0x96,0x85,0x8e,0x89,0x91, 0x93,0xe1,0xd6,0xcc,0x0d,0xdd,0xff,0xd6,0x16,0x01,0x35,0xba,0x2b,0x9e,0x6d,0x75, 0xbc,0x08,0x7f,0x58,0x65,0x34,0x51,0x03,0xd8,0x4e,0x5c,0x8e,0x20,0x1c,0x5f,0xa0, 0x65,0x4b,0x0d,0xab,0x1f,0x6f,0xb3,0xc8,0x47,0x0e,0x9b,0x07,0x85,0xed,0xcc,0xe6, 0x30,0x73,0x5a,0x9b,0x98,0x70,0xba,0x6d,0x91,0x24,0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b,0xd5,0xfc,0x8a,0x04,0x43,0x2b,0xb2,0x37, 0x3e,0x1e,0x0d,0x07,0x1e,0xbb,0x98,0x25,0x16,0x1a,0x1c,0x2e,0x2e,0x09,0x27,0xda, 0x23,0xa1,0x0f,0xdc,0x17,0x25,0x83,0x4b,0x28,0x49,0x39,0x25,0xf9,0xb8,0x6e,0xbf, 0x7d,0x8d,0xea,0x32,0x45,0x60,0xbf,0x77,0x6c,0xfb,0xbc,0x97,0xf9,0x6c,0xca,0x45, 0x9c,0xb9,0xc1,0x93,0x44,0x4d,0x98,0x2f,0xe2,0x71,0xe0,0x4b,0xf9,0x6f,0xab,0x14, 0xd7,0x8f,0xc5,0x71,0xc6,0x52,0x68,0x96,0x6d,0xf5,0xe4,0xeb,0xad,0xcc,0x27,0x0e, 0xc9,0x6c,0xb5,0x43,0x44,0x5c,0xc4,0x66,0xe7,0x0a,0x00,0x5d,0x52,0x75,0xf3,0xa0, 0x91,0xae,0x6d,0xa1,0xee,0x89,0x27,0x73,0x3b,0x8c,0x7b,0x75,0x09,0xcf,0x6d,0xd8, 0x23,0x49,0x96,0x19,0xe1,0x24,0xe2,0x53,0x7c,0x43,0xf3,0x33,0x74,0x29,0x99,0xed, 0x40,0xed,0x4d,0xa2,0x4d,0xb2,0xcb,0x11,0x0a,0x70,0x18,0xc8,0xed,0x47,0x41,0x2f, 0x29,0xd8,0xdc,0xdf,0x83,0xe7,0x5a,0x10,0x02,0xdf,0x98,0x99,0x25,0x6e,0x7a,0x14, 0x1f,0xc1,0x16,0x1b,0x86,0x8d,0x98,0xe8,0x87,0x36,0x46,0x52,0x1d,0x97,0xe5,0xbc, 0xa5,0x21,0x87,0xad,0x44,0x90,0xd9,0xf1,0x26,0x38,0x73,0xe0,0xe2,0xc0,0xfe,0xa3, 0xe1,0x47,0x82,0x64,0xb9,0xec,0xc1,0xf8,0xb3,0xb1,0xbc,0xe5,0x60,0x7f,0xd6,0xd7, 0x20,0xee,0x7f,0x46,0xcd,0x8e,0x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,0xd6,0x04,0x35,0x85,0xf0,0x24,0xfc,0x7e,0x52,0xe8,0xd0,0x85,0x58,0x1b,0x4e, 0x7d,0x04,0xe5,0x54,0x77,0x07,0x7d,0x2a,0xce,0x68,0xa4,0xb6,0x16,0x0f,0xa7,0xba, 0x39,0x49,0x6e,0xf9,0xd7,0xa1,0x5e,0x42,0x87,0xba,0x73,0x27,0x37,0xfa,0x53,0xfb, 0xeb,0x55,0xef,0x43,0x56,0x94,0xc8,0xd4,0x58,0x1f,0xb7,0x6f,0x29,0x35,0x5d,0x15, 0x39,0x36,0x33,0xe5,0xd0,0x77,0xdb,0xbc,0x7e,0x44,0x66,0x5c,0x72,0x7e,0x48,0x6a, 0xf1,0x8c,0x07,0xfc,0x3a,0x30,0xe6,0x38,0x4b,0x08,0x59,0xc6,0xcc,0xc5,0x50,0xe3, 0xf2,0x90,0x7f,0x9a,0x43,0x28,0x20,0xca,0xd0,0x69,0xe9,0x5d,0x3d,0x30,0x94,0xb7, 0xed,0x9e,0x2a,0xf0,0x47,0xd7,0xdb,0x94,0x59,0x09,0x14,0x9c,0x1f,0xdf,0xb6,0x4b, 0x51,0x63,0x2b,0x41,0x77,0xaa,0xc5,0x98,0x3b,0xb6,0x78,0x02,0x7e,0x53,0xca,0x29, 0xca,0x53,0x64,0x58,0xf8,0xa2,0x94,0xa2,0x4f,0x6c,0x7b,0x07,0x74,0xbc,0xf8,0x43, 0xce,0x4e,0xbe,0xf6,0x6b,0xe4,0x7a,0xf7,0x72,0x1d,0xc6,0x8d,0x3b,0x38,0xf3,0xb5, 0xe9,0x85,0xbc,0xec,0x6f,0x84,0x2a,0xcf,0xa6,0xe3,0x53,0xc4,0xce,0x5d,0xac,0x36, 0x4a,0xb3,0x55,0x64,0x79,0xb9,0x2c,0xd8,0xef,0x48,0xe3,0x7d,0x4d,0xf5,0xca,0xca, 0x82,0x3b,0xae,0xae,0x45,0x9f,0xef,0x80,0x42,0x09,0xdd,0x87,0x73,0xa9,0x1e,0x26, 0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0xa8,0x7d, 0x25,0x9d,0xd8,0xa0,0xfb,0x6d,0xd8,0x50,0x6b,0xb3,0x75,0x46,0x4a,0x8d,0xb6,0x73, 0x99,0xd5,0xb1,0x8c,0xab,0x5e,0x1f,0xbb,0x40,0xae,0x02,0xde,0x8a,0x4b,0x60,0x56, 0xc3,0x95,0xcc,0x3b,0x93,0x4c,0x40,0xad,0x71,0x09,0xf7,0x2d,0xce,0x6d,0xe3,0xe7, 0x4f,0x1e,0x68,0x8d,0x63,0x8f,0xbd,0xbd,0x59,0x8c,0x76,0xcc,0x34,0x16,0x13,0x70, 0x56,0x78,0xc7,0x1a,0xaa,0x38,0xbe,0xbc,0xed,0xc0,0x8f,0x4c,0x36,0xdb,0x6d,0x38, 0x8f,0x06,0x02,0x33,0xa4,0x2c,0x0c,0xc1,0x2a,0xab,0x30,0x3a,0xd3,0x7d,0x29,0xf2, 0x0c,0x82,0x10,0x92,0xfe,0xb2,0x08,0x9d,0x0b,0x9a,0xd6,0xe9,0xc9,0xea,0x81,0x2a, 0xe4,0x98,0xa3,0x56,0x94,0x90,0x6f,0x29,0x06,0x5b,0x3c,0xa4,0xa0,0x13,0x39,0xaa, 0xfc,0x17,0x0c,0x26,0x49,0xec,0xdc,0xce,0x90,0x2a,0x52,0x59,0x62,0x95,0x01,0x2c, 0x66,0x02,0x95,0xfa,0xe2,0x31,0x29,0xed,0x87,0x39,0x50,0xc2,0x2a,0x56,0xb5,0x05, 0x45,0xf4,0x84,0xe5,0xee,0xf7,0x5b,0xa5,0xbb,0x66,0x87,0xae,0xbe,0x5e,0x08,0xf9, 0x6a,0x17,0x5b,0xb6,0x66,0xda,0xa8,0xb5,0xe6,0xd0,0x15,0xf1,0x9b,0xd1,0xf8,0x01, 0x26,0xd5,0x75,0x88,0xfc,0x4a,0x8e,0x2a,0x6f,0x74,0xb7,0x62,0xf1,0x1e,0x86,0x82, }; BeamCrypto_Context* BeamCrypto_Context_get() { static_assert(sizeof(g_ContextBuf) == sizeof(BeamCrypto_Context), "context size mismatch"); return (BeamCrypto_Context*) g_ContextBuf; }
581558.c
/* Copyright (c) 2007 Scott Lembcke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include "chipmunk.h" #include "ChipmunkDemo.h" static void update(cpSpace *space) { int steps = 3; cpFloat dt = 1.0f/60.0f/(cpFloat)steps; for(int i=0; i<steps; i++) cpSpaceStep(space, dt); } #define WIDTH 4.0f #define HEIGHT 30.0f static void add_domino(cpSpace *space, cpVect pos, cpBool flipped) { cpFloat mass = 1.0f; cpFloat moment = cpMomentForBox(mass, WIDTH, HEIGHT); cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, moment)); cpBodySetPos(body, pos); cpShape *shape = (flipped ? cpBoxShapeNew(body, HEIGHT, WIDTH) : cpBoxShapeNew(body, WIDTH, HEIGHT)); cpSpaceAddShape(space, shape); cpShapeSetElasticity(shape, 0.0f); cpShapeSetFriction(shape, 0.6f); } static cpSpace * init(void) { cpSpace *space = cpSpaceNew(); cpSpaceSetIterations(space, 30); cpSpaceSetGravity(space, cpv(0, -300)); cpSpaceSetSleepTimeThreshold(space, 0.5f); cpSpaceSetCollisionSlop(space, 0.5f); // Add a floor. cpShape *shape = cpSpaceAddShape(space, cpSegmentShapeNew(cpSpaceGetStaticBody(space), cpv(-600,-240), cpv(600,-240), 0.0f)); cpShapeSetElasticity(shape, 1.0f); cpShapeSetFriction(shape, 1.0f); cpShapeSetLayers(shape, NOT_GRABABLE_MASK); // Add the dominoes. int n = 12; for(int i=0; i<n; i++){ for(int j=0; j<(n - i); j++){ cpVect offset = cpv((j - (n - 1 - i)*0.5f)*1.5f*HEIGHT, (i + 0.5f)*(HEIGHT + 2*WIDTH) - WIDTH - 240); add_domino(space, offset, cpFalse); add_domino(space, cpvadd(offset, cpv(0, (HEIGHT + WIDTH)/2.0f)), cpTrue); if(j == 0){ add_domino(space, cpvadd(offset, cpv(0.5f*(WIDTH - HEIGHT), HEIGHT + WIDTH)), cpFalse); } if(j != n - i - 1){ add_domino(space, cpvadd(offset, cpv(HEIGHT*0.75f, (HEIGHT + 3*WIDTH)/2.0f)), cpTrue); } else { add_domino(space, cpvadd(offset, cpv(0.5f*(HEIGHT - WIDTH), HEIGHT + WIDTH)), cpFalse); } } } return space; } static void destroy(cpSpace *space) { ChipmunkDemoFreeSpaceChildren(space); cpSpaceFree(space); } ChipmunkDemo PyramidTopple = { "Pyramid Topple", init, update, ChipmunkDemoDefaultDrawImpl, destroy, };
707682.c
const char *init_shopping[3]; void shopping_list(void) { init_shopping[0] = "cheese"; init_shopping[1] = "wine"; init_shopping[2] = "dessert"; }
833666.c
/* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * The Original Code is Copyright (C) 2006 by Nicholas Bishop * All rights reserved. * Implements the Sculpt Mode tools */ /** \file * \ingroup edsculpt */ #include "MEM_guardedalloc.h" #include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_dial_2d.h" #include "BLI_task.h" #include "BLI_utildefines.h" #include "BLI_ghash.h" #include "BLT_translation.h" #include "DNA_customdata_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_brush_types.h" #include "BKE_brush.h" #include "BKE_ccg.h" #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_image.h" #include "BKE_key.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_mesh.h" #include "BKE_mesh_mapping.h" #include "BKE_modifier.h" #include "BKE_multires.h" #include "BKE_node.h" #include "BKE_object.h" #include "BKE_paint.h" #include "BKE_particle.h" #include "BKE_pbvh.h" #include "BKE_pointcache.h" #include "BKE_report.h" #include "BKE_screen.h" #include "BKE_subsurf.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" #include "WM_api.h" #include "WM_types.h" #include "WM_message.h" #include "WM_toolsystem.h" #include "ED_sculpt.h" #include "ED_object.h" #include "ED_screen.h" #include "ED_view3d.h" #include "paint_intern.h" #include "sculpt_intern.h" #include "RNA_access.h" #include "RNA_define.h" #include "UI_interface.h" #include "UI_resources.h" #include "bmesh.h" #include "bmesh_tools.h" #include <math.h> #include <stdlib.h> #include <string.h> /** \name Tool Capabilities * * Avoid duplicate checks, internal logic only, * share logic with #rna_def_sculpt_capabilities where possible. * * \{ */ /* Check if there are any active modifiers in stack * (used for flushing updates at enter/exit sculpt mode) */ static bool sculpt_has_active_modifiers(Scene *scene, Object *ob) { ModifierData *md; VirtualModifierData virtualModifierData; md = modifiers_getVirtualModifierList(ob, &virtualModifierData); /* exception for shape keys because we can edit those */ for (; md; md = md->next) { if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) { return 1; } } return 0; } static bool sculpt_tool_needs_original(const char sculpt_tool) { return ELEM( sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_ROTATE, SCULPT_TOOL_THUMB, SCULPT_TOOL_LAYER); } static bool sculpt_tool_is_proxy_used(const char sculpt_tool) { return ELEM(sculpt_tool, SCULPT_TOOL_SMOOTH, SCULPT_TOOL_LAYER); } static bool sculpt_brush_use_topology_rake(const SculptSession *ss, const Brush *brush) { return SCULPT_TOOL_HAS_TOPOLOGY_RAKE(brush->sculpt_tool) && (brush->topology_rake_factor > 0.0f) && (ss->bm != NULL); } /** * Test whether the #StrokeCache.sculpt_normal needs update in #do_brush_action */ static int sculpt_brush_needs_normal(const SculptSession *ss, const Brush *brush) { return ((SCULPT_TOOL_HAS_NORMAL_WEIGHT(brush->sculpt_tool) && (ss->cache->normal_weight > 0.0f)) || ELEM(brush->sculpt_tool, SCULPT_TOOL_BLOB, SCULPT_TOOL_CREASE, SCULPT_TOOL_DRAW, SCULPT_TOOL_LAYER, SCULPT_TOOL_NUDGE, SCULPT_TOOL_ROTATE, SCULPT_TOOL_THUMB) || (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA)) || sculpt_brush_use_topology_rake(ss, brush); } /** \} */ static bool sculpt_brush_needs_rake_rotation(const Brush *brush) { return SCULPT_TOOL_HAS_RAKE(brush->sculpt_tool) && (brush->rake_factor != 0.0f); } typedef enum StrokeFlags { CLIP_X = 1, CLIP_Y = 2, CLIP_Z = 4, } StrokeFlags; /************** Access to original unmodified vertex data *************/ typedef struct { BMLog *bm_log; SculptUndoNode *unode; float (*coords)[3]; short (*normals)[3]; const float *vmasks; /* Original coordinate, normal, and mask */ const float *co; const short *no; float mask; } SculptOrigVertData; /* Initialize a SculptOrigVertData for accessing original vertex data; * handles BMesh, mesh, and multires */ static void sculpt_orig_vert_data_unode_init(SculptOrigVertData *data, Object *ob, SculptUndoNode *unode) { SculptSession *ss = ob->sculpt; BMesh *bm = ss->bm; memset(data, 0, sizeof(*data)); data->unode = unode; if (bm) { data->bm_log = ss->bm_log; } else { data->coords = data->unode->co; data->normals = data->unode->no; data->vmasks = data->unode->mask; } } /* Initialize a SculptOrigVertData for accessing original vertex data; * handles BMesh, mesh, and multires */ static void sculpt_orig_vert_data_init(SculptOrigVertData *data, Object *ob, PBVHNode *node) { SculptUndoNode *unode; unode = sculpt_undo_push_node(ob, node, SCULPT_UNDO_COORDS); sculpt_orig_vert_data_unode_init(data, ob, unode); } /* Update a SculptOrigVertData for a particular vertex from the PBVH * iterator */ static void sculpt_orig_vert_data_update(SculptOrigVertData *orig_data, PBVHVertexIter *iter) { if (orig_data->unode->type == SCULPT_UNDO_COORDS) { if (orig_data->bm_log) { BM_log_original_vert_data(orig_data->bm_log, iter->bm_vert, &orig_data->co, &orig_data->no); } else { orig_data->co = orig_data->coords[iter->i]; orig_data->no = orig_data->normals[iter->i]; } } else if (orig_data->unode->type == SCULPT_UNDO_MASK) { if (orig_data->bm_log) { orig_data->mask = BM_log_original_mask(orig_data->bm_log, iter->bm_vert); } else { orig_data->mask = orig_data->vmasks[iter->i]; } } } static void sculpt_rake_data_update(struct SculptRakeData *srd, const float co[3]) { float rake_dist = len_v3v3(srd->follow_co, co); if (rake_dist > srd->follow_dist) { interp_v3_v3v3(srd->follow_co, srd->follow_co, co, rake_dist - srd->follow_dist); } } static void sculpt_rake_rotate(const SculptSession *ss, const float sculpt_co[3], const float v_co[3], float factor, float r_delta[3]) { float vec_rot[3]; #if 0 /* lerp */ sub_v3_v3v3(vec_rot, v_co, sculpt_co); mul_qt_v3(ss->cache->rake_rotation_symmetry, vec_rot); add_v3_v3(vec_rot, sculpt_co); sub_v3_v3v3(r_delta, vec_rot, v_co); mul_v3_fl(r_delta, factor); #else /* slerp */ float q_interp[4]; sub_v3_v3v3(vec_rot, v_co, sculpt_co); copy_qt_qt(q_interp, ss->cache->rake_rotation_symmetry); pow_qt_fl_normalized(q_interp, factor); mul_qt_v3(q_interp, vec_rot); add_v3_v3(vec_rot, sculpt_co); sub_v3_v3v3(r_delta, vec_rot, v_co); #endif } /** * Align the grab delta to the brush normal. * * \param grab_delta: Typically from `ss->cache->grab_delta_symmetry`. */ static void sculpt_project_v3_normal_align(SculptSession *ss, const float normal_weight, float grab_delta[3]) { /* signed to support grabbing in (to make a hole) as well as out. */ const float len_signed = dot_v3v3(ss->cache->sculpt_normal_symm, grab_delta); /* this scale effectively projects the offset so dragging follows the cursor, * as the normal points towards the view, the scale increases. */ float len_view_scale; { float view_aligned_normal[3]; project_plane_v3_v3v3( view_aligned_normal, ss->cache->sculpt_normal_symm, ss->cache->view_normal); len_view_scale = fabsf(dot_v3v3(view_aligned_normal, ss->cache->sculpt_normal_symm)); len_view_scale = (len_view_scale > FLT_EPSILON) ? 1.0f / len_view_scale : 1.0f; } mul_v3_fl(grab_delta, 1.0f - normal_weight); madd_v3_v3fl( grab_delta, ss->cache->sculpt_normal_symm, (len_signed * normal_weight) * len_view_scale); } /** \name SculptProjectVector * * Fast-path for #project_plane_v3_v3v3 * * \{ */ typedef struct SculptProjectVector { float plane[3]; float len_sq; float len_sq_inv_neg; bool is_valid; } SculptProjectVector; /** * \param plane: Direction, can be any length. */ static void sculpt_project_v3_cache_init(SculptProjectVector *spvc, const float plane[3]) { copy_v3_v3(spvc->plane, plane); spvc->len_sq = len_squared_v3(spvc->plane); spvc->is_valid = (spvc->len_sq > FLT_EPSILON); spvc->len_sq_inv_neg = (spvc->is_valid) ? -1.0f / spvc->len_sq : 0.0f; } /** * Calculate the projection. */ static void sculpt_project_v3(const SculptProjectVector *spvc, const float vec[3], float r_vec[3]) { #if 0 project_plane_v3_v3v3(r_vec, vec, spvc->plane); #else /* inline the projection, cache `-1.0 / dot_v3_v3(v_proj, v_proj)` */ madd_v3_v3fl(r_vec, spvc->plane, dot_v3v3(vec, spvc->plane) * spvc->len_sq_inv_neg); #endif } /** \} */ /**********************************************************************/ /* Returns true if the stroke will use dynamic topology, false * otherwise. * * Factors: some brushes like grab cannot do dynamic topology. * Others, like smooth, are better without. Same goes for alt- * key smoothing. */ static bool sculpt_stroke_is_dynamic_topology(const SculptSession *ss, const Brush *brush) { return ((BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) && (!ss->cache || (!ss->cache->alt_smooth)) && /* Requires mesh restore, which doesn't work with * dynamic-topology */ !(brush->flag & BRUSH_ANCHORED) && !(brush->flag & BRUSH_DRAG_DOT) && SCULPT_TOOL_HAS_DYNTOPO(brush->sculpt_tool)); } /*** paint mesh ***/ static void paint_mesh_restore_co_task_cb(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; SculptUndoNode *unode; SculptUndoType type = (data->brush->sculpt_tool == SCULPT_TOOL_MASK ? SCULPT_UNDO_MASK : SCULPT_UNDO_COORDS); if (ss->bm) { unode = sculpt_undo_push_node(data->ob, data->nodes[n], type); } else { unode = sculpt_undo_get_node(data->nodes[n]); } if (unode) { PBVHVertexIter vd; SculptOrigVertData orig_data; sculpt_orig_vert_data_unode_init(&orig_data, data->ob, unode); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { sculpt_orig_vert_data_update(&orig_data, &vd); if (orig_data.unode->type == SCULPT_UNDO_COORDS) { copy_v3_v3(vd.co, orig_data.co); if (vd.no) { copy_v3_v3_short(vd.no, orig_data.no); } else { normal_short_to_float_v3(vd.fno, orig_data.no); } } else if (orig_data.unode->type == SCULPT_UNDO_MASK) { *vd.mask = orig_data.mask; } if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } BKE_pbvh_vertex_iter_end; BKE_pbvh_node_mark_update(data->nodes[n]); } } static void paint_mesh_restore_co(Sculpt *sd, Object *ob) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); PBVHNode **nodes; int totnode; BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); /** * Disable OpenMP when dynamic-topology is enabled. Otherwise, new entries might be inserted by * #sculpt_undo_push_node() into the GHash used internally by #BM_log_original_vert_co() * by a different thread. See T33787. */ SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && !ss->bm && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, paint_mesh_restore_co_task_cb, &settings); if (nodes) { MEM_freeN(nodes); } } /*** BVH Tree ***/ static void sculpt_extend_redraw_rect_previous(Object *ob, rcti *rect) { /* expand redraw rect with redraw rect from previous step to * prevent partial-redraw issues caused by fast strokes. This is * needed here (not in sculpt_flush_update) as it was before * because redraw rectangle should be the same in both of * optimized PBVH draw function and 3d view redraw (if not -- some * mesh parts could disappear from screen (sergey) */ SculptSession *ss = ob->sculpt; if (ss->cache) { if (!BLI_rcti_is_empty(&ss->cache->previous_r)) { BLI_rcti_union(rect, &ss->cache->previous_r); } } } /* Get a screen-space rectangle of the modified area */ bool sculpt_get_redraw_rect(ARegion *ar, RegionView3D *rv3d, Object *ob, rcti *rect) { PBVH *pbvh = ob->sculpt->pbvh; float bb_min[3], bb_max[3]; if (!pbvh) { return 0; } BKE_pbvh_redraw_BB(pbvh, bb_min, bb_max); /* convert 3D bounding box to screen space */ if (!paint_convert_bb_to_rect(rect, bb_min, bb_max, ar, rv3d, ob)) { return 0; } return 1; } void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *ar, Object *ob) { PBVH *pbvh = ob->sculpt->pbvh; /* copy here, original will be used below */ rcti rect = ob->sculpt->cache->current_r; sculpt_extend_redraw_rect_previous(ob, &rect); paint_calc_redraw_planes(planes, ar, ob, &rect); /* we will draw this rect, so now we can set it as the previous partial rect. * Note that we don't update with the union of previous/current (rect), only with * the current. Thus we avoid the rectangle needlessly growing to include * all the stroke area */ ob->sculpt->cache->previous_r = ob->sculpt->cache->current_r; /* clear redraw flag from nodes */ if (pbvh) { BKE_pbvh_update(pbvh, PBVH_UpdateRedraw, NULL); } } /************************ Brush Testing *******************/ void sculpt_brush_test_init(SculptSession *ss, SculptBrushTest *test) { RegionView3D *rv3d = ss->cache->vc->rv3d; test->radius_squared = ss->cache->radius_squared; copy_v3_v3(test->location, ss->cache->location); test->dist = 0.0f; /* just for initialize */ /* Only for 2D projection. */ zero_v4(test->plane_view); zero_v4(test->plane_tool); test->mirror_symmetry_pass = ss->cache->mirror_symmetry_pass; if (rv3d->rflag & RV3D_CLIPPING) { test->clip_rv3d = rv3d; } else { test->clip_rv3d = NULL; } } BLI_INLINE bool sculpt_brush_test_clipping(const SculptBrushTest *test, const float co[3]) { RegionView3D *rv3d = test->clip_rv3d; if (!rv3d) { return false; } float symm_co[3]; flip_v3_v3(symm_co, co, test->mirror_symmetry_pass); return ED_view3d_clipping_test(rv3d, symm_co, true); } bool sculpt_brush_test_sphere(SculptBrushTest *test, const float co[3]) { float distsq = len_squared_v3v3(co, test->location); if (distsq <= test->radius_squared) { if (sculpt_brush_test_clipping(test, co)) { return 0; } test->dist = sqrtf(distsq); return 1; } else { return 0; } } bool sculpt_brush_test_sphere_sq(SculptBrushTest *test, const float co[3]) { float distsq = len_squared_v3v3(co, test->location); if (distsq <= test->radius_squared) { if (sculpt_brush_test_clipping(test, co)) { return 0; } test->dist = distsq; return 1; } else { return 0; } } bool sculpt_brush_test_sphere_fast(const SculptBrushTest *test, const float co[3]) { if (sculpt_brush_test_clipping(test, co)) { return 0; } return len_squared_v3v3(co, test->location) <= test->radius_squared; } bool sculpt_brush_test_circle_sq(SculptBrushTest *test, const float co[3]) { float co_proj[3]; closest_to_plane_normalized_v3(co_proj, test->plane_view, co); float distsq = len_squared_v3v3(co_proj, test->location); if (distsq <= test->radius_squared) { if (sculpt_brush_test_clipping(test, co)) { return 0; } test->dist = distsq; return 1; } else { return 0; } } bool sculpt_brush_test_cube(SculptBrushTest *test, const float co[3], float local[4][4]) { float side = M_SQRT1_2; float local_co[3]; if (sculpt_brush_test_clipping(test, co)) { return 0; } mul_v3_m4v3(local_co, local, co); local_co[0] = fabsf(local_co[0]); local_co[1] = fabsf(local_co[1]); local_co[2] = fabsf(local_co[2]); if (local_co[0] <= side && local_co[1] <= side && local_co[2] <= side) { float p = 4.0f; test->dist = ((powf(local_co[0], p) + powf(local_co[1], p) + powf(local_co[2], p)) / powf(side, p)); return 1; } else { return 0; } } SculptBrushTestFn sculpt_brush_test_init_with_falloff_shape(SculptSession *ss, SculptBrushTest *test, char falloff_shape) { sculpt_brush_test_init(ss, test); SculptBrushTestFn sculpt_brush_test_sq_fn; if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) { sculpt_brush_test_sq_fn = sculpt_brush_test_sphere_sq; } else { /* PAINT_FALLOFF_SHAPE_TUBE */ plane_from_point_normal_v3(test->plane_view, test->location, ss->cache->view_normal); sculpt_brush_test_sq_fn = sculpt_brush_test_circle_sq; } return sculpt_brush_test_sq_fn; } const float *sculpt_brush_frontface_normal_from_falloff_shape(SculptSession *ss, char falloff_shape) { if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) { return ss->cache->sculpt_normal_symm; } else { /* PAINT_FALLOFF_SHAPE_TUBE */ return ss->cache->view_normal; } } static float frontface(const Brush *br, const float sculpt_normal[3], const short no[3], const float fno[3]) { if (br->flag & BRUSH_FRONTFACE) { float dot; if (no) { float tmp[3]; normal_short_to_float_v3(tmp, no); dot = dot_v3v3(tmp, sculpt_normal); } else { dot = dot_v3v3(fno, sculpt_normal); } return dot > 0 ? dot : 0; } else { return 1; } } #if 0 static bool sculpt_brush_test_cyl(SculptBrushTest *test, float co[3], float location[3], const float area_no[3]) { if (sculpt_brush_test_sphere_fast(test, co)) { float t1[3], t2[3], t3[3], dist; sub_v3_v3v3(t1, location, co); sub_v3_v3v3(t2, x2, location); cross_v3_v3v3(t3, area_no, t1); dist = len_v3(t3) / len_v3(t2); test->dist = dist; return 1; } return 0; } #endif /* ===== Sculpting ===== */ static void flip_v3(float v[3], const char symm) { flip_v3_v3(v, v, symm); } static float calc_overlap(StrokeCache *cache, const char symm, const char axis, const float angle) { float mirror[3]; float distsq; /* flip_v3_v3(mirror, cache->traced_location, symm); */ flip_v3_v3(mirror, cache->true_location, symm); if (axis != 0) { float mat[3][3]; axis_angle_to_mat3_single(mat, axis, angle); mul_m3_v3(mat, mirror); } /* distsq = len_squared_v3v3(mirror, cache->traced_location); */ distsq = len_squared_v3v3(mirror, cache->true_location); if (distsq <= 4.0f * (cache->radius_squared)) { return (2.0f * (cache->radius) - sqrtf(distsq)) / (2.0f * (cache->radius)); } else { return 0; } } static float calc_radial_symmetry_feather(Sculpt *sd, StrokeCache *cache, const char symm, const char axis) { int i; float overlap; overlap = 0; for (i = 1; i < sd->radial_symm[axis - 'X']; ++i) { const float angle = 2 * M_PI * i / sd->radial_symm[axis - 'X']; overlap += calc_overlap(cache, symm, axis, angle); } return overlap; } static float calc_symmetry_feather(Sculpt *sd, StrokeCache *cache) { if (sd->paint.symmetry_flags & PAINT_SYMMETRY_FEATHER) { float overlap; int symm = cache->symmetry; int i; overlap = 0; for (i = 0; i <= symm; i++) { if (i == 0 || (symm & i && (symm != 5 || i != 3) && (symm != 6 || (i != 3 && i != 5)))) { overlap += calc_overlap(cache, i, 0, 0); overlap += calc_radial_symmetry_feather(sd, cache, i, 'X'); overlap += calc_radial_symmetry_feather(sd, cache, i, 'Y'); overlap += calc_radial_symmetry_feather(sd, cache, i, 'Z'); } } return 1 / overlap; } else { return 1; } } /** \name Calculate Normal and Center * * Calculate geometry surrounding the brush center. * (optionally using original coordinates). * * Functions are: * - #calc_area_center * - #calc_area_normal * - #calc_area_normal_and_center * * \note These are all _very_ similar, when changing one, check others. * \{ */ static void calc_area_normal_and_center_task_cb(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; float(*area_nos)[3] = data->area_nos; float(*area_cos)[3] = data->area_cos; PBVHVertexIter vd; SculptUndoNode *unode = NULL; float private_co[2][3] = {{0.0f}}; float private_no[2][3] = {{0.0f}}; int private_count[2] = {0}; bool use_original = false; if (ss->cache->original) { unode = sculpt_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS); use_original = (unode->co || unode->bm_entry); } SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); /* when the mesh is edited we can't rely on original coords * (original mesh may not even have verts in brush radius) */ if (use_original && data->has_bm_orco) { float(*orco_coords)[3]; int(*orco_tris)[3]; int orco_tris_num; int i; BKE_pbvh_node_get_bm_orco_data(data->nodes[n], &orco_tris, &orco_tris_num, &orco_coords); for (i = 0; i < orco_tris_num; i++) { const float *co_tri[3] = { orco_coords[orco_tris[i][0]], orco_coords[orco_tris[i][1]], orco_coords[orco_tris[i][2]], }; float co[3]; closest_on_tri_to_point_v3(co, test.location, UNPACK3(co_tri)); if (sculpt_brush_test_sq_fn(&test, co)) { float no[3]; int flip_index; normal_tri_v3(no, UNPACK3(co_tri)); flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f); if (area_cos) { add_v3_v3(private_co[flip_index], co); } if (area_nos) { add_v3_v3(private_no[flip_index], no); } private_count[flip_index] += 1; } } } else { BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { const float *co; const short *no_s; /* bm_vert only */ if (use_original) { if (unode->bm_entry) { BM_log_original_vert_data(ss->bm_log, vd.bm_vert, &co, &no_s); } else { co = unode->co[vd.i]; no_s = unode->no[vd.i]; } } else { co = vd.co; } if (sculpt_brush_test_sq_fn(&test, co)) { float no_buf[3]; const float *no; int flip_index; if (use_original) { normal_short_to_float_v3(no_buf, no_s); no = no_buf; } else { if (vd.no) { normal_short_to_float_v3(no_buf, vd.no); no = no_buf; } else { no = vd.fno; } } flip_index = (dot_v3v3(ss->cache->view_normal, no) <= 0.0f); if (area_cos) { add_v3_v3(private_co[flip_index], co); } if (area_nos) { add_v3_v3(private_no[flip_index], no); } private_count[flip_index] += 1; } } BKE_pbvh_vertex_iter_end; } BLI_mutex_lock(&data->mutex); /* for flatten center */ if (area_cos) { add_v3_v3(area_cos[0], private_co[0]); add_v3_v3(area_cos[1], private_co[1]); } /* for area normal */ if (area_nos) { add_v3_v3(area_nos[0], private_no[0]); add_v3_v3(area_nos[1], private_no[1]); } /* weights */ data->count[0] += private_count[0]; data->count[1] += private_count[1]; BLI_mutex_unlock(&data->mutex); } static void calc_area_center( Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_co[3]) { const Brush *brush = BKE_paint_brush(&sd->paint); SculptSession *ss = ob->sculpt; const bool has_bm_orco = ss->bm && sculpt_stroke_is_dynamic_topology(ss, brush); int n; /* 0=towards view, 1=flipped */ float area_cos[2][3] = {{0.0f}}; int count[2] = {0}; /* Intentionally set 'sd' to NULL since we share logic with vertex paint. */ SculptThreadedTaskData data = { .sd = NULL, .ob = ob, .brush = brush, .nodes = nodes, .totnode = totnode, .has_bm_orco = has_bm_orco, .area_cos = area_cos, .area_nos = NULL, .count = count, }; BLI_mutex_init(&data.mutex); ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); BLI_mutex_end(&data.mutex); /* for flatten center */ for (n = 0; n < ARRAY_SIZE(area_cos); n++) { if (count[n] != 0) { mul_v3_v3fl(r_area_co, area_cos[n], 1.0f / count[n]); break; } } if (n == 2) { zero_v3(r_area_co); } } static void calc_area_normal( Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3]) { const Brush *brush = BKE_paint_brush(&sd->paint); bool use_threading = (sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT; sculpt_pbvh_calc_area_normal(brush, ob, nodes, totnode, use_threading, r_area_no); } /* expose 'calc_area_normal' externally. */ void sculpt_pbvh_calc_area_normal(const Brush *brush, Object *ob, PBVHNode **nodes, int totnode, bool use_threading, float r_area_no[3]) { SculptSession *ss = ob->sculpt; const bool has_bm_orco = ss->bm && sculpt_stroke_is_dynamic_topology(ss, brush); /* 0=towards view, 1=flipped */ float area_nos[2][3] = {{0.0f}}; int count[2] = {0}; /* Intentionally set 'sd' to NULL since this is used for vertex paint too. */ SculptThreadedTaskData data = { .sd = NULL, .ob = ob, .brush = brush, .nodes = nodes, .totnode = totnode, .has_bm_orco = has_bm_orco, .area_cos = NULL, .area_nos = area_nos, .count = count, }; BLI_mutex_init(&data.mutex); ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = use_threading; BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); BLI_mutex_end(&data.mutex); /* for area normal */ for (int i = 0; i < ARRAY_SIZE(area_nos); i++) { if (normalize_v3_v3(r_area_no, area_nos[i]) != 0.0f) { break; } } } /* this calculates flatten center and area normal together, * amortizing the memory bandwidth and loop overhead to calculate both at the same time */ static void calc_area_normal_and_center( Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3]) { const Brush *brush = BKE_paint_brush(&sd->paint); SculptSession *ss = ob->sculpt; const bool has_bm_orco = ss->bm && sculpt_stroke_is_dynamic_topology(ss, brush); int n; /* 0=towards view, 1=flipped */ float area_cos[2][3] = {{0.0f}}; float area_nos[2][3] = {{0.0f}}; int count[2] = {0}; /* Intentionally set 'sd' to NULL since this is used for vertex paint too. */ SculptThreadedTaskData data = { .sd = NULL, .ob = ob, .brush = brush, .nodes = nodes, .totnode = totnode, .has_bm_orco = has_bm_orco, .area_cos = area_cos, .area_nos = area_nos, .count = count, }; BLI_mutex_init(&data.mutex); ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); BLI_mutex_end(&data.mutex); /* for flatten center */ for (n = 0; n < ARRAY_SIZE(area_cos); n++) { if (count[n] != 0) { mul_v3_v3fl(r_area_co, area_cos[n], 1.0f / count[n]); break; } } if (n == 2) { zero_v3(r_area_co); } /* for area normal */ for (n = 0; n < ARRAY_SIZE(area_nos); n++) { if (normalize_v3_v3(r_area_no, area_nos[n]) != 0.0f) { break; } } } /** \} */ /* Return modified brush strength. Includes the direction of the brush, positive * values pull vertices, negative values push. Uses tablet pressure and a * special multiplier found experimentally to scale the strength factor. */ static float brush_strength(const Sculpt *sd, const StrokeCache *cache, const float feather, const UnifiedPaintSettings *ups) { const Scene *scene = cache->vc->scene; const Brush *brush = BKE_paint_brush((Paint *)&sd->paint); /* Primary strength input; square it to make lower values more sensitive */ const float root_alpha = BKE_brush_alpha_get(scene, brush); float alpha = root_alpha * root_alpha; float dir = (brush->flag & BRUSH_DIR_IN) ? -1 : 1; float pressure = BKE_brush_use_alpha_pressure(scene, brush) ? cache->pressure : 1; float pen_flip = cache->pen_flip ? -1 : 1; float invert = cache->invert ? -1 : 1; float overlap = ups->overlap_factor; /* spacing is integer percentage of radius, divide by 50 to get * normalized diameter */ float flip = dir * invert * pen_flip; switch (brush->sculpt_tool) { case SCULPT_TOOL_CLAY: case SCULPT_TOOL_CLAY_STRIPS: case SCULPT_TOOL_DRAW: case SCULPT_TOOL_LAYER: return alpha * flip * pressure * overlap * feather; case SCULPT_TOOL_MASK: overlap = (1 + overlap) / 2; switch ((BrushMaskTool)brush->mask_tool) { case BRUSH_MASK_DRAW: return alpha * flip * pressure * overlap * feather; case BRUSH_MASK_SMOOTH: return alpha * pressure * feather; } BLI_assert(!"Not supposed to happen"); return 0.0f; case SCULPT_TOOL_CREASE: case SCULPT_TOOL_BLOB: return alpha * flip * pressure * overlap * feather; case SCULPT_TOOL_INFLATE: if (flip > 0) { return 0.250f * alpha * flip * pressure * overlap * feather; } else { return 0.125f * alpha * flip * pressure * overlap * feather; } case SCULPT_TOOL_FILL: case SCULPT_TOOL_SCRAPE: case SCULPT_TOOL_FLATTEN: if (flip > 0) { overlap = (1 + overlap) / 2; return alpha * flip * pressure * overlap * feather; } else { /* reduce strength for DEEPEN, PEAKS, and CONTRAST */ return 0.5f * alpha * flip * pressure * overlap * feather; } case SCULPT_TOOL_SMOOTH: return alpha * pressure * feather; case SCULPT_TOOL_PINCH: if (flip > 0) { return alpha * flip * pressure * overlap * feather; } else { return 0.25f * alpha * flip * pressure * overlap * feather; } case SCULPT_TOOL_NUDGE: overlap = (1 + overlap) / 2; return alpha * pressure * overlap * feather; case SCULPT_TOOL_THUMB: return alpha * pressure * feather; case SCULPT_TOOL_SNAKE_HOOK: return root_alpha * feather; case SCULPT_TOOL_GRAB: return root_alpha * feather; case SCULPT_TOOL_ROTATE: return alpha * pressure * feather; default: return 0; } } /* Return a multiplier for brush strength on a particular vertex. */ float tex_strength(SculptSession *ss, const Brush *br, const float brush_point[3], const float len, const short vno[3], const float fno[3], const float mask, const int thread_id) { StrokeCache *cache = ss->cache; const Scene *scene = cache->vc->scene; const MTex *mtex = &br->mtex; float avg = 1; float rgba[4]; float point[3]; sub_v3_v3v3(point, brush_point, cache->plane_offset); if (!mtex->tex) { avg = 1; } else if (mtex->brush_map_mode == MTEX_MAP_MODE_3D) { /* Get strength by feeding the vertex * location directly into a texture */ avg = BKE_brush_sample_tex_3d(scene, br, point, rgba, 0, ss->tex_pool); } else if (ss->texcache) { float symm_point[3], point_2d[2]; float x = 0.0f, y = 0.0f; /* Quite warnings */ /* if the active area is being applied for symmetry, flip it * across the symmetry axis and rotate it back to the original * position in order to project it. This insures that the * brush texture will be oriented correctly. */ flip_v3_v3(symm_point, point, cache->mirror_symmetry_pass); if (cache->radial_symmetry_pass) { mul_m4_v3(cache->symm_rot_mat_inv, symm_point); } ED_view3d_project_float_v2_m4(cache->vc->ar, symm_point, point_2d, cache->projection_mat); /* still no symmetry supported for other paint modes. * Sculpt does it DIY */ if (mtex->brush_map_mode == MTEX_MAP_MODE_AREA) { /* Similar to fixed mode, but projects from brush angle * rather than view direction */ mul_m4_v3(cache->brush_local_mat, symm_point); x = symm_point[0]; y = symm_point[1]; x *= br->mtex.size[0]; y *= br->mtex.size[1]; x += br->mtex.ofs[0]; y += br->mtex.ofs[1]; avg = paint_get_tex_pixel(&br->mtex, x, y, ss->tex_pool, thread_id); avg += br->texture_sample_bias; } else { const float point_3d[3] = {point_2d[0], point_2d[1], 0.0f}; avg = BKE_brush_sample_tex_3d(scene, br, point_3d, rgba, 0, ss->tex_pool); } } /* Falloff curve */ avg *= BKE_brush_curve_strength(br, len, cache->radius); avg *= frontface(br, cache->view_normal, vno, fno); /* Paint mask */ avg *= 1.0f - mask; return avg; } /* Test AABB against sphere */ bool sculpt_search_sphere_cb(PBVHNode *node, void *data_v) { SculptSearchSphereData *data = data_v; float *center = data->ss->cache->location, nearest[3]; float t[3], bb_min[3], bb_max[3]; int i; if (data->original) { BKE_pbvh_node_get_original_BB(node, bb_min, bb_max); } else { BKE_pbvh_node_get_BB(node, bb_min, bb_max); } for (i = 0; i < 3; ++i) { if (bb_min[i] > center[i]) { nearest[i] = bb_min[i]; } else if (bb_max[i] < center[i]) { nearest[i] = bb_max[i]; } else { nearest[i] = center[i]; } } sub_v3_v3v3(t, center, nearest); return len_squared_v3(t) < data->radius_squared; } /* 2D projection (distance to line). */ bool sculpt_search_circle_cb(PBVHNode *node, void *data_v) { SculptSearchCircleData *data = data_v; float bb_min[3], bb_max[3]; if (data->original) { BKE_pbvh_node_get_original_BB(node, bb_min, bb_max); } else { BKE_pbvh_node_get_BB(node, bb_min, bb_min); } float dummy_co[3], dummy_depth; const float dist_sq = dist_squared_ray_to_aabb_v3( data->dist_ray_to_aabb_precalc, bb_min, bb_max, dummy_co, &dummy_depth); return dist_sq < data->radius_squared || 1; } /* Handles clipping against a mirror modifier and SCULPT_LOCK axis flags */ static void sculpt_clip(Sculpt *sd, SculptSession *ss, float co[3], const float val[3]) { int i; for (i = 0; i < 3; ++i) { if (sd->flags & (SCULPT_LOCK_X << i)) { continue; } if ((ss->cache->flag & (CLIP_X << i)) && (fabsf(co[i]) <= ss->cache->clip_tolerance[i])) { co[i] = 0.0f; } else { co[i] = val[i]; } } } static PBVHNode **sculpt_pbvh_gather_generic(Object *ob, Sculpt *sd, const Brush *brush, bool use_original, float radius_scale, int *r_totnode) { SculptSession *ss = ob->sculpt; PBVHNode **nodes = NULL; /* Build a list of all nodes that are potentially within the brush's area of influence */ if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) { SculptSearchSphereData data = { .ss = ss, .sd = sd, .radius_squared = SQUARE(ss->cache->radius * radius_scale), .original = use_original, }; BKE_pbvh_search_gather(ss->pbvh, sculpt_search_sphere_cb, &data, &nodes, r_totnode); } else { struct DistRayAABB_Precalc dist_ray_to_aabb_precalc; dist_squared_ray_to_aabb_v3_precalc( &dist_ray_to_aabb_precalc, ss->cache->location, ss->cache->view_normal); SculptSearchCircleData data = { .ss = ss, .sd = sd, .radius_squared = SQUARE(ss->cache->radius * radius_scale), .original = use_original, .dist_ray_to_aabb_precalc = &dist_ray_to_aabb_precalc, }; BKE_pbvh_search_gather(ss->pbvh, sculpt_search_circle_cb, &data, &nodes, r_totnode); } return nodes; } /* Calculate primary direction of movement for many brushes */ static void calc_sculpt_normal( Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3]) { const Brush *brush = BKE_paint_brush(&sd->paint); const SculptSession *ss = ob->sculpt; switch (brush->sculpt_plane) { case SCULPT_DISP_DIR_VIEW: copy_v3_v3(r_area_no, ss->cache->true_view_normal); break; case SCULPT_DISP_DIR_X: ARRAY_SET_ITEMS(r_area_no, 1, 0, 0); break; case SCULPT_DISP_DIR_Y: ARRAY_SET_ITEMS(r_area_no, 0, 1, 0); break; case SCULPT_DISP_DIR_Z: ARRAY_SET_ITEMS(r_area_no, 0, 0, 1); break; case SCULPT_DISP_DIR_AREA: calc_area_normal(sd, ob, nodes, totnode, r_area_no); break; default: break; } } static void update_sculpt_normal(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { const Brush *brush = BKE_paint_brush(&sd->paint); StrokeCache *cache = ob->sculpt->cache; if (cache->mirror_symmetry_pass == 0 && cache->radial_symmetry_pass == 0 && (cache->first_time || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) { calc_sculpt_normal(sd, ob, nodes, totnode, cache->sculpt_normal); if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { project_plane_v3_v3v3(cache->sculpt_normal, cache->sculpt_normal, cache->view_normal); normalize_v3(cache->sculpt_normal); } copy_v3_v3(cache->sculpt_normal_symm, cache->sculpt_normal); } else { copy_v3_v3(cache->sculpt_normal_symm, cache->sculpt_normal); flip_v3(cache->sculpt_normal_symm, cache->mirror_symmetry_pass); mul_m4_v3(cache->symm_rot_mat, cache->sculpt_normal_symm); } } static void calc_local_y(ViewContext *vc, const float center[3], float y[3]) { Object *ob = vc->obact; float loc[3], mval_f[2] = {0.0f, 1.0f}; float zfac; mul_v3_m4v3(loc, ob->imat, center); zfac = ED_view3d_calc_zfac(vc->rv3d, loc, NULL); ED_view3d_win_to_delta(vc->ar, mval_f, y, zfac); normalize_v3(y); add_v3_v3(y, ob->loc); mul_m4_v3(ob->imat, y); } static void calc_brush_local_mat(const Brush *brush, Object *ob, float local_mat[4][4]) { const StrokeCache *cache = ob->sculpt->cache; float tmat[4][4]; float mat[4][4]; float scale[4][4]; float angle, v[3]; float up[3]; /* Ensure ob->imat is up to date */ invert_m4_m4(ob->imat, ob->obmat); /* Initialize last column of matrix */ mat[0][3] = 0; mat[1][3] = 0; mat[2][3] = 0; mat[3][3] = 1; /* Get view's up vector in object-space */ calc_local_y(cache->vc, cache->location, up); /* Calculate the X axis of the local matrix */ cross_v3_v3v3(v, up, cache->sculpt_normal); /* Apply rotation (user angle, rake, etc.) to X axis */ angle = brush->mtex.rot - cache->special_rotation; rotate_v3_v3v3fl(mat[0], v, cache->sculpt_normal, angle); /* Get other axes */ cross_v3_v3v3(mat[1], cache->sculpt_normal, mat[0]); copy_v3_v3(mat[2], cache->sculpt_normal); /* Set location */ copy_v3_v3(mat[3], cache->location); /* Scale by brush radius */ normalize_m4(mat); scale_m4_fl(scale, cache->radius); mul_m4_m4m4(tmat, mat, scale); /* Return inverse (for converting from modelspace coords to local * area coords) */ invert_m4_m4(local_mat, tmat); } static void update_brush_local_mat(Sculpt *sd, Object *ob) { StrokeCache *cache = ob->sculpt->cache; if (cache->mirror_symmetry_pass == 0 && cache->radial_symmetry_pass == 0) { calc_brush_local_mat(BKE_paint_brush(&sd->paint), ob, cache->brush_local_mat); } } /* For the smooth brush, uses the neighboring vertices around vert to calculate * a smoothed location for vert. Skips corner vertices (used by only one * polygon.) */ static void neighbor_average(SculptSession *ss, float avg[3], unsigned vert) { const MeshElemMap *vert_map = &ss->pmap[vert]; const MVert *mvert = ss->mvert; float(*deform_co)[3] = ss->deform_cos; /* Don't modify corner vertices */ if (vert_map->count > 1) { int i, total = 0; zero_v3(avg); for (i = 0; i < vert_map->count; i++) { const MPoly *p = &ss->mpoly[vert_map->indices[i]]; unsigned f_adj_v[2]; if (poly_get_adj_loops_from_vert(p, ss->mloop, vert, f_adj_v) != -1) { int j; for (j = 0; j < ARRAY_SIZE(f_adj_v); j += 1) { if (vert_map->count != 2 || ss->pmap[f_adj_v[j]].count <= 2) { add_v3_v3(avg, deform_co ? deform_co[f_adj_v[j]] : mvert[f_adj_v[j]].co); total++; } } } } if (total > 0) { mul_v3_fl(avg, 1.0f / total); return; } } copy_v3_v3(avg, deform_co ? deform_co[vert] : mvert[vert].co); } /* Similar to neighbor_average(), but returns an averaged mask value * instead of coordinate. Also does not restrict based on border or * corner vertices. */ static float neighbor_average_mask(SculptSession *ss, unsigned vert) { const float *vmask = ss->vmask; float avg = 0; int i, total = 0; for (i = 0; i < ss->pmap[vert].count; i++) { const MPoly *p = &ss->mpoly[ss->pmap[vert].indices[i]]; unsigned f_adj_v[2]; if (poly_get_adj_loops_from_vert(p, ss->mloop, vert, f_adj_v) != -1) { int j; for (j = 0; j < ARRAY_SIZE(f_adj_v); j += 1) { avg += vmask[f_adj_v[j]]; total++; } } } if (total > 0) { return avg / (float)total; } else { return vmask[vert]; } } /* Same logic as neighbor_average(), but for bmesh rather than mesh */ static void bmesh_neighbor_average(float avg[3], BMVert *v) { /* logic for 3 or more is identical */ const int vfcount = BM_vert_face_count_at_most(v, 3); /* Don't modify corner vertices */ if (vfcount > 1) { BMIter liter; BMLoop *l; int i, total = 0; zero_v3(avg); BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) { const BMVert *adj_v[2] = {l->prev->v, l->next->v}; for (i = 0; i < ARRAY_SIZE(adj_v); i++) { const BMVert *v_other = adj_v[i]; if (vfcount != 2 || BM_vert_face_count_at_most(v_other, 2) <= 2) { add_v3_v3(avg, v_other->co); total++; } } } if (total > 0) { mul_v3_fl(avg, 1.0f / total); return; } } copy_v3_v3(avg, v->co); } /* For bmesh: average only the four most aligned (parallel and perpendicular) edges * relative to a direction. Naturally converges to a quad-like tessellation. */ static void bmesh_four_neighbor_average(float avg[3], float direction[3], BMVert *v) { /* Logic for 3 or more is identical. */ const int vfcount = BM_vert_face_count_at_most(v, 3); /* Don't modify corner vertices. */ if (vfcount < 2) { copy_v3_v3(avg, v->co); return; } /* Project the direction to the vertex normal and create an additional * parallel vector. */ float dir_a[3], dir_b[3]; cross_v3_v3v3(dir_a, direction, v->no); cross_v3_v3v3(dir_b, dir_a, v->no); /* The four vectors which will be used for smoothing. * Occasionally less than 4 verts match the requirements in that case * use 'v' as fallback. */ BMVert *pos_a = v; BMVert *neg_a = v; BMVert *pos_b = v; BMVert *neg_b = v; float pos_score_a = 0.0f; float neg_score_a = 0.0f; float pos_score_b = 0.0f; float neg_score_b = 0.0f; BMIter liter; BMLoop *l; BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) { BMVert *adj_v[2] = {l->prev->v, l->next->v}; for (int i = 0; i < ARRAY_SIZE(adj_v); i++) { BMVert *v_other = adj_v[i]; if (vfcount != 2 || BM_vert_face_count_at_most(v_other, 2) <= 2) { float vec[3]; sub_v3_v3v3(vec, v_other->co, v->co); normalize_v3(vec); /* The score is a measure of how orthogonal the edge is. */ float score = dot_v3v3(vec, dir_a); if (score >= pos_score_a) { pos_a = v_other; pos_score_a = score; } else if (score < neg_score_a) { neg_a = v_other; neg_score_a = score; } /* The same scoring but for the perpendicular direction. */ score = dot_v3v3(vec, dir_b); if (score >= pos_score_b) { pos_b = v_other; pos_score_b = score; } else if (score < neg_score_b) { neg_b = v_other; neg_score_b = score; } } } } /* Average everything together. */ zero_v3(avg); add_v3_v3(avg, pos_a->co); add_v3_v3(avg, neg_a->co); add_v3_v3(avg, pos_b->co); add_v3_v3(avg, neg_b->co); mul_v3_fl(avg, 0.25f); /* Preserve volume. */ float vec[3]; sub_v3_v3(avg, v->co); mul_v3_v3fl(vec, v->no, dot_v3v3(avg, v->no)); sub_v3_v3(avg, vec); add_v3_v3(avg, v->co); } /* Same logic as neighbor_average_mask(), but for bmesh rather than mesh */ static float bmesh_neighbor_average_mask(BMVert *v, const int cd_vert_mask_offset) { BMIter liter; BMLoop *l; float avg = 0; int i, total = 0; BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) { /* skip this vertex */ const BMVert *adj_v[2] = {l->prev->v, l->next->v}; for (i = 0; i < ARRAY_SIZE(adj_v); i++) { const BMVert *v_other = adj_v[i]; const float *vmask = BM_ELEM_CD_GET_VOID_P(v_other, cd_vert_mask_offset); avg += (*vmask); total++; } } if (total > 0) { return avg / (float)total; } else { const float *vmask = BM_ELEM_CD_GET_VOID_P(v, cd_vert_mask_offset); return (*vmask); } } /* Note: uses after-struct allocated mem to store actual cache... */ typedef struct SculptDoBrushSmoothGridDataChunk { size_t tmpgrid_size; } SculptDoBrushSmoothGridDataChunk; typedef struct { SculptSession *ss; const float *ray_start, *ray_normal; bool hit; float depth; bool original; } SculptRaycastData; typedef struct { const float *ray_start, *ray_normal; bool hit; float depth; float edge_length; } SculptDetailRaycastData; typedef struct { SculptSession *ss; const float *ray_start, *ray_normal; bool hit; float depth; float dist_sq_to_ray; bool original; } SculptFindNearestToRayData; static void do_smooth_brush_mesh_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; const Brush *brush = data->brush; const bool smooth_mask = data->smooth_mask; float bstrength = data->strength; PBVHVertexIter vd; CLAMP(bstrength, 0.0f, 1.0f); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, smooth_mask ? 0.0f : (vd.mask ? *vd.mask : 0.0f), tls->thread_id); if (smooth_mask) { float val = neighbor_average_mask(ss, vd.vert_indices[vd.i]) - *vd.mask; val *= fade * bstrength; *vd.mask += val; CLAMP(*vd.mask, 0.0f, 1.0f); } else { float avg[3], val[3]; neighbor_average(ss, avg, vd.vert_indices[vd.i]); sub_v3_v3v3(val, avg, vd.co); madd_v3_v3v3fl(val, vd.co, val, fade); sculpt_clip(sd, ss, vd.co, val); } if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_smooth_brush_bmesh_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; const Brush *brush = data->brush; const bool smooth_mask = data->smooth_mask; float bstrength = data->strength; PBVHVertexIter vd; CLAMP(bstrength, 0.0f, 1.0f); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, smooth_mask ? 0.0f : *vd.mask, tls->thread_id); if (smooth_mask) { float val = bmesh_neighbor_average_mask(vd.bm_vert, vd.cd_vert_mask_offset) - *vd.mask; val *= fade * bstrength; *vd.mask += val; CLAMP(*vd.mask, 0.0f, 1.0f); } else { float avg[3], val[3]; bmesh_neighbor_average(avg, vd.bm_vert); sub_v3_v3v3(val, avg, vd.co); madd_v3_v3v3fl(val, vd.co, val, fade); sculpt_clip(sd, ss, vd.co, val); } if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; const Brush *brush = data->brush; float direction[3]; copy_v3_v3(direction, ss->cache->grab_delta_symmetry); float tmp[3]; mul_v3_v3fl( tmp, ss->cache->sculpt_normal_symm, dot_v3v3(ss->cache->sculpt_normal_symm, direction)); sub_v3_v3(direction, tmp); /* Cancel if there's no grab data. */ if (is_zero_v3(direction)) { return; } float bstrength = data->strength; CLAMP(bstrength, 0.0f, 1.0f); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { const float fade = bstrength * tex_strength( ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, *vd.mask, tls->thread_id) * ss->cache->pressure; float avg[3], val[3]; bmesh_four_neighbor_average(avg, direction, vd.bm_vert); sub_v3_v3v3(val, avg, vd.co); madd_v3_v3v3fl(val, vd.co, val, fade); sculpt_clip(sd, ss, vd.co, val); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_smooth_brush_multires_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptDoBrushSmoothGridDataChunk *data_chunk = tls->userdata_chunk; SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; const Brush *brush = data->brush; const bool smooth_mask = data->smooth_mask; float bstrength = data->strength; CCGElem **griddata, *gddata; CCGKey key; float(*tmpgrid_co)[3] = NULL; float tmprow_co[2][3]; float *tmpgrid_mask = NULL; float tmprow_mask[2]; BLI_bitmap *const *grid_hidden; int *grid_indices, totgrid, gridsize; int i, x, y; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); CLAMP(bstrength, 0.0f, 1.0f); BKE_pbvh_node_get_grids( ss->pbvh, data->nodes[n], &grid_indices, &totgrid, NULL, &gridsize, &griddata); BKE_pbvh_get_grid_key(ss->pbvh, &key); grid_hidden = BKE_pbvh_grid_hidden(ss->pbvh); if (smooth_mask) { tmpgrid_mask = (void *)(data_chunk + 1); } else { tmpgrid_co = (void *)(data_chunk + 1); } for (i = 0; i < totgrid; i++) { int gi = grid_indices[i]; const BLI_bitmap *gh = grid_hidden[gi]; gddata = griddata[gi]; if (smooth_mask) { memset(tmpgrid_mask, 0, data_chunk->tmpgrid_size); } else { memset(tmpgrid_co, 0, data_chunk->tmpgrid_size); } for (y = 0; y < gridsize - 1; y++) { const int v = y * gridsize; if (smooth_mask) { tmprow_mask[0] = (*CCG_elem_offset_mask(&key, gddata, v) + *CCG_elem_offset_mask(&key, gddata, v + gridsize)); } else { add_v3_v3v3(tmprow_co[0], CCG_elem_offset_co(&key, gddata, v), CCG_elem_offset_co(&key, gddata, v + gridsize)); } for (x = 0; x < gridsize - 1; x++) { const int v1 = x + y * gridsize; const int v2 = v1 + 1; const int v3 = v1 + gridsize; const int v4 = v3 + 1; if (smooth_mask) { float tmp; tmprow_mask[(x + 1) % 2] = (*CCG_elem_offset_mask(&key, gddata, v2) + *CCG_elem_offset_mask(&key, gddata, v4)); tmp = tmprow_mask[(x + 1) % 2] + tmprow_mask[x % 2]; tmpgrid_mask[v1] += tmp; tmpgrid_mask[v2] += tmp; tmpgrid_mask[v3] += tmp; tmpgrid_mask[v4] += tmp; } else { float tmp[3]; add_v3_v3v3(tmprow_co[(x + 1) % 2], CCG_elem_offset_co(&key, gddata, v2), CCG_elem_offset_co(&key, gddata, v4)); add_v3_v3v3(tmp, tmprow_co[(x + 1) % 2], tmprow_co[x % 2]); add_v3_v3(tmpgrid_co[v1], tmp); add_v3_v3(tmpgrid_co[v2], tmp); add_v3_v3(tmpgrid_co[v3], tmp); add_v3_v3(tmpgrid_co[v4], tmp); } } } /* blend with existing coordinates */ for (y = 0; y < gridsize; y++) { for (x = 0; x < gridsize; x++) { float *co; const float *fno; float *mask; const int index = y * gridsize + x; if (gh) { if (BLI_BITMAP_TEST(gh, index)) { continue; } } co = CCG_elem_offset_co(&key, gddata, index); fno = CCG_elem_offset_no(&key, gddata, index); mask = CCG_elem_offset_mask(&key, gddata, index); if (sculpt_brush_test_sq_fn(&test, co)) { const float strength_mask = (smooth_mask ? 0.0f : *mask); const float fade = bstrength * tex_strength( ss, brush, co, sqrtf(test.dist), NULL, fno, strength_mask, tls->thread_id); float f = 1.0f / 16.0f; if (x == 0 || x == gridsize - 1) { f *= 2.0f; } if (y == 0 || y == gridsize - 1) { f *= 2.0f; } if (smooth_mask) { *mask += ((tmpgrid_mask[index] * f) - *mask) * fade; } else { float *avg = tmpgrid_co[index]; float val[3]; mul_v3_fl(avg, f); sub_v3_v3v3(val, avg, co); madd_v3_v3v3fl(val, co, val, fade); sculpt_clip(sd, ss, co, val); } } } } } } static void smooth(Sculpt *sd, Object *ob, PBVHNode **nodes, const int totnode, float bstrength, const bool smooth_mask) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); const int max_iterations = 4; const float fract = 1.0f / max_iterations; PBVHType type = BKE_pbvh_type(ss->pbvh); int iteration, count; float last; CLAMP(bstrength, 0.0f, 1.0f); count = (int)(bstrength * max_iterations); last = max_iterations * (bstrength - count * fract); if (type == PBVH_FACES && !ss->pmap) { BLI_assert(!"sculpt smooth: pmap missing"); return; } for (iteration = 0; iteration <= count; ++iteration) { const float strength = (iteration != count) ? 1.0f : last; SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .smooth_mask = smooth_mask, .strength = strength, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); switch (type) { case PBVH_GRIDS: { int gridsize; size_t size; SculptDoBrushSmoothGridDataChunk *data_chunk; BKE_pbvh_node_get_grids(ss->pbvh, NULL, NULL, NULL, NULL, &gridsize, NULL); size = (size_t)gridsize; size = sizeof(float) * size * size * (smooth_mask ? 1 : 3); data_chunk = MEM_mallocN(sizeof(*data_chunk) + size, __func__); data_chunk->tmpgrid_size = size; size += sizeof(*data_chunk); settings.userdata_chunk = data_chunk; settings.userdata_chunk_size = size; BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_multires_task_cb_ex, &settings); MEM_freeN(data_chunk); break; } case PBVH_FACES: BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_mesh_task_cb_ex, &settings); break; case PBVH_BMESH: BLI_task_parallel_range(0, totnode, &data, do_smooth_brush_bmesh_task_cb_ex, &settings); break; } if (ss->multires) { multires_stitch_grids(ob); } } } static void bmesh_topology_rake( Sculpt *sd, Object *ob, PBVHNode **nodes, const int totnode, float bstrength) { Brush *brush = BKE_paint_brush(&sd->paint); CLAMP(bstrength, 0.0f, 1.0f); /* Interactions increase both strength and quality. */ const int iterations = 3; int iteration; const int count = iterations * bstrength + 1; const float factor = iterations * bstrength / count; for (iteration = 0; iteration <= count; ++iteration) { SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .strength = factor, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_topology_rake_bmesh_task_cb_ex, &settings); } } static void do_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; smooth(sd, ob, nodes, totnode, ss->cache->bstrength, false); } static void do_mask_brush_draw_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float bstrength = ss->cache->bstrength; PBVHVertexIter vd; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { const float fade = tex_strength( ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, 0.0f, tls->thread_id); (*vd.mask) += fade * bstrength; CLAMP(*vd.mask, 0, 1); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } BKE_pbvh_vertex_iter_end; } } static void do_mask_brush_draw(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { Brush *brush = BKE_paint_brush(&sd->paint); /* threaded loop over nodes */ SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_mask_brush_draw_task_cb_ex, &settings); } static void do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); switch ((BrushMaskTool)brush->mask_tool) { case BRUSH_MASK_DRAW: do_mask_brush_draw(sd, ob, nodes, totnode); break; case BRUSH_MASK_SMOOTH: smooth(sd, ob, nodes, totnode, ss->cache->bstrength, true); break; } } static void do_draw_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *offset = data->offset; PBVHVertexIter vd; float(*proxy)[3]; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { /* offset vertex */ const float fade = tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], offset, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); float offset[3]; const float bstrength = ss->cache->bstrength; /* offset with as much as possible factored in already */ mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius); mul_v3_v3(offset, ss->cache->scale); mul_v3_fl(offset, bstrength); /* XXX - this shouldn't be necessary, but sculpting crashes in blender2.8 otherwise * initialize before threads so they can do curve mapping */ curvemapping_initialize(brush->curve); /* threaded loop over nodes */ SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .offset = offset, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_draw_brush_task_cb_ex, &settings); } /** * Used for 'SCULPT_TOOL_CREASE' and 'SCULPT_TOOL_BLOB' */ static void do_crease_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; SculptProjectVector *spvc = data->spvc; const float flippedbstrength = data->flippedbstrength; const float *offset = data->offset; PBVHVertexIter vd; float(*proxy)[3]; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { /* offset vertex */ const float fade = tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); float val1[3]; float val2[3]; /* first we pinch */ sub_v3_v3v3(val1, test.location, vd.co); if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { project_plane_v3_v3v3(val1, val1, ss->cache->view_normal); } mul_v3_fl(val1, fade * flippedbstrength); sculpt_project_v3(spvc, val1, val1); /* then we draw */ mul_v3_v3fl(val2, offset, fade); add_v3_v3v3(proxy[vd.i], val1, val2); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; const Scene *scene = ss->cache->vc->scene; Brush *brush = BKE_paint_brush(&sd->paint); float offset[3]; float bstrength = ss->cache->bstrength; float flippedbstrength, crease_correction; float brush_alpha; SculptProjectVector spvc; /* offset with as much as possible factored in already */ mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius); mul_v3_v3(offset, ss->cache->scale); mul_v3_fl(offset, bstrength); /* We divide out the squared alpha and multiply by the squared crease * to give us the pinch strength. */ crease_correction = brush->crease_pinch_factor * brush->crease_pinch_factor; brush_alpha = BKE_brush_alpha_get(scene, brush); if (brush_alpha > 0.0f) { crease_correction /= brush_alpha * brush_alpha; } /* we always want crease to pinch or blob to relax even when draw is negative */ flippedbstrength = (bstrength < 0) ? -crease_correction * bstrength : crease_correction * bstrength; if (brush->sculpt_tool == SCULPT_TOOL_BLOB) { flippedbstrength *= -1.0f; } /* Use surface normal for 'spvc', * so the vertices are pinched towards a line instead of a single point. * Without this we get a 'flat' surface surrounding the pinch */ sculpt_project_v3_cache_init(&spvc, ss->cache->sculpt_normal_symm); /* threaded loop over nodes */ SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .spvc = &spvc, .offset = offset, .flippedbstrength = flippedbstrength, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_crease_brush_task_cb_ex, &settings); } static void do_pinch_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; PBVHVertexIter vd; float(*proxy)[3]; const float bstrength = ss->cache->bstrength; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); float val[3]; sub_v3_v3v3(val, test.location, vd.co); if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { project_plane_v3_v3v3(val, val, ss->cache->view_normal); } mul_v3_v3fl(proxy[vd.i], val, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { Brush *brush = BKE_paint_brush(&sd->paint); SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_pinch_brush_task_cb_ex, &settings); } static void do_grab_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *grab_delta = data->grab_delta; PBVHVertexIter vd; SculptOrigVertData orig_data; float(*proxy)[3]; const float bstrength = ss->cache->bstrength; sculpt_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { sculpt_orig_vert_data_update(&orig_data, &vd); if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { const float fade = bstrength * tex_strength(ss, brush, orig_data.co, sqrtf(test.dist), orig_data.no, NULL, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], grab_delta, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); float grab_delta[3]; copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); if (ss->cache->normal_weight > 0.0f) { sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta); } SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .grab_delta = grab_delta, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_grab_brush_task_cb_ex, &settings); } static void do_nudge_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *cono = data->cono; PBVHVertexIter vd; float(*proxy)[3]; const float bstrength = ss->cache->bstrength; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], cono, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); float grab_delta[3]; float tmp[3], cono[3]; copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); cross_v3_v3v3(tmp, ss->cache->sculpt_normal_symm, grab_delta); cross_v3_v3v3(cono, tmp, ss->cache->sculpt_normal_symm); SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .cono = cono, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_nudge_brush_task_cb_ex, &settings); } static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; SculptProjectVector *spvc = data->spvc; const float *grab_delta = data->grab_delta; PBVHVertexIter vd; float(*proxy)[3]; const float bstrength = ss->cache->bstrength; const bool do_rake_rotation = ss->cache->is_rake_rotation_valid; const bool do_pinch = (brush->crease_pinch_factor != 0.5f); const float pinch = do_pinch ? (2.0f * (0.5f - brush->crease_pinch_factor) * (len_v3(grab_delta) / ss->cache->radius)) : 0.0f; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], grab_delta, fade); /* negative pinch will inflate, helps maintain volume */ if (do_pinch) { float delta_pinch_init[3], delta_pinch[3]; sub_v3_v3v3(delta_pinch, vd.co, test.location); if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { project_plane_v3_v3v3(delta_pinch, delta_pinch, ss->cache->true_view_normal); } /* important to calculate based on the grabbed location * (intentionally ignore fade here). */ add_v3_v3(delta_pinch, grab_delta); sculpt_project_v3(spvc, delta_pinch, delta_pinch); copy_v3_v3(delta_pinch_init, delta_pinch); float pinch_fade = pinch * fade; /* when reducing, scale reduction back by how close to the center we are, * so we don't pinch into nothingness */ if (pinch > 0.0f) { /* square to have even less impact for close vertices */ pinch_fade *= pow2f(min_ff(1.0f, len_v3(delta_pinch) / ss->cache->radius)); } mul_v3_fl(delta_pinch, 1.0f + pinch_fade); sub_v3_v3v3(delta_pinch, delta_pinch_init, delta_pinch); add_v3_v3(proxy[vd.i], delta_pinch); } if (do_rake_rotation) { float delta_rotate[3]; sculpt_rake_rotate(ss, test.location, vd.co, fade, delta_rotate); add_v3_v3(proxy[vd.i], delta_rotate); } if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); const float bstrength = ss->cache->bstrength; float grab_delta[3]; SculptProjectVector spvc; copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); if (bstrength < 0) { negate_v3(grab_delta); } if (ss->cache->normal_weight > 0.0f) { sculpt_project_v3_normal_align(ss, ss->cache->normal_weight, grab_delta); } /* optionally pinch while painting */ if (brush->crease_pinch_factor != 0.5f) { sculpt_project_v3_cache_init(&spvc, grab_delta); } SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .spvc = &spvc, .grab_delta = grab_delta, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_snake_hook_brush_task_cb_ex, &settings); } static void do_thumb_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *cono = data->cono; PBVHVertexIter vd; SculptOrigVertData orig_data; float(*proxy)[3]; const float bstrength = ss->cache->bstrength; sculpt_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { sculpt_orig_vert_data_update(&orig_data, &vd); if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { const float fade = bstrength * tex_strength(ss, brush, orig_data.co, sqrtf(test.dist), orig_data.no, NULL, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], cono, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); float grab_delta[3]; float tmp[3], cono[3]; copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); cross_v3_v3v3(tmp, ss->cache->sculpt_normal_symm, grab_delta); cross_v3_v3v3(cono, tmp, ss->cache->sculpt_normal_symm); SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .cono = cono, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_thumb_brush_task_cb_ex, &settings); } static void do_rotate_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float angle = data->angle; PBVHVertexIter vd; SculptOrigVertData orig_data; float(*proxy)[3]; const float bstrength = ss->cache->bstrength; sculpt_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { sculpt_orig_vert_data_update(&orig_data, &vd); if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { float vec[3], rot[3][3]; const float fade = bstrength * tex_strength(ss, brush, orig_data.co, sqrtf(test.dist), orig_data.no, NULL, vd.mask ? *vd.mask : 0.0f, tls->thread_id); sub_v3_v3v3(vec, orig_data.co, ss->cache->location); axis_angle_normalized_to_mat3(rot, ss->cache->sculpt_normal_symm, angle * fade); mul_v3_m3v3(proxy[vd.i], rot, vec); add_v3_v3(proxy[vd.i], ss->cache->location); sub_v3_v3(proxy[vd.i], orig_data.co); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); static const int flip[8] = {1, -1, -1, 1, -1, 1, 1, -1}; const float angle = ss->cache->vertex_rotation * flip[ss->cache->mirror_symmetry_pass]; SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .angle = angle, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_rotate_brush_task_cb_ex, &settings); } static void do_layer_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; const Brush *brush = data->brush; const float *offset = data->offset; PBVHVertexIter vd; SculptOrigVertData orig_data; float *layer_disp; const float bstrength = ss->cache->bstrength; const float lim = (bstrength < 0) ? -data->brush->height : data->brush->height; /* XXX: layer brush needs conversion to proxy but its more complicated */ /* proxy = BKE_pbvh_node_add_proxy(ss->pbvh, nodes[n])->co; */ sculpt_orig_vert_data_init(&orig_data, data->ob, data->nodes[n]); /* Why does this have to be thread-protected? */ BLI_mutex_lock(&data->mutex); layer_disp = BKE_pbvh_node_layer_disp_get(ss->pbvh, data->nodes[n]); BLI_mutex_unlock(&data->mutex); SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { sculpt_orig_vert_data_update(&orig_data, &vd); if (sculpt_brush_test_sq_fn(&test, orig_data.co)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); float *disp = &layer_disp[vd.i]; float val[3]; *disp += fade; /* Don't let the displacement go past the limit */ if ((lim < 0.0f && *disp < lim) || (lim >= 0.0f && *disp > lim)) { *disp = lim; } mul_v3_v3fl(val, offset, *disp); if (!ss->multires && !ss->bm && ss->layer_co && (brush->flag & BRUSH_PERSISTENT)) { int index = vd.vert_indices[vd.i]; /* persistent base */ add_v3_v3(val, ss->layer_co[index]); } else { add_v3_v3(val, orig_data.co); } sculpt_clip(sd, ss, vd.co, val); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); float offset[3]; mul_v3_v3v3(offset, ss->cache->scale, ss->cache->sculpt_normal_symm); SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .offset = offset, }; BLI_mutex_init(&data.mutex); ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_layer_brush_task_cb_ex, &settings); BLI_mutex_end(&data.mutex); } static void do_inflate_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; PBVHVertexIter vd; float(*proxy)[3]; const float bstrength = ss->cache->bstrength; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); float val[3]; if (vd.fno) { copy_v3_v3(val, vd.fno); } else { normal_short_to_float_v3(val, vd.no); } mul_v3_fl(val, fade * ss->cache->radius); mul_v3_v3v3(proxy[vd.i], val, ss->cache->scale); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { Brush *brush = BKE_paint_brush(&sd->paint); SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_inflate_brush_task_cb_ex, &settings); } static void calc_sculpt_plane( Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float r_area_no[3], float r_area_co[3]) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); if (ss->cache->mirror_symmetry_pass == 0 && ss->cache->radial_symmetry_pass == 0 && ss->cache->tile_pass == 0 && (ss->cache->first_time || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) { switch (brush->sculpt_plane) { case SCULPT_DISP_DIR_VIEW: copy_v3_v3(r_area_no, ss->cache->true_view_normal); break; case SCULPT_DISP_DIR_X: ARRAY_SET_ITEMS(r_area_no, 1, 0, 0); break; case SCULPT_DISP_DIR_Y: ARRAY_SET_ITEMS(r_area_no, 0, 1, 0); break; case SCULPT_DISP_DIR_Z: ARRAY_SET_ITEMS(r_area_no, 0, 0, 1); break; case SCULPT_DISP_DIR_AREA: calc_area_normal_and_center(sd, ob, nodes, totnode, r_area_no, r_area_co); if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { project_plane_v3_v3v3(r_area_no, r_area_no, ss->cache->view_normal); normalize_v3(r_area_no); } break; default: break; } /* for flatten center */ /* flatten center has not been calculated yet if we are not using the area normal */ if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA) { calc_area_center(sd, ob, nodes, totnode, r_area_co); } /* for area normal */ copy_v3_v3(ss->cache->sculpt_normal, r_area_no); /* for flatten center */ copy_v3_v3(ss->cache->last_center, r_area_co); } else { /* for area normal */ copy_v3_v3(r_area_no, ss->cache->sculpt_normal); /* for flatten center */ copy_v3_v3(r_area_co, ss->cache->last_center); /* for area normal */ flip_v3(r_area_no, ss->cache->mirror_symmetry_pass); /* for flatten center */ flip_v3(r_area_co, ss->cache->mirror_symmetry_pass); /* for area normal */ mul_m4_v3(ss->cache->symm_rot_mat, r_area_no); /* for flatten center */ mul_m4_v3(ss->cache->symm_rot_mat, r_area_co); /* shift the plane for the current tile */ add_v3_v3(r_area_co, ss->cache->plane_offset); } } static int plane_trim(const StrokeCache *cache, const Brush *brush, const float val[3]) { return (!(brush->flag & BRUSH_PLANE_TRIM) || ((dot_v3v3(val, val) <= cache->radius_squared * cache->plane_trim_squared))); } static bool plane_point_side_flip(const float co[3], const float plane[4], const bool flip) { float d = plane_point_side_v3(plane, co); if (flip) { d = -d; } return d <= 0.0f; } static int plane_point_side(const float co[3], const float plane[4]) { float d = plane_point_side_v3(plane, co); return d <= 0.0f; } static float get_offset(Sculpt *sd, SculptSession *ss) { Brush *brush = BKE_paint_brush(&sd->paint); float rv = brush->plane_offset; if (brush->flag & BRUSH_OFFSET_PRESSURE) { rv *= ss->cache->pressure; } return rv; } static void do_flatten_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *area_no = data->area_no; const float *area_co = data->area_co; PBVHVertexIter vd; float(*proxy)[3]; const float bstrength = ss->cache->bstrength; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); plane_from_point_normal_v3(test.plane_tool, area_co, area_no); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { float intr[3]; float val[3]; closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); sub_v3_v3v3(val, intr, vd.co); if (plane_trim(ss->cache, brush, val)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], val, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } } BKE_pbvh_vertex_iter_end; } static void do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); const float radius = ss->cache->radius; float area_no[3]; float area_co[3]; float offset = get_offset(sd, ss); float displace; float temp[3]; calc_sculpt_plane(sd, ob, nodes, totnode, area_no, area_co); displace = radius * offset; mul_v3_v3v3(temp, area_no, ss->cache->scale); mul_v3_fl(temp, displace); add_v3_v3(area_co, temp); SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .area_no = area_no, .area_co = area_co, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_flatten_brush_task_cb_ex, &settings); } static void do_clay_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *area_no = data->area_no; const float *area_co = data->area_co; PBVHVertexIter vd; float(*proxy)[3]; const bool flip = (ss->cache->bstrength < 0); const float bstrength = flip ? -ss->cache->bstrength : ss->cache->bstrength; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); plane_from_point_normal_v3(test.plane_tool, area_co, area_no); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { if (plane_point_side_flip(vd.co, test.plane_tool, flip)) { float intr[3]; float val[3]; closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); sub_v3_v3v3(val, intr, vd.co); if (plane_trim(ss->cache, brush, val)) { /* note, the normal from the vertices is ignored, * causes glitch with planes, see: T44390 */ const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], val, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } } } BKE_pbvh_vertex_iter_end; } static void do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); const bool flip = (ss->cache->bstrength < 0); const float radius = flip ? -ss->cache->radius : ss->cache->radius; float offset = get_offset(sd, ss); float displace; float area_no[3]; float area_co[3]; float temp[3]; calc_sculpt_plane(sd, ob, nodes, totnode, area_no, area_co); displace = radius * (0.25f + offset); mul_v3_v3v3(temp, area_no, ss->cache->scale); mul_v3_fl(temp, displace); add_v3_v3(area_co, temp); /* add_v3_v3v3(p, ss->cache->location, area_no); */ SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .area_no = area_no, .area_co = area_co, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_clay_brush_task_cb_ex, &settings); } static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; float(*mat)[4] = data->mat; const float *area_no_sp = data->area_no_sp; const float *area_co = data->area_co; PBVHVertexIter vd; SculptBrushTest test; float(*proxy)[3]; const bool flip = (ss->cache->bstrength < 0); const float bstrength = flip ? -ss->cache->bstrength : ss->cache->bstrength; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; sculpt_brush_test_init(ss, &test); plane_from_point_normal_v3(test.plane_tool, area_co, area_no_sp); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_cube(&test, vd.co, mat)) { if (plane_point_side_flip(vd.co, test.plane_tool, flip)) { float intr[3]; float val[3]; closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); sub_v3_v3v3(val, intr, vd.co); if (plane_trim(ss->cache, brush, val)) { /* note, the normal from the vertices is ignored, * causes glitch with planes, see: T44390 */ const float fade = bstrength * tex_strength(ss, brush, vd.co, ss->cache->radius * test.dist, vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], val, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } } } BKE_pbvh_vertex_iter_end; } static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); const bool flip = (ss->cache->bstrength < 0); const float radius = flip ? -ss->cache->radius : ss->cache->radius; const float offset = get_offset(sd, ss); const float displace = radius * (0.25f + offset); float area_no_sp[3]; /* the sculpt-plane normal (whatever its set to) */ float area_no[3]; /* geometry normal */ float area_co[3]; float temp[3]; float mat[4][4]; float scale[4][4]; float tmat[4][4]; calc_sculpt_plane(sd, ob, nodes, totnode, area_no_sp, area_co); if (brush->sculpt_plane != SCULPT_DISP_DIR_AREA || (brush->flag & BRUSH_ORIGINAL_NORMAL)) { calc_area_normal(sd, ob, nodes, totnode, area_no); } else { copy_v3_v3(area_no, area_no_sp); } /* delay the first daub because grab delta is not setup */ if (ss->cache->first_time) { return; } if (is_zero_v3(ss->cache->grab_delta_symmetry)) { return; } mul_v3_v3v3(temp, area_no_sp, ss->cache->scale); mul_v3_fl(temp, displace); add_v3_v3(area_co, temp); /* init mat */ cross_v3_v3v3(mat[0], area_no, ss->cache->grab_delta_symmetry); mat[0][3] = 0; cross_v3_v3v3(mat[1], area_no, mat[0]); mat[1][3] = 0; copy_v3_v3(mat[2], area_no); mat[2][3] = 0; copy_v3_v3(mat[3], ss->cache->location); mat[3][3] = 1; normalize_m4(mat); /* scale mat */ scale_m4_fl(scale, ss->cache->radius); mul_m4_m4m4(tmat, mat, scale); invert_m4_m4(mat, tmat); SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .area_no_sp = area_no_sp, .area_co = area_co, .mat = mat, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_clay_strips_brush_task_cb_ex, &settings); } static void do_fill_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *area_no = data->area_no; const float *area_co = data->area_co; PBVHVertexIter vd; float(*proxy)[3]; const float bstrength = ss->cache->bstrength; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); plane_from_point_normal_v3(test.plane_tool, area_co, area_no); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { if (plane_point_side(vd.co, test.plane_tool)) { float intr[3]; float val[3]; closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); sub_v3_v3v3(val, intr, vd.co); if (plane_trim(ss->cache, brush, val)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], val, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } } } BKE_pbvh_vertex_iter_end; } static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); const float radius = ss->cache->radius; float area_no[3]; float area_co[3]; float offset = get_offset(sd, ss); float displace; float temp[3]; calc_sculpt_plane(sd, ob, nodes, totnode, area_no, area_co); displace = radius * offset; mul_v3_v3v3(temp, area_no, ss->cache->scale); mul_v3_fl(temp, displace); add_v3_v3(area_co, temp); SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .area_no = area_no, .area_co = area_co, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_fill_brush_task_cb_ex, &settings); } static void do_scrape_brush_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; const float *area_no = data->area_no; const float *area_co = data->area_co; PBVHVertexIter vd; float(*proxy)[3]; const float bstrength = ss->cache->bstrength; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); plane_from_point_normal_v3(test.plane_tool, area_co, area_no); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { if (!plane_point_side(vd.co, test.plane_tool)) { float intr[3]; float val[3]; closest_to_plane_normalized_v3(intr, test.plane_tool, vd.co); sub_v3_v3v3(val, intr, vd.co); if (plane_trim(ss->cache, brush, val)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], val, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } } } BKE_pbvh_vertex_iter_end; } static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); const float radius = ss->cache->radius; float area_no[3]; float area_co[3]; float offset = get_offset(sd, ss); float displace; float temp[3]; calc_sculpt_plane(sd, ob, nodes, totnode, area_no, area_co); displace = -radius * offset; mul_v3_v3v3(temp, area_no, ss->cache->scale); mul_v3_fl(temp, displace); add_v3_v3(area_co, temp); SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .area_no = area_no, .area_co = area_co, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_scrape_brush_task_cb_ex, &settings); } static void do_gravity_task_cb_ex(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; const Brush *brush = data->brush; float *offset = data->offset; PBVHVertexIter vd; float(*proxy)[3]; proxy = BKE_pbvh_node_add_proxy(ss->pbvh, data->nodes[n])->co; SculptBrushTest test; SculptBrushTestFn sculpt_brush_test_sq_fn = sculpt_brush_test_init_with_falloff_shape( ss, &test, data->brush->falloff_shape); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_sq_fn(&test, vd.co)) { const float fade = tex_strength(ss, brush, vd.co, sqrtf(test.dist), vd.no, vd.fno, vd.mask ? *vd.mask : 0.0f, tls->thread_id); mul_v3_v3fl(proxy[vd.i], offset, fade); if (vd.mvert) { vd.mvert->flag |= ME_VERT_PBVH_UPDATE; } } } BKE_pbvh_vertex_iter_end; } static void do_gravity(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float bstrength) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); float offset[3] /*, area_no[3]*/; float gravity_vector[3]; mul_v3_v3fl(gravity_vector, ss->cache->gravity_direction, -ss->cache->radius_squared); /* offset with as much as possible factored in already */ mul_v3_v3v3(offset, gravity_vector, ss->cache->scale); mul_v3_fl(offset, bstrength); /* threaded loop over nodes */ SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .offset = offset, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_gravity_task_cb_ex, &settings); } void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]) { Mesh *me = (Mesh *)ob->data; float(*ofs)[3] = NULL; int a; const int kb_act_idx = ob->shapenr - 1; KeyBlock *currkey; /* for relative keys editing of base should update other keys */ if (BKE_keyblock_is_basis(me->key, kb_act_idx)) { ofs = BKE_keyblock_convert_to_vertcos(ob, kb); /* calculate key coord offsets (from previous location) */ for (a = 0; a < me->totvert; a++) { sub_v3_v3v3(ofs[a], vertCos[a], ofs[a]); } /* apply offsets on other keys */ for (currkey = me->key->block.first; currkey; currkey = currkey->next) { if ((currkey != kb) && (currkey->relative == kb_act_idx)) { BKE_keyblock_update_from_offset(ob, currkey, ofs); } } MEM_freeN(ofs); } /* modifying of basis key should update mesh */ if (kb == me->key->refkey) { MVert *mvert = me->mvert; for (a = 0; a < me->totvert; a++, mvert++) { copy_v3_v3(mvert->co, vertCos[a]); } BKE_mesh_calc_normals(me); } /* apply new coords on active key block, no need to re-allocate kb->data here! */ BKE_keyblock_update_from_vertcos(ob, kb, vertCos); } /* Note: we do the topology update before any brush actions to avoid * issues with the proxies. The size of the proxy can't change, so * topology must be updated first. */ static void sculpt_topology_update(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *UNUSED(ups)) { SculptSession *ss = ob->sculpt; int n, totnode; /* Build a list of all nodes that are potentially within the brush's area of influence */ const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ? true : ss->cache->original; const float radius_scale = 1.25f; PBVHNode **nodes = sculpt_pbvh_gather_generic( ob, sd, brush, use_original, radius_scale, &totnode); /* Only act if some verts are inside the brush area */ if (totnode) { PBVHTopologyUpdateMode mode = 0; float location[3]; if (!(sd->flags & SCULPT_DYNTOPO_DETAIL_MANUAL)) { if (sd->flags & SCULPT_DYNTOPO_SUBDIVIDE) { mode |= PBVH_Subdivide; } if ((sd->flags & SCULPT_DYNTOPO_COLLAPSE) || (brush->sculpt_tool == SCULPT_TOOL_SIMPLIFY)) { mode |= PBVH_Collapse; } } for (n = 0; n < totnode; n++) { sculpt_undo_push_node(ob, nodes[n], brush->sculpt_tool == SCULPT_TOOL_MASK ? SCULPT_UNDO_MASK : SCULPT_UNDO_COORDS); BKE_pbvh_node_mark_update(nodes[n]); if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) { BKE_pbvh_node_mark_topology_update(nodes[n]); BKE_pbvh_bmesh_node_save_orig(nodes[n]); } } if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) { BKE_pbvh_bmesh_update_topology(ss->pbvh, mode, ss->cache->location, ss->cache->view_normal, ss->cache->radius, (brush->flag & BRUSH_FRONTFACE) != 0, (brush->falloff_shape != PAINT_FALLOFF_SHAPE_SPHERE)); } MEM_freeN(nodes); /* update average stroke position */ copy_v3_v3(location, ss->cache->true_location); mul_m4_v3(ob->obmat, location); } } static void do_brush_action_task_cb(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; sculpt_undo_push_node(data->ob, data->nodes[n], data->brush->sculpt_tool == SCULPT_TOOL_MASK ? SCULPT_UNDO_MASK : SCULPT_UNDO_COORDS); BKE_pbvh_node_mark_update(data->nodes[n]); } static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups) { SculptSession *ss = ob->sculpt; int totnode; /* Build a list of all nodes that are potentially within the brush's area of influence */ const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ? true : ss->cache->original; const float radius_scale = 1.0f; PBVHNode **nodes = sculpt_pbvh_gather_generic( ob, sd, brush, use_original, radius_scale, &totnode); /* Only act if some verts are inside the brush area */ if (totnode) { float location[3]; SculptThreadedTaskData task_data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings); if (sculpt_brush_needs_normal(ss, brush)) { update_sculpt_normal(sd, ob, nodes, totnode); } if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) { update_brush_local_mat(sd, ob); } /* Apply one type of brush action */ switch (brush->sculpt_tool) { case SCULPT_TOOL_DRAW: do_draw_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_SMOOTH: do_smooth_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_CREASE: do_crease_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_BLOB: do_crease_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_PINCH: do_pinch_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_INFLATE: do_inflate_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_GRAB: do_grab_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_ROTATE: do_rotate_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_SNAKE_HOOK: do_snake_hook_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_NUDGE: do_nudge_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_THUMB: do_thumb_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_LAYER: do_layer_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_FLATTEN: do_flatten_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_CLAY: do_clay_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_CLAY_STRIPS: do_clay_strips_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_FILL: do_fill_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_SCRAPE: do_scrape_brush(sd, ob, nodes, totnode); break; case SCULPT_TOOL_MASK: do_mask_brush(sd, ob, nodes, totnode); break; } if (!ELEM(brush->sculpt_tool, SCULPT_TOOL_SMOOTH, SCULPT_TOOL_MASK) && brush->autosmooth_factor > 0) { if (brush->flag & BRUSH_INVERSE_SMOOTH_PRESSURE) { smooth( sd, ob, nodes, totnode, brush->autosmooth_factor * (1 - ss->cache->pressure), false); } else { smooth(sd, ob, nodes, totnode, brush->autosmooth_factor, false); } } if (sculpt_brush_use_topology_rake(ss, brush)) { bmesh_topology_rake(sd, ob, nodes, totnode, brush->topology_rake_factor); } if (ss->cache->supports_gravity) { do_gravity(sd, ob, nodes, totnode, sd->gravity_factor); } MEM_freeN(nodes); /* update average stroke position */ copy_v3_v3(location, ss->cache->true_location); mul_m4_v3(ob->obmat, location); add_v3_v3(ups->average_stroke_accum, location); ups->average_stroke_counter++; /* update last stroke position */ ups->last_stroke_valid = true; } } /* flush displacement from deformed PBVH vertex to original mesh */ static void sculpt_flush_pbvhvert_deform(Object *ob, PBVHVertexIter *vd) { SculptSession *ss = ob->sculpt; Mesh *me = ob->data; float disp[3], newco[3]; int index = vd->vert_indices[vd->i]; sub_v3_v3v3(disp, vd->co, ss->deform_cos[index]); mul_m3_v3(ss->deform_imats[index], disp); add_v3_v3v3(newco, disp, ss->orig_cos[index]); copy_v3_v3(ss->deform_cos[index], vd->co); copy_v3_v3(ss->orig_cos[index], newco); if (!ss->kb) { copy_v3_v3(me->mvert[index].co, newco); } } static void sculpt_combine_proxies_task_cb(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; Object *ob = data->ob; /* these brushes start from original coordinates */ const bool use_orco = ELEM( data->brush->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_ROTATE, SCULPT_TOOL_THUMB); PBVHVertexIter vd; PBVHProxyNode *proxies; int proxy_count; float(*orco)[3] = NULL; if (use_orco && !ss->bm) { orco = sculpt_undo_push_node(data->ob, data->nodes[n], SCULPT_UNDO_COORDS)->co; } BKE_pbvh_node_get_proxies(data->nodes[n], &proxies, &proxy_count); BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { float val[3]; int p; if (use_orco) { if (ss->bm) { copy_v3_v3(val, BM_log_original_vert_co(ss->bm_log, vd.bm_vert)); } else { copy_v3_v3(val, orco[vd.i]); } } else { copy_v3_v3(val, vd.co); } for (p = 0; p < proxy_count; p++) { add_v3_v3(val, proxies[p].co[vd.i]); } sculpt_clip(sd, ss, vd.co, val); if (ss->modifiers_active) { sculpt_flush_pbvhvert_deform(ob, &vd); } } BKE_pbvh_vertex_iter_end; BKE_pbvh_node_free_proxies(data->nodes[n]); } static void sculpt_combine_proxies(Sculpt *sd, Object *ob) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); PBVHNode **nodes; int totnode; BKE_pbvh_gather_proxies(ss->pbvh, &nodes, &totnode); /* first line is tools that don't support proxies */ if (ss->cache->supports_gravity || (sculpt_tool_is_proxy_used(brush->sculpt_tool) == false)) { SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, sculpt_combine_proxies_task_cb, &settings); } if (nodes) { MEM_freeN(nodes); } } /* copy the modified vertices from bvh to the active key */ static void sculpt_update_keyblock(Object *ob) { SculptSession *ss = ob->sculpt; float(*vertCos)[3]; /* Keyblock update happens after handling deformation caused by modifiers, * so ss->orig_cos would be updated with new stroke */ if (ss->orig_cos) { vertCos = ss->orig_cos; } else { vertCos = BKE_pbvh_get_vertCos(ss->pbvh); } if (vertCos) { sculpt_vertcos_to_key(ob, ss->kb, vertCos); if (vertCos != ss->orig_cos) { MEM_freeN(vertCos); } } } static void sculpt_flush_stroke_deform_task_cb(void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; Object *ob = data->ob; float(*vertCos)[3] = data->vertCos; PBVHVertexIter vd; BKE_pbvh_vertex_iter_begin(ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) { sculpt_flush_pbvhvert_deform(ob, &vd); if (vertCos) { int index = vd.vert_indices[vd.i]; copy_v3_v3(vertCos[index], ss->orig_cos[index]); } } BKE_pbvh_vertex_iter_end; } /* flush displacement from deformed PBVH to original layer */ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); if (sculpt_tool_is_proxy_used(brush->sculpt_tool)) { /* this brushes aren't using proxies, so sculpt_combine_proxies() wouldn't * propagate needed deformation to original base */ int totnode; Mesh *me = (Mesh *)ob->data; PBVHNode **nodes; float(*vertCos)[3] = NULL; if (ss->kb) { vertCos = MEM_mallocN(sizeof(*vertCos) * me->totvert, "flushStrokeDeofrm keyVerts"); /* mesh could have isolated verts which wouldn't be in BVH, * to deal with this we copy old coordinates over new ones * and then update coordinates for all vertices from BVH */ memcpy(vertCos, ss->orig_cos, sizeof(*vertCos) * me->totvert); } BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .vertCos = vertCos, }; ParallelRangeSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, sculpt_flush_stroke_deform_task_cb, &settings); if (vertCos) { sculpt_vertcos_to_key(ob, ss->kb, vertCos); MEM_freeN(vertCos); } MEM_freeN(nodes); /* Modifiers could depend on mesh normals, so we should update them/ * Note, then if sculpting happens on locked key, normals should be re-calculated * after applying coords from keyblock on base mesh */ BKE_mesh_calc_normals(me); } else if (ss->kb) { sculpt_update_keyblock(ob); } } /* Flip all the editdata across the axis/axes specified by symm. Used to * calculate multiple modifications to the mesh when symmetry is enabled. */ void sculpt_cache_calc_brushdata_symm(StrokeCache *cache, const char symm, const char axis, const float angle) { flip_v3_v3(cache->location, cache->true_location, symm); flip_v3_v3(cache->last_location, cache->true_last_location, symm); flip_v3_v3(cache->grab_delta_symmetry, cache->grab_delta, symm); flip_v3_v3(cache->view_normal, cache->true_view_normal, symm); /* XXX This reduces the length of the grab delta if it approaches the line of symmetry * XXX However, a different approach appears to be needed */ #if 0 if (sd->paint.symmetry_flags & PAINT_SYMMETRY_FEATHER) { float frac = 1.0f / max_overlap_count(sd); float reduce = (feather - frac) / (1 - frac); printf("feather: %f frac: %f reduce: %f\n", feather, frac, reduce); if (frac < 1) mul_v3_fl(cache->grab_delta_symmetry, reduce); } #endif unit_m4(cache->symm_rot_mat); unit_m4(cache->symm_rot_mat_inv); zero_v3(cache->plane_offset); if (axis) { /* expects XYZ */ rotate_m4(cache->symm_rot_mat, axis, angle); rotate_m4(cache->symm_rot_mat_inv, axis, -angle); } mul_m4_v3(cache->symm_rot_mat, cache->location); mul_m4_v3(cache->symm_rot_mat, cache->grab_delta_symmetry); if (cache->supports_gravity) { flip_v3_v3(cache->gravity_direction, cache->true_gravity_direction, symm); mul_m4_v3(cache->symm_rot_mat, cache->gravity_direction); } if (cache->is_rake_rotation_valid) { flip_qt_qt(cache->rake_rotation_symmetry, cache->rake_rotation, symm); } } typedef void (*BrushActionFunc)(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups); static void do_tiled( Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, BrushActionFunc action) { SculptSession *ss = ob->sculpt; StrokeCache *cache = ss->cache; const float radius = cache->radius; BoundBox *bb = BKE_object_boundbox_get(ob); const float *bbMin = bb->vec[0]; const float *bbMax = bb->vec[6]; const float *step = sd->paint.tile_offset; int dim; /* These are integer locations, for real location: multiply with step and add orgLoc. * So 0,0,0 is at orgLoc. */ int start[3]; int end[3]; int cur[3]; float orgLoc[3]; /* position of the "prototype" stroke for tiling */ copy_v3_v3(orgLoc, cache->location); for (dim = 0; dim < 3; ++dim) { if ((sd->paint.symmetry_flags & (PAINT_TILE_X << dim)) && step[dim] > 0) { start[dim] = (bbMin[dim] - orgLoc[dim] - radius) / step[dim]; end[dim] = (bbMax[dim] - orgLoc[dim] + radius) / step[dim]; } else { start[dim] = end[dim] = 0; } } /* first do the "untiled" position to initialize the stroke for this location */ cache->tile_pass = 0; action(sd, ob, brush, ups); /* now do it for all the tiles */ copy_v3_v3_int(cur, start); for (cur[0] = start[0]; cur[0] <= end[0]; ++cur[0]) { for (cur[1] = start[1]; cur[1] <= end[1]; ++cur[1]) { for (cur[2] = start[2]; cur[2] <= end[2]; ++cur[2]) { if (!cur[0] && !cur[1] && !cur[2]) { continue; /* skip tile at orgLoc, this was already handled before all others */ } ++cache->tile_pass; for (dim = 0; dim < 3; ++dim) { cache->location[dim] = cur[dim] * step[dim] + orgLoc[dim]; cache->plane_offset[dim] = cur[dim] * step[dim]; } action(sd, ob, brush, ups); } } } } static void do_radial_symmetry(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, BrushActionFunc action, const char symm, const int axis, const float UNUSED(feather)) { SculptSession *ss = ob->sculpt; int i; for (i = 1; i < sd->radial_symm[axis - 'X']; ++i) { const float angle = 2 * M_PI * i / sd->radial_symm[axis - 'X']; ss->cache->radial_symmetry_pass = i; sculpt_cache_calc_brushdata_symm(ss->cache, symm, axis, angle); do_tiled(sd, ob, brush, ups, action); } } /* noise texture gives different values for the same input coord; this * can tear a multires mesh during sculpting so do a stitch in this * case */ static void sculpt_fix_noise_tear(Sculpt *sd, Object *ob) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); MTex *mtex = &brush->mtex; if (ss->multires && mtex->tex && mtex->tex->type == TEX_NOISE) { multires_stitch_grids(ob); } } static void do_symmetrical_brush_actions(Sculpt *sd, Object *ob, BrushActionFunc action, UnifiedPaintSettings *ups) { Brush *brush = BKE_paint_brush(&sd->paint); SculptSession *ss = ob->sculpt; StrokeCache *cache = ss->cache; const char symm = sd->paint.symmetry_flags & PAINT_SYMM_AXIS_ALL; int i; float feather = calc_symmetry_feather(sd, ss->cache); cache->bstrength = brush_strength(sd, cache, feather, ups); cache->symmetry = symm; /* symm is a bit combination of XYZ - * 1 is mirror X; 2 is Y; 3 is XY; 4 is Z; 5 is XZ; 6 is YZ; 7 is XYZ */ for (i = 0; i <= symm; ++i) { if (i == 0 || (symm & i && (symm != 5 || i != 3) && (symm != 6 || (i != 3 && i != 5)))) { cache->mirror_symmetry_pass = i; cache->radial_symmetry_pass = 0; sculpt_cache_calc_brushdata_symm(cache, i, 0, 0); do_tiled(sd, ob, brush, ups, action); do_radial_symmetry(sd, ob, brush, ups, action, i, 'X', feather); do_radial_symmetry(sd, ob, brush, ups, action, i, 'Y', feather); do_radial_symmetry(sd, ob, brush, ups, action, i, 'Z', feather); } } } static void sculpt_update_tex(const Scene *scene, Sculpt *sd, SculptSession *ss) { Brush *brush = BKE_paint_brush(&sd->paint); const int radius = BKE_brush_size_get(scene, brush); if (ss->texcache) { MEM_freeN(ss->texcache); ss->texcache = NULL; } if (ss->tex_pool) { BKE_image_pool_free(ss->tex_pool); ss->tex_pool = NULL; } /* Need to allocate a bigger buffer for bigger brush size */ ss->texcache_side = 2 * radius; if (!ss->texcache || ss->texcache_side > ss->texcache_actual) { ss->texcache = BKE_brush_gen_texture_cache(brush, radius, false); ss->texcache_actual = ss->texcache_side; ss->tex_pool = BKE_image_pool_new(); } } bool sculpt_mode_poll(bContext *C) { Object *ob = CTX_data_active_object(C); return ob && ob->mode & OB_MODE_SCULPT; } bool sculpt_mode_poll_view3d(bContext *C) { return (sculpt_mode_poll(C) && CTX_wm_region_view3d(C)); } bool sculpt_poll_view3d(bContext *C) { return (sculpt_poll(C) && CTX_wm_region_view3d(C)); } bool sculpt_poll(bContext *C) { return sculpt_mode_poll(C) && paint_poll(C); } static const char *sculpt_tool_name(Sculpt *sd) { Brush *brush = BKE_paint_brush(&sd->paint); switch ((eBrushSculptTool)brush->sculpt_tool) { case SCULPT_TOOL_DRAW: return "Draw Brush"; case SCULPT_TOOL_SMOOTH: return "Smooth Brush"; case SCULPT_TOOL_CREASE: return "Crease Brush"; case SCULPT_TOOL_BLOB: return "Blob Brush"; case SCULPT_TOOL_PINCH: return "Pinch Brush"; case SCULPT_TOOL_INFLATE: return "Inflate Brush"; case SCULPT_TOOL_GRAB: return "Grab Brush"; case SCULPT_TOOL_NUDGE: return "Nudge Brush"; case SCULPT_TOOL_THUMB: return "Thumb Brush"; case SCULPT_TOOL_LAYER: return "Layer Brush"; case SCULPT_TOOL_FLATTEN: return "Flatten Brush"; case SCULPT_TOOL_CLAY: return "Clay Brush"; case SCULPT_TOOL_CLAY_STRIPS: return "Clay Strips Brush"; case SCULPT_TOOL_FILL: return "Fill Brush"; case SCULPT_TOOL_SCRAPE: return "Scrape Brush"; case SCULPT_TOOL_SNAKE_HOOK: return "Snake Hook Brush"; case SCULPT_TOOL_ROTATE: return "Rotate Brush"; case SCULPT_TOOL_MASK: return "Mask Brush"; case SCULPT_TOOL_SIMPLIFY: return "Simplify Brush"; } return "Sculpting"; } /** * Operator for applying a stroke (various attributes including mouse path) * using the current brush. */ void sculpt_cache_free(StrokeCache *cache) { if (cache->dial) { MEM_freeN(cache->dial); } MEM_freeN(cache); } /* Initialize mirror modifier clipping */ static void sculpt_init_mirror_clipping(Object *ob, SculptSession *ss) { ModifierData *md; int i; for (md = ob->modifiers.first; md; md = md->next) { if (md->type == eModifierType_Mirror && (md->mode & eModifierMode_Realtime)) { MirrorModifierData *mmd = (MirrorModifierData *)md; if (mmd->flag & MOD_MIR_CLIPPING) { /* check each axis for mirroring */ for (i = 0; i < 3; ++i) { if (mmd->flag & (MOD_MIR_AXIS_X << i)) { /* enable sculpt clipping */ ss->cache->flag |= CLIP_X << i; /* update the clip tolerance */ if (mmd->tolerance > ss->cache->clip_tolerance[i]) { ss->cache->clip_tolerance[i] = mmd->tolerance; } } } } } } } /* Initialize the stroke cache invariants from operator properties */ static void sculpt_update_cache_invariants( bContext *C, Sculpt *sd, SculptSession *ss, wmOperator *op, const float mouse[2]) { StrokeCache *cache = MEM_callocN(sizeof(StrokeCache), "stroke cache"); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; Brush *brush = BKE_paint_brush(&sd->paint); ViewContext *vc = paint_stroke_view_context(op->customdata); Object *ob = CTX_data_active_object(C); float mat[3][3]; float viewDir[3] = {0.0f, 0.0f, 1.0f}; float max_scale; int i; int mode; ss->cache = cache; /* Set scaling adjustment */ if (brush->sculpt_tool == SCULPT_TOOL_LAYER) { max_scale = 1.0f; } else { max_scale = 0.0f; for (i = 0; i < 3; i++) { max_scale = max_ff(max_scale, fabsf(ob->scale[i])); } } cache->scale[0] = max_scale / ob->scale[0]; cache->scale[1] = max_scale / ob->scale[1]; cache->scale[2] = max_scale / ob->scale[2]; cache->plane_trim_squared = brush->plane_trim * brush->plane_trim; cache->flag = 0; sculpt_init_mirror_clipping(ob, ss); /* Initial mouse location */ if (mouse) { copy_v2_v2(cache->initial_mouse, mouse); } else { zero_v2(cache->initial_mouse); } mode = RNA_enum_get(op->ptr, "mode"); cache->invert = mode == BRUSH_STROKE_INVERT; cache->alt_smooth = mode == BRUSH_STROKE_SMOOTH; cache->normal_weight = brush->normal_weight; /* interpret invert as following normal, for grab brushes */ if (SCULPT_TOOL_HAS_NORMAL_WEIGHT(brush->sculpt_tool)) { if (cache->invert) { cache->invert = false; cache->normal_weight = (cache->normal_weight == 0.0f); } } /* not very nice, but with current events system implementation * we can't handle brush appearance inversion hotkey separately (sergey) */ if (cache->invert) { ups->draw_inverted = true; } else { ups->draw_inverted = false; } /* Alt-Smooth */ if (cache->alt_smooth) { if (brush->sculpt_tool == SCULPT_TOOL_MASK) { cache->saved_mask_brush_tool = brush->mask_tool; brush->mask_tool = BRUSH_MASK_SMOOTH; } else { Paint *p = &sd->paint; Brush *br; int size = BKE_brush_size_get(scene, brush); BLI_strncpy(cache->saved_active_brush_name, brush->id.name + 2, sizeof(cache->saved_active_brush_name)); br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Smooth"); if (br) { BKE_paint_brush_set(p, br); brush = br; cache->saved_smooth_size = BKE_brush_size_get(scene, brush); BKE_brush_size_set(scene, brush, size); curvemapping_initialize(brush->curve); } } } copy_v2_v2(cache->mouse, cache->initial_mouse); copy_v2_v2(ups->tex_mouse, cache->initial_mouse); /* Truly temporary data that isn't stored in properties */ cache->vc = vc; cache->brush = brush; /* cache projection matrix */ ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob, cache->projection_mat); invert_m4_m4(ob->imat, ob->obmat); copy_m3_m4(mat, cache->vc->rv3d->viewinv); mul_m3_v3(mat, viewDir); copy_m3_m4(mat, ob->imat); mul_m3_v3(mat, viewDir); normalize_v3_v3(cache->true_view_normal, viewDir); cache->supports_gravity = (!ELEM(brush->sculpt_tool, SCULPT_TOOL_MASK, SCULPT_TOOL_SMOOTH, SCULPT_TOOL_SIMPLIFY) && (sd->gravity_factor > 0.0f)); /* get gravity vector in world space */ if (cache->supports_gravity) { if (sd->gravity_object) { Object *gravity_object = sd->gravity_object; copy_v3_v3(cache->true_gravity_direction, gravity_object->obmat[2]); } else { cache->true_gravity_direction[0] = cache->true_gravity_direction[1] = 0.0; cache->true_gravity_direction[2] = 1.0; } /* transform to sculpted object space */ mul_m3_v3(mat, cache->true_gravity_direction); normalize_v3(cache->true_gravity_direction); } /* Initialize layer brush displacements and persistent coords */ if (brush->sculpt_tool == SCULPT_TOOL_LAYER) { /* not supported yet for multires or dynamic topology */ if (!ss->multires && !ss->bm && !ss->layer_co && (brush->flag & BRUSH_PERSISTENT)) { if (!ss->layer_co) { ss->layer_co = MEM_mallocN(sizeof(float) * 3 * ss->totvert, "sculpt mesh vertices copy"); } if (ss->deform_cos) { memcpy(ss->layer_co, ss->deform_cos, ss->totvert); } else { for (i = 0; i < ss->totvert; ++i) { copy_v3_v3(ss->layer_co[i], ss->mvert[i].co); } } } if (ss->bm) { /* Free any remaining layer displacements from nodes. If not and topology changes * from using another tool, then next layer toolstroke * can access past disp array bounds */ BKE_pbvh_free_layer_disp(ss->pbvh); } } /* Make copies of the mesh vertex locations and normals for some tools */ if (brush->flag & BRUSH_ANCHORED) { cache->original = 1; } if (SCULPT_TOOL_HAS_ACCUMULATE(brush->sculpt_tool)) { if (!(brush->flag & BRUSH_ACCUMULATE)) { cache->original = 1; } } cache->first_time = 1; #define PIXEL_INPUT_THRESHHOLD 5 if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) { cache->dial = BLI_dial_initialize(cache->initial_mouse, PIXEL_INPUT_THRESHHOLD); } #undef PIXEL_INPUT_THRESHHOLD } static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Brush *brush) { SculptSession *ss = ob->sculpt; StrokeCache *cache = ss->cache; const float mouse[2] = { cache->mouse[0], cache->mouse[1], }; int tool = brush->sculpt_tool; if (ELEM(tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_NUDGE, SCULPT_TOOL_CLAY_STRIPS, SCULPT_TOOL_SNAKE_HOOK, SCULPT_TOOL_THUMB) || sculpt_brush_use_topology_rake(ss, brush)) { float grab_location[3], imat[4][4], delta[3], loc[3]; if (cache->first_time) { copy_v3_v3(cache->orig_grab_location, cache->true_location); } else if (tool == SCULPT_TOOL_SNAKE_HOOK) { add_v3_v3(cache->true_location, cache->grab_delta); } /* compute 3d coordinate at same z from original location + mouse */ mul_v3_m4v3(loc, ob->obmat, cache->orig_grab_location); ED_view3d_win_to_3d(cache->vc->v3d, cache->vc->ar, loc, mouse, grab_location); /* compute delta to move verts by */ if (!cache->first_time) { switch (tool) { case SCULPT_TOOL_GRAB: case SCULPT_TOOL_THUMB: sub_v3_v3v3(delta, grab_location, cache->old_grab_location); invert_m4_m4(imat, ob->obmat); mul_mat3_m4_v3(imat, delta); add_v3_v3(cache->grab_delta, delta); break; case SCULPT_TOOL_CLAY_STRIPS: case SCULPT_TOOL_NUDGE: case SCULPT_TOOL_SNAKE_HOOK: if (brush->flag & BRUSH_ANCHORED) { float orig[3]; mul_v3_m4v3(orig, ob->obmat, cache->orig_grab_location); sub_v3_v3v3(cache->grab_delta, grab_location, orig); } else { sub_v3_v3v3(cache->grab_delta, grab_location, cache->old_grab_location); } invert_m4_m4(imat, ob->obmat); mul_mat3_m4_v3(imat, cache->grab_delta); break; default: /* Use for 'Brush.topology_rake_factor'. */ sub_v3_v3v3(cache->grab_delta, grab_location, cache->old_grab_location); break; } } else { zero_v3(cache->grab_delta); } if (brush->falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) { project_plane_v3_v3v3(cache->grab_delta, cache->grab_delta, ss->cache->true_view_normal); } copy_v3_v3(cache->old_grab_location, grab_location); if (tool == SCULPT_TOOL_GRAB) { copy_v3_v3(cache->anchored_location, cache->true_location); } else if (tool == SCULPT_TOOL_THUMB) { copy_v3_v3(cache->anchored_location, cache->orig_grab_location); } if (ELEM(tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_THUMB)) { /* location stays the same for finding vertices in brush radius */ copy_v3_v3(cache->true_location, cache->orig_grab_location); ups->draw_anchored = true; copy_v2_v2(ups->anchored_initial_mouse, cache->initial_mouse); ups->anchored_size = ups->pixel_radius; } /* handle 'rake' */ cache->is_rake_rotation_valid = false; if (cache->first_time) { copy_v3_v3(cache->rake_data.follow_co, grab_location); } if (sculpt_brush_needs_rake_rotation(brush)) { cache->rake_data.follow_dist = cache->radius * SCULPT_RAKE_BRUSH_FACTOR; if (!is_zero_v3(cache->grab_delta)) { const float eps = 0.00001f; float v1[3], v2[3]; copy_v3_v3(v1, cache->rake_data.follow_co); copy_v3_v3(v2, cache->rake_data.follow_co); sub_v3_v3(v2, cache->grab_delta); sub_v3_v3(v1, grab_location); sub_v3_v3(v2, grab_location); if ((normalize_v3(v2) > eps) && (normalize_v3(v1) > eps) && (len_squared_v3v3(v1, v2) > eps)) { const float rake_dist_sq = len_squared_v3v3(cache->rake_data.follow_co, grab_location); const float rake_fade = (rake_dist_sq > SQUARE(cache->rake_data.follow_dist)) ? 1.0f : sqrtf(rake_dist_sq) / cache->rake_data.follow_dist; float axis[3], angle; float tquat[4]; rotation_between_vecs_to_quat(tquat, v1, v2); /* use axis-angle to scale rotation since the factor may be above 1 */ quat_to_axis_angle(axis, &angle, tquat); normalize_v3(axis); angle *= brush->rake_factor * rake_fade; axis_angle_normalized_to_quat(cache->rake_rotation, axis, angle); cache->is_rake_rotation_valid = true; } } sculpt_rake_data_update(&cache->rake_data, grab_location); } } } /* Initialize the stroke cache variants from operator properties */ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, PointerRNA *ptr) { Scene *scene = CTX_data_scene(C); UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; SculptSession *ss = ob->sculpt; StrokeCache *cache = ss->cache; Brush *brush = BKE_paint_brush(&sd->paint); /* RNA_float_get_array(ptr, "location", cache->traced_location); */ if (cache->first_time || !((brush->flag & BRUSH_ANCHORED) || (brush->sculpt_tool == SCULPT_TOOL_SNAKE_HOOK) || (brush->sculpt_tool == SCULPT_TOOL_ROTATE))) { RNA_float_get_array(ptr, "location", cache->true_location); } cache->pen_flip = RNA_boolean_get(ptr, "pen_flip"); RNA_float_get_array(ptr, "mouse", cache->mouse); /* XXX: Use pressure value from first brush step for brushes which don't * support strokes (grab, thumb). They depends on initial state and * brush coord/pressure/etc. * It's more an events design issue, which doesn't split coordinate/pressure/angle * changing events. We should avoid this after events system re-design */ if (paint_supports_dynamic_size(brush, PAINT_MODE_SCULPT) || cache->first_time) { cache->pressure = RNA_float_get(ptr, "pressure"); } /* Truly temporary data that isn't stored in properties */ if (cache->first_time) { if (!BKE_brush_use_locked_size(scene, brush)) { cache->initial_radius = paint_calc_object_space_radius( cache->vc, cache->true_location, BKE_brush_size_get(scene, brush)); BKE_brush_unprojected_radius_set(scene, brush, cache->initial_radius); } else { cache->initial_radius = BKE_brush_unprojected_radius_get(scene, brush); } } if (BKE_brush_use_size_pressure(scene, brush) && paint_supports_dynamic_size(brush, PAINT_MODE_SCULPT)) { cache->radius = cache->initial_radius * cache->pressure; } else { cache->radius = cache->initial_radius; } cache->radius_squared = cache->radius * cache->radius; if (brush->flag & BRUSH_ANCHORED) { /* true location has been calculated as part of the stroke system already here */ if (brush->flag & BRUSH_EDGE_TO_EDGE) { RNA_float_get_array(ptr, "location", cache->true_location); } cache->radius = paint_calc_object_space_radius( cache->vc, cache->true_location, ups->pixel_radius); cache->radius_squared = cache->radius * cache->radius; copy_v3_v3(cache->anchored_location, cache->true_location); } sculpt_update_brush_delta(ups, ob, brush); if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) { cache->vertex_rotation = -BLI_dial_angle(cache->dial, cache->mouse) * cache->bstrength; ups->draw_anchored = true; copy_v2_v2(ups->anchored_initial_mouse, cache->initial_mouse); copy_v3_v3(cache->anchored_location, cache->true_location); ups->anchored_size = ups->pixel_radius; } cache->special_rotation = ups->brush_rotation; } /* Returns true if any of the smoothing modes are active (currently * one of smooth brush, autosmooth, mask smooth, or shift-key * smooth) */ static bool sculpt_any_smooth_mode(const Brush *brush, StrokeCache *cache, int stroke_mode) { return ((stroke_mode == BRUSH_STROKE_SMOOTH) || (cache && cache->alt_smooth) || (brush->sculpt_tool == SCULPT_TOOL_SMOOTH) || (brush->autosmooth_factor > 0) || ((brush->sculpt_tool == SCULPT_TOOL_MASK) && (brush->mask_tool == BRUSH_MASK_SMOOTH))); } static void sculpt_stroke_modifiers_check(const bContext *C, Object *ob, const Brush *brush) { SculptSession *ss = ob->sculpt; if (ss->kb || ss->modifiers_active) { Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Sculpt *sd = scene->toolsettings->sculpt; bool need_pmap = sculpt_any_smooth_mode(brush, ss->cache, 0); BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, need_pmap, false); } } static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float *tmin) { if (BKE_pbvh_node_get_tmin(node) < *tmin) { SculptRaycastData *srd = data_v; float(*origco)[3] = NULL; bool use_origco = false; if (srd->original && srd->ss->cache) { if (BKE_pbvh_type(srd->ss->pbvh) == PBVH_BMESH) { use_origco = true; } else { /* intersect with coordinates from before we started stroke */ SculptUndoNode *unode = sculpt_undo_get_node(node); origco = (unode) ? unode->co : NULL; use_origco = origco ? true : false; } } if (BKE_pbvh_node_raycast(srd->ss->pbvh, node, origco, use_origco, srd->ray_start, srd->ray_normal, &srd->depth)) { srd->hit = 1; *tmin = srd->depth; } } } static void sculpt_find_nearest_to_ray_cb(PBVHNode *node, void *data_v, float *tmin) { if (BKE_pbvh_node_get_tmin(node) < *tmin) { SculptFindNearestToRayData *srd = data_v; float(*origco)[3] = NULL; bool use_origco = false; if (srd->original && srd->ss->cache) { if (BKE_pbvh_type(srd->ss->pbvh) == PBVH_BMESH) { use_origco = true; } else { /* intersect with coordinates from before we started stroke */ SculptUndoNode *unode = sculpt_undo_get_node(node); origco = (unode) ? unode->co : NULL; use_origco = origco ? true : false; } } if (BKE_pbvh_node_find_nearest_to_ray(srd->ss->pbvh, node, origco, use_origco, srd->ray_start, srd->ray_normal, &srd->depth, &srd->dist_sq_to_ray)) { srd->hit = 1; *tmin = srd->dist_sq_to_ray; } } } static void sculpt_raycast_detail_cb(PBVHNode *node, void *data_v, float *tmin) { if (BKE_pbvh_node_get_tmin(node) < *tmin) { SculptDetailRaycastData *srd = data_v; if (BKE_pbvh_bmesh_node_raycast_detail( node, srd->ray_start, srd->ray_normal, &srd->depth, &srd->edge_length)) { srd->hit = 1; *tmin = srd->depth; } } } static float sculpt_raycast_init(ViewContext *vc, const float mouse[2], float ray_start[3], float ray_end[3], float ray_normal[3], bool original) { float obimat[4][4]; float dist; Object *ob = vc->obact; RegionView3D *rv3d = vc->ar->regiondata; /* TODO: what if the segment is totally clipped? (return == 0) */ ED_view3d_win_to_segment_clipped( vc->depsgraph, vc->ar, vc->v3d, mouse, ray_start, ray_end, true); invert_m4_m4(obimat, ob->obmat); mul_m4_v3(obimat, ray_start); mul_m4_v3(obimat, ray_end); sub_v3_v3v3(ray_normal, ray_end, ray_start); dist = normalize_v3(ray_normal); if ((rv3d->is_persp == false) && /* if the ray is clipped, don't adjust its start/end */ ((rv3d->rflag & RV3D_CLIPPING) == 0)) { BKE_pbvh_raycast_project_ray_root(ob->sculpt->pbvh, original, ray_start, ray_end, ray_normal); /* recalculate the normal */ sub_v3_v3v3(ray_normal, ray_end, ray_start); dist = normalize_v3(ray_normal); } return dist; } /* Do a raycast in the tree to find the 3d brush location * (This allows us to ignore the GL depth buffer) * Returns 0 if the ray doesn't hit the mesh, non-zero otherwise */ bool sculpt_stroke_get_location(bContext *C, float out[3], const float mouse[2]) { Object *ob; SculptSession *ss; StrokeCache *cache; float ray_start[3], ray_end[3], ray_normal[3], depth; bool original; ViewContext vc; ED_view3d_viewcontext_init(C, &vc); ob = vc.obact; ss = ob->sculpt; cache = ss->cache; original = (cache) ? cache->original : 0; const Brush *brush = BKE_paint_brush(BKE_paint_get_active_from_context(C)); sculpt_stroke_modifiers_check(C, ob, brush); depth = sculpt_raycast_init(&vc, mouse, ray_start, ray_end, ray_normal, original); bool hit = false; { SculptRaycastData srd = { .original = original, .ss = ob->sculpt, .hit = 0, .ray_start = ray_start, .ray_normal = ray_normal, .depth = depth, }; BKE_pbvh_raycast(ss->pbvh, sculpt_raycast_cb, &srd, ray_start, ray_normal, srd.original); if (srd.hit) { hit = true; copy_v3_v3(out, ray_normal); mul_v3_fl(out, srd.depth); add_v3_v3(out, ray_start); } } if (hit == false) { if (ELEM(brush->falloff_shape, PAINT_FALLOFF_SHAPE_TUBE)) { SculptFindNearestToRayData srd = { .original = original, .ss = ob->sculpt, .hit = 0, .ray_start = ray_start, .ray_normal = ray_normal, .depth = FLT_MAX, .dist_sq_to_ray = FLT_MAX, }; BKE_pbvh_find_nearest_to_ray( ss->pbvh, sculpt_find_nearest_to_ray_cb, &srd, ray_start, ray_normal, srd.original); if (srd.hit) { hit = true; copy_v3_v3(out, ray_normal); mul_v3_fl(out, srd.depth); add_v3_v3(out, ray_start); } } } if (cache && hit) { copy_v3_v3(cache->true_location, out); } return hit; } static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession *ss) { Brush *brush = BKE_paint_brush(&sd->paint); MTex *mtex = &brush->mtex; /* init mtex nodes */ if (mtex->tex && mtex->tex->nodetree) { /* has internal flag to detect it only does it once */ ntreeTexBeginExecTree(mtex->tex->nodetree); } /* TODO: Shouldn't really have to do this at the start of every * stroke, but sculpt would need some sort of notification when * changes are made to the texture. */ sculpt_update_tex(scene, sd, ss); } static void sculpt_brush_stroke_init(bContext *C, wmOperator *op) { Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = CTX_data_active_object(C)->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); int mode = RNA_enum_get(op->ptr, "mode"); bool is_smooth; bool need_mask = false; if (brush->sculpt_tool == SCULPT_TOOL_MASK) { need_mask = true; } view3d_operator_needs_opengl(C); sculpt_brush_init_tex(scene, sd, ss); is_smooth = sculpt_any_smooth_mode(brush, NULL, mode); BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, is_smooth, need_mask); } static void sculpt_restore_mesh(Sculpt *sd, Object *ob) { SculptSession *ss = ob->sculpt; Brush *brush = BKE_paint_brush(&sd->paint); /* Restore the mesh before continuing with anchored stroke */ if ((brush->flag & BRUSH_ANCHORED) || (brush->sculpt_tool == SCULPT_TOOL_GRAB && BKE_brush_use_size_pressure(ss->cache->vc->scene, brush)) || (brush->flag & BRUSH_DRAG_DOT)) { paint_mesh_restore_co(sd, ob); } } /* Copy the PBVH bounding box into the object's bounding box */ void sculpt_update_object_bounding_box(Object *ob) { if (ob->runtime.bb) { float bb_min[3], bb_max[3]; BKE_pbvh_bounding_box(ob->sculpt->pbvh, bb_min, bb_max); BKE_boundbox_init_from_minmax(ob->runtime.bb, bb_min, bb_max); } } static void sculpt_flush_update(bContext *C) { Depsgraph *depsgraph = CTX_data_depsgraph(C); Object *ob = CTX_data_active_object(C); Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); SculptSession *ss = ob->sculpt; ARegion *ar = CTX_wm_region(C); bScreen *screen = CTX_wm_screen(C); MultiresModifierData *mmd = ss->multires; if (mmd != NULL) { /* NOTE: SubdivCCG is living in the evaluated object. */ multires_mark_as_modified(ob_eval, MULTIRES_COORDS_MODIFIED); } DEG_id_tag_update(&ob->id, ID_RECALC_SHADING); bool use_shaded_mode = false; if (mmd || (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH)) { /* Multres or dyntopo are drawn directly by EEVEE, * no need for hacks in this case. */ } else { /* We search if an area of the current window is in lookdev/rendered * display mode. In this case, for changes to show up, we need to * tag for ID_RECALC_GEOMETRY. */ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; if (v3d->shading.type > OB_SOLID) { use_shaded_mode = true; } } } } } if (ss->kb || ss->modifiers_active || use_shaded_mode) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); ED_region_tag_redraw(ar); } else { rcti r; BKE_pbvh_update(ss->pbvh, PBVH_UpdateBB, NULL); /* Update the object's bounding box too so that the object * doesn't get incorrectly clipped during drawing in * draw_mesh_object(). [#33790] */ sculpt_update_object_bounding_box(ob); if (sculpt_get_redraw_rect(ar, CTX_wm_region_view3d(C), ob, &r)) { if (ss->cache) { ss->cache->current_r = r; } /* previous is not set in the current cache else * the partial rect will always grow */ sculpt_extend_redraw_rect_previous(ob, &r); r.xmin += ar->winrct.xmin - 2; r.xmax += ar->winrct.xmin + 2; r.ymin += ar->winrct.ymin - 2; r.ymax += ar->winrct.ymin + 2; ss->partial_redraw = 1; ED_region_tag_redraw_partial(ar, &r); } } } /* Returns whether the mouse/stylus is over the mesh (1) * or over the background (0) */ static bool over_mesh(bContext *C, struct wmOperator *UNUSED(op), float x, float y) { float mouse[2], co[3]; mouse[0] = x; mouse[1] = y; return sculpt_stroke_get_location(C, co, mouse); } static bool sculpt_stroke_test_start(bContext *C, struct wmOperator *op, const float mouse[2]) { /* Don't start the stroke until mouse goes over the mesh. * note: mouse will only be null when re-executing the saved stroke. * We have exception for 'exec' strokes since they may not set 'mouse', * only 'location', see: T52195. */ if (((op->flag & OP_IS_INVOKE) == 0) || (mouse == NULL) || over_mesh(C, op, mouse[0], mouse[1])) { Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; Sculpt *sd = CTX_data_tool_settings(C)->sculpt; ED_view3d_init_mats_rv3d(ob, CTX_wm_region_view3d(C)); sculpt_update_cache_invariants(C, sd, ss, op, mouse); sculpt_undo_push_begin(sculpt_tool_name(sd)); return 1; } else { return 0; } } static void sculpt_stroke_update_step(bContext *C, struct PaintStroke *UNUSED(stroke), PointerRNA *itemptr) { UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; const Brush *brush = BKE_paint_brush(&sd->paint); sculpt_stroke_modifiers_check(C, ob, brush); sculpt_update_cache_variants(C, sd, ob, itemptr); sculpt_restore_mesh(sd, ob); if (sd->flags & (SCULPT_DYNTOPO_DETAIL_CONSTANT | SCULPT_DYNTOPO_DETAIL_MANUAL)) { float object_space_constant_detail = 1.0f / (sd->constant_detail * mat4_to_scale(ob->obmat)); BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail); } else if (sd->flags & SCULPT_DYNTOPO_DETAIL_BRUSH) { BKE_pbvh_bmesh_detail_size_set(ss->pbvh, ss->cache->radius * sd->detail_percent / 100.0f); } else { BKE_pbvh_bmesh_detail_size_set(ss->pbvh, (ss->cache->radius / (float)ups->pixel_radius) * (float)(sd->detail_size * U.pixelsize) / 0.4f); } if (sculpt_stroke_is_dynamic_topology(ss, brush)) { do_symmetrical_brush_actions(sd, ob, sculpt_topology_update, ups); } do_symmetrical_brush_actions(sd, ob, do_brush_action, ups); sculpt_combine_proxies(sd, ob); /* hack to fix noise texture tearing mesh */ sculpt_fix_noise_tear(sd, ob); /* TODO(sergey): This is not really needed for the solid shading, * which does use pBVH drawing anyway, but texture and wireframe * requires this. * * Could be optimized later, but currently don't think it's so * much common scenario. * * Same applies to the DEG_id_tag_update() invoked from * sculpt_flush_update(). */ if (ss->modifiers_active) { sculpt_flush_stroke_deform(sd, ob); } else if (ss->kb) { sculpt_update_keyblock(ob); } ss->cache->first_time = false; /* Cleanup */ sculpt_flush_update(C); } static void sculpt_brush_exit_tex(Sculpt *sd) { Brush *brush = BKE_paint_brush(&sd->paint); MTex *mtex = &brush->mtex; if (mtex->tex && mtex->tex->nodetree) { ntreeTexEndExecTree(mtex->tex->nodetree->execdata); } } static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(stroke)) { Main *bmain = CTX_data_main(C); Object *ob = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); SculptSession *ss = ob->sculpt; Sculpt *sd = CTX_data_tool_settings(C)->sculpt; /* Finished */ if (ss->cache) { UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; Brush *brush = BKE_paint_brush(&sd->paint); BLI_assert(brush == ss->cache->brush); /* const, so we shouldn't change. */ ups->draw_inverted = false; sculpt_stroke_modifiers_check(C, ob, brush); /* Alt-Smooth */ if (ss->cache->alt_smooth) { if (brush->sculpt_tool == SCULPT_TOOL_MASK) { brush->mask_tool = ss->cache->saved_mask_brush_tool; } else { BKE_brush_size_set(scene, brush, ss->cache->saved_smooth_size); brush = (Brush *)BKE_libblock_find_name(bmain, ID_BR, ss->cache->saved_active_brush_name); if (brush) { BKE_paint_brush_set(&sd->paint, brush); } } } sculpt_cache_free(ss->cache); ss->cache = NULL; sculpt_undo_push_end(); BKE_pbvh_update(ss->pbvh, PBVH_UpdateOriginalBB, NULL); if (BKE_pbvh_type(ss->pbvh) == PBVH_BMESH) { BKE_pbvh_bmesh_after_stroke(ss->pbvh); } /* optimization: if there is locked key and active modifiers present in */ /* the stack, keyblock is updating at each step. otherwise we could update */ /* keyblock only when stroke is finished */ if (ss->kb && !ss->modifiers_active) { sculpt_update_keyblock(ob); } ss->partial_redraw = 0; /* try to avoid calling this, only for e.g. linked duplicates now */ if (((Mesh *)ob->data)->id.us > 1) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); } sculpt_brush_exit_tex(sd); } static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, const wmEvent *event) { struct PaintStroke *stroke; int ignore_background_click; int retval; sculpt_brush_stroke_init(C, op); stroke = paint_stroke_new(C, op, sculpt_stroke_get_location, sculpt_stroke_test_start, sculpt_stroke_update_step, NULL, sculpt_stroke_done, event->type); op->customdata = stroke; /* For tablet rotation */ ignore_background_click = RNA_boolean_get(op->ptr, "ignore_background_click"); if (ignore_background_click && !over_mesh(C, op, event->x, event->y)) { paint_stroke_data_free(op); return OPERATOR_PASS_THROUGH; } if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) { paint_stroke_data_free(op); return OPERATOR_FINISHED; } /* add modal handler */ WM_event_add_modal_handler(C, op); OPERATOR_RETVAL_CHECK(retval); BLI_assert(retval == OPERATOR_RUNNING_MODAL); return OPERATOR_RUNNING_MODAL; } static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op) { sculpt_brush_stroke_init(C, op); op->customdata = paint_stroke_new(C, op, sculpt_stroke_get_location, sculpt_stroke_test_start, sculpt_stroke_update_step, NULL, sculpt_stroke_done, 0); /* frees op->customdata */ paint_stroke_exec(C, op); return OPERATOR_FINISHED; } static void sculpt_brush_stroke_cancel(bContext *C, wmOperator *op) { Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; Sculpt *sd = CTX_data_tool_settings(C)->sculpt; const Brush *brush = BKE_paint_brush(&sd->paint); /* XXX Canceling strokes that way does not work with dynamic topology, * user will have to do real undo for now. See T46456. */ if (ss->cache && !sculpt_stroke_is_dynamic_topology(ss, brush)) { paint_mesh_restore_co(sd, ob); } paint_stroke_cancel(C, op); if (ss->cache) { sculpt_cache_free(ss->cache); ss->cache = NULL; } sculpt_brush_exit_tex(sd); } static void SCULPT_OT_brush_stroke(wmOperatorType *ot) { /* identifiers */ ot->name = "Sculpt"; ot->idname = "SCULPT_OT_brush_stroke"; ot->description = "Sculpt\nSculpt a stroke into the geometry"; /* api callbacks */ ot->invoke = sculpt_brush_stroke_invoke; ot->modal = paint_stroke_modal; ot->exec = sculpt_brush_stroke_exec; ot->poll = sculpt_poll; ot->cancel = sculpt_brush_stroke_cancel; /* flags (sculpt does own undo? (ton) */ ot->flag = OPTYPE_BLOCKING; /* properties */ paint_stroke_operator_properties(ot); RNA_def_boolean(ot->srna, "ignore_background_click", 0, "Ignore Background Click", "Clicks on the background do not start the stroke"); } /* Reset the copy of the mesh that is being sculpted on (currently just for the layer brush) */ static int sculpt_set_persistent_base_exec(bContext *C, wmOperator *UNUSED(op)) { SculptSession *ss = CTX_data_active_object(C)->sculpt; if (ss) { if (ss->layer_co) { MEM_freeN(ss->layer_co); } ss->layer_co = NULL; } return OPERATOR_FINISHED; } static void SCULPT_OT_set_persistent_base(wmOperatorType *ot) { /* identifiers */ ot->name = "Set Persistent Base"; ot->idname = "SCULPT_OT_set_persistent_base"; ot->description = "Set Persistent Base\nReset the copy of the mesh that is being sculpted on"; /* api callbacks */ ot->exec = sculpt_set_persistent_base_exec; ot->poll = sculpt_mode_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /************************** Dynamic Topology **************************/ static void sculpt_dynamic_topology_triangulate(BMesh *bm) { if (bm->totloop != bm->totface * 3) { BM_mesh_triangulate( bm, MOD_TRIANGULATE_QUAD_BEAUTY, MOD_TRIANGULATE_NGON_EARCLIP, 4, false, NULL, NULL, NULL); } } void sculpt_pbvh_clear(Object *ob) { SculptSession *ss = ob->sculpt; /* Clear out any existing DM and PBVH */ if (ss->pbvh) { BKE_pbvh_free(ss->pbvh); } ss->pbvh = NULL; BKE_object_free_derived_caches(ob); } void sculpt_dyntopo_node_layers_add(SculptSession *ss) { int cd_node_layer_index; char layer_id[] = "_dyntopo_node_id"; cd_node_layer_index = CustomData_get_named_layer_index(&ss->bm->vdata, CD_PROP_INT, layer_id); if (cd_node_layer_index == -1) { BM_data_layer_add_named(ss->bm, &ss->bm->vdata, CD_PROP_INT, layer_id); cd_node_layer_index = CustomData_get_named_layer_index(&ss->bm->vdata, CD_PROP_INT, layer_id); } ss->cd_vert_node_offset = CustomData_get_n_offset( &ss->bm->vdata, CD_PROP_INT, cd_node_layer_index - CustomData_get_layer_index(&ss->bm->vdata, CD_PROP_INT)); ss->bm->vdata.layers[cd_node_layer_index].flag |= CD_FLAG_TEMPORARY; cd_node_layer_index = CustomData_get_named_layer_index(&ss->bm->pdata, CD_PROP_INT, layer_id); if (cd_node_layer_index == -1) { BM_data_layer_add_named(ss->bm, &ss->bm->pdata, CD_PROP_INT, layer_id); cd_node_layer_index = CustomData_get_named_layer_index(&ss->bm->pdata, CD_PROP_INT, layer_id); } ss->cd_face_node_offset = CustomData_get_n_offset( &ss->bm->pdata, CD_PROP_INT, cd_node_layer_index - CustomData_get_layer_index(&ss->bm->pdata, CD_PROP_INT)); ss->bm->pdata.layers[cd_node_layer_index].flag |= CD_FLAG_TEMPORARY; } void sculpt_update_after_dynamic_topology_toggle(Depsgraph *depsgraph, Scene *scene, Object *ob) { Sculpt *sd = scene->toolsettings->sculpt; /* Create the PBVH */ BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, false); WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob); } void sculpt_dynamic_topology_enable_ex(Depsgraph *depsgraph, Scene *scene, Object *ob) { SculptSession *ss = ob->sculpt; Mesh *me = ob->data; const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me); sculpt_pbvh_clear(ob); ss->bm_smooth_shading = (scene->toolsettings->sculpt->flags & SCULPT_DYNTOPO_SMOOTH_SHADING) != 0; /* Dynamic topology doesn't ensure selection state is valid, so remove [#36280] */ BKE_mesh_mselect_clear(me); /* Create triangles-only BMesh */ ss->bm = BM_mesh_create(&allocsize, &((struct BMeshCreateParams){ .use_toolflags = false, })); BM_mesh_bm_from_me(ss->bm, me, (&(struct BMeshFromMeshParams){ .calc_face_normal = true, .use_shapekey = true, .active_shapekey = ob->shapenr, })); sculpt_dynamic_topology_triangulate(ss->bm); BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_PAINT_MASK); sculpt_dyntopo_node_layers_add(ss); /* make sure the data for existing faces are initialized */ if (me->totpoly != ss->bm->totface) { BM_mesh_normals_update(ss->bm); } /* Enable dynamic topology */ me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY; /* Enable logging for undo/redo */ ss->bm_log = BM_log_create(ss->bm); /* Refresh */ sculpt_update_after_dynamic_topology_toggle(depsgraph, scene, ob); } /* Free the sculpt BMesh and BMLog * * If 'unode' is given, the BMesh's data is copied out to the unode * before the BMesh is deleted so that it can be restored from */ void sculpt_dynamic_topology_disable_ex(Depsgraph *depsgraph, Scene *scene, Object *ob, SculptUndoNode *unode) { SculptSession *ss = ob->sculpt; Mesh *me = ob->data; sculpt_pbvh_clear(ob); if (unode) { /* Free all existing custom data */ CustomData_free(&me->vdata, me->totvert); CustomData_free(&me->edata, me->totedge); CustomData_free(&me->fdata, me->totface); CustomData_free(&me->ldata, me->totloop); CustomData_free(&me->pdata, me->totpoly); /* Copy over stored custom data */ me->totvert = unode->bm_enter_totvert; me->totloop = unode->bm_enter_totloop; me->totpoly = unode->bm_enter_totpoly; me->totedge = unode->bm_enter_totedge; me->totface = 0; CustomData_copy(&unode->bm_enter_vdata, &me->vdata, CD_MASK_MESH.vmask, CD_DUPLICATE, unode->bm_enter_totvert); CustomData_copy(&unode->bm_enter_edata, &me->edata, CD_MASK_MESH.emask, CD_DUPLICATE, unode->bm_enter_totedge); CustomData_copy(&unode->bm_enter_ldata, &me->ldata, CD_MASK_MESH.lmask, CD_DUPLICATE, unode->bm_enter_totloop); CustomData_copy(&unode->bm_enter_pdata, &me->pdata, CD_MASK_MESH.pmask, CD_DUPLICATE, unode->bm_enter_totpoly); BKE_mesh_update_customdata_pointers(me, false); } else { BKE_sculptsession_bm_to_me(ob, true); } /* Clear data */ me->flag &= ~ME_SCULPT_DYNAMIC_TOPOLOGY; /* typically valid but with global-undo they can be NULL, [#36234] */ if (ss->bm) { BM_mesh_free(ss->bm); ss->bm = NULL; } if (ss->bm_log) { BM_log_free(ss->bm_log); ss->bm_log = NULL; } BKE_particlesystem_reset_all(ob); BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_OUTDATED); /* Refresh */ sculpt_update_after_dynamic_topology_toggle(depsgraph, scene, ob); } void sculpt_dynamic_topology_disable(bContext *C, SculptUndoNode *unode) { Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); sculpt_dynamic_topology_disable_ex(depsgraph, scene, ob, unode); } static void sculpt_dynamic_topology_disable_with_undo(Depsgraph *depsgraph, Scene *scene, Object *ob) { SculptSession *ss = ob->sculpt; if (ss->bm) { sculpt_undo_push_begin("Dynamic topology disable"); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_END); sculpt_dynamic_topology_disable_ex(depsgraph, scene, ob, NULL); sculpt_undo_push_end(); } } static void sculpt_dynamic_topology_enable_with_undo(Depsgraph *depsgraph, Scene *scene, Object *ob) { SculptSession *ss = ob->sculpt; if (ss->bm == NULL) { sculpt_undo_push_begin("Dynamic topology enable"); sculpt_dynamic_topology_enable_ex(depsgraph, scene, ob); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN); sculpt_undo_push_end(); } } static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; WM_cursor_wait(1); if (ss->bm) { sculpt_dynamic_topology_disable_with_undo(depsgraph, scene, ob); } else { sculpt_dynamic_topology_enable_with_undo(depsgraph, scene, ob); } WM_cursor_wait(0); return OPERATOR_FINISHED; } enum eDynTopoWarnFlag { DYNTOPO_WARN_VDATA = (1 << 0), DYNTOPO_WARN_EDATA = (1 << 1), DYNTOPO_WARN_LDATA = (1 << 2), DYNTOPO_WARN_MODIFIER = (1 << 3), }; static int dyntopo_warning_popup(bContext *C, wmOperatorType *ot, enum eDynTopoWarnFlag flag) { uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("Warning!"), ICON_ERROR); uiLayout *layout = UI_popup_menu_layout(pup); if (flag & (DYNTOPO_WARN_VDATA | DYNTOPO_WARN_EDATA | DYNTOPO_WARN_LDATA)) { const char *msg_error = TIP_("Vertex Data Detected!"); const char *msg = TIP_("Dyntopo will not preserve vertex colors, UVs, or other customdata"); uiItemL(layout, msg_error, ICON_INFO); uiItemL(layout, msg, ICON_NONE); uiItemS(layout); } if (flag & DYNTOPO_WARN_MODIFIER) { const char *msg_error = TIP_("Generative Modifiers Detected!"); const char *msg = TIP_( "Keeping the modifiers will increase polycount when returning to object mode"); uiItemL(layout, msg_error, ICON_INFO); uiItemL(layout, msg, ICON_NONE); uiItemS(layout); } uiItemFullO_ptr(layout, ot, IFACE_("OK"), ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, 0, NULL); UI_popup_menu_end(C, pup); return OPERATOR_INTERFACE; } static enum eDynTopoWarnFlag sculpt_dynamic_topology_check(Scene *scene, Object *ob) { Mesh *me = ob->data; SculptSession *ss = ob->sculpt; enum eDynTopoWarnFlag flag = 0; BLI_assert(ss->bm == NULL); UNUSED_VARS_NDEBUG(ss); for (int i = 0; i < CD_NUMTYPES; i++) { if (!ELEM(i, CD_MVERT, CD_MEDGE, CD_MFACE, CD_MLOOP, CD_MPOLY, CD_PAINT_MASK, CD_ORIGINDEX)) { if (CustomData_has_layer(&me->vdata, i)) { flag |= DYNTOPO_WARN_VDATA; } if (CustomData_has_layer(&me->edata, i)) { flag |= DYNTOPO_WARN_EDATA; } if (CustomData_has_layer(&me->ldata, i)) { flag |= DYNTOPO_WARN_LDATA; } } } { VirtualModifierData virtualModifierData; ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData); /* exception for shape keys because we can edit those */ for (; md; md = md->next) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); if (!modifier_isEnabled(scene, md, eModifierMode_Realtime)) { continue; } if (mti->type == eModifierTypeType_Constructive) { flag |= DYNTOPO_WARN_MODIFIER; break; } } } return flag; } static int sculpt_dynamic_topology_toggle_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; if (!ss->bm) { Scene *scene = CTX_data_scene(C); enum eDynTopoWarnFlag flag = sculpt_dynamic_topology_check(scene, ob); if (flag) { /* The mesh has customdata that will be lost, let the user confirm this is OK */ return dyntopo_warning_popup(C, op->type, flag); } } return sculpt_dynamic_topology_toggle_exec(C, op); } static void SCULPT_OT_dynamic_topology_toggle(wmOperatorType *ot) { /* identifiers */ ot->name = "Dynamic Topology Toggle"; ot->idname = "SCULPT_OT_dynamic_topology_toggle"; ot->description = "Dynamic Topology Toggle\nDynamic topology alters the mesh topology while sculpting"; /* api callbacks */ ot->invoke = sculpt_dynamic_topology_toggle_invoke; ot->exec = sculpt_dynamic_topology_toggle_exec; ot->poll = sculpt_mode_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /************************* SCULPT_OT_optimize *************************/ static int sculpt_optimize_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_active_object(C); sculpt_pbvh_clear(ob); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); return OPERATOR_FINISHED; } static bool sculpt_and_dynamic_topology_poll(bContext *C) { Object *ob = CTX_data_active_object(C); return sculpt_mode_poll(C) && ob->sculpt->bm; } /* The BVH gets less optimal more quickly with dynamic topology than * regular sculpting. There is no doubt more clever stuff we can do to * optimize it on the fly, but for now this gives the user a nicer way * to recalculate it than toggling modes. */ static void SCULPT_OT_optimize(wmOperatorType *ot) { /* identifiers */ ot->name = "Optimize"; ot->idname = "SCULPT_OT_optimize"; ot->description = "Optimize\nRecalculate the sculpt BVH to improve performance"; /* api callbacks */ ot->exec = sculpt_optimize_exec; ot->poll = sculpt_and_dynamic_topology_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /********************* Dynamic topology symmetrize ********************/ static int sculpt_symmetrize_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_active_object(C); const Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = ob->sculpt; /* To simplify undo for symmetrize, all BMesh elements are logged * as deleted, then after symmetrize operation all BMesh elements * are logged as added (as opposed to attempting to store just the * parts that symmetrize modifies) */ sculpt_undo_push_begin("Dynamic topology symmetrize"); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_SYMMETRIZE); BM_log_before_all_removed(ss->bm, ss->bm_log); BM_mesh_toolflags_set(ss->bm, true); /* Symmetrize and re-triangulate */ BMO_op_callf(ss->bm, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), "symmetrize input=%avef direction=%i dist=%f", sd->symmetrize_direction, 0.00001f); sculpt_dynamic_topology_triangulate(ss->bm); /* bisect operator flags edges (keep tags clean for edge queue) */ BM_mesh_elem_hflag_disable_all(ss->bm, BM_EDGE, BM_ELEM_TAG, false); BM_mesh_toolflags_set(ss->bm, false); /* Finish undo */ BM_log_all_added(ss->bm, ss->bm_log); sculpt_undo_push_end(); /* Redraw */ sculpt_pbvh_clear(ob); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); return OPERATOR_FINISHED; } static void SCULPT_OT_symmetrize(wmOperatorType *ot) { /* identifiers */ ot->name = "Symmetrize"; ot->idname = "SCULPT_OT_symmetrize"; ot->description = "Symmetrize\nSymmetrize the topology modifications"; /* api callbacks */ ot->exec = sculpt_symmetrize_exec; ot->poll = sculpt_and_dynamic_topology_poll; } /**** Toggle operator for turning sculpt mode on or off ****/ static void sculpt_init_session(Depsgraph *depsgraph, Scene *scene, Object *ob) { /* Create persistent sculpt mode data */ BKE_sculpt_toolsettings_data_ensure(scene); ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session"); ob->sculpt->mode_type = OB_MODE_SCULPT; BKE_sculpt_update_mesh_elements(depsgraph, scene, scene->toolsettings->sculpt, ob, false, false); } static int ed_object_sculptmode_flush_recalc_flag(Scene *scene, Object *ob, MultiresModifierData *mmd) { int flush_recalc = 0; /* multires in sculpt mode could have different from object mode subdivision level */ flush_recalc |= mmd && mmd->sculptlvl != mmd->lvl; /* if object has got active modifiers, it's dm could be different in sculpt mode */ flush_recalc |= sculpt_has_active_modifiers(scene, ob); return flush_recalc; } void ED_object_sculptmode_enter_ex(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob, const bool force_dyntopo, ReportList *reports) { const int mode_flag = OB_MODE_SCULPT; Mesh *me = BKE_mesh_from_object(ob); /* Enter sculptmode */ ob->mode |= mode_flag; MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob); const int flush_recalc = ed_object_sculptmode_flush_recalc_flag(scene, ob, mmd); if (flush_recalc) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); } /* Create sculpt mode session data */ if (ob->sculpt) { BKE_sculptsession_free(ob); } /* Make sure derived final from original object does not reference possibly * freed memory. */ BKE_object_free_derived_caches(ob); sculpt_init_session(depsgraph, scene, ob); /* Mask layer is required */ if (mmd) { /* XXX, we could attempt to support adding mask data mid-sculpt mode (with multi-res) * but this ends up being quite tricky (and slow) */ BKE_sculpt_mask_layers_ensure(ob, mmd); } if (!(fabsf(ob->scale[0] - ob->scale[1]) < 1e-4f && fabsf(ob->scale[1] - ob->scale[2]) < 1e-4f)) { BKE_report( reports, RPT_WARNING, "Object has non-uniform scale, sculpting may be unpredictable"); } else if (is_negative_m4(ob->obmat)) { BKE_report(reports, RPT_WARNING, "Object has negative scale, sculpting may be unpredictable"); } Paint *paint = BKE_paint_get_active_from_paintmode(scene, PAINT_MODE_SCULPT); BKE_paint_init(bmain, scene, PAINT_MODE_SCULPT, PAINT_CURSOR_SCULPT); paint_cursor_start_explicit(paint, bmain->wm.first, sculpt_poll_view3d); /* Check dynamic-topology flag; re-enter dynamic-topology mode when changing modes, * As long as no data was added that is not supported. */ if (me->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) { const char *message_unsupported = NULL; if (me->totloop != me->totpoly * 3) { message_unsupported = TIP_("non-triangle face"); } else if (mmd != NULL) { message_unsupported = TIP_("multi-res modifier"); } else { enum eDynTopoWarnFlag flag = sculpt_dynamic_topology_check(scene, ob); if (flag == 0) { /* pass */ } else if (flag & DYNTOPO_WARN_VDATA) { message_unsupported = TIP_("vertex data"); } else if (flag & DYNTOPO_WARN_EDATA) { message_unsupported = TIP_("edge data"); } else if (flag & DYNTOPO_WARN_LDATA) { message_unsupported = TIP_("face data"); } else if (flag & DYNTOPO_WARN_MODIFIER) { message_unsupported = TIP_("constructive modifier"); } else { BLI_assert(0); } } if ((message_unsupported == NULL) || force_dyntopo) { /* Needed because we may be entering this mode before the undo system loads. */ wmWindowManager *wm = bmain->wm.first; bool has_undo = wm->undo_stack != NULL; /* undo push is needed to prevent memory leak */ if (has_undo) { sculpt_undo_push_begin("Dynamic topology enable"); } sculpt_dynamic_topology_enable_ex(depsgraph, scene, ob); if (has_undo) { sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN); sculpt_undo_push_end(); } } else { BKE_reportf( reports, RPT_WARNING, "Dynamic Topology found: %s, disabled", message_unsupported); me->flag &= ~ME_SCULPT_DYNAMIC_TOPOLOGY; } } /* Flush object mode. */ DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); } void ED_object_sculptmode_enter(struct bContext *C, ReportList *reports) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = OBACT(view_layer); Depsgraph *depsgraph = CTX_data_depsgraph(C); ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, false, reports); } void ED_object_sculptmode_exit_ex(Depsgraph *depsgraph, Scene *scene, Object *ob) { const int mode_flag = OB_MODE_SCULPT; Mesh *me = BKE_mesh_from_object(ob); MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob); if (mmd) { multires_force_update(ob); } /* Not needed for now. */ #if 0 const int flush_recalc = ed_object_sculptmode_flush_recalc_flag(scene, ob, mmd); #endif /* Always for now, so leaving sculpt mode always ensures scene is in * a consistent state. */ if (true || /* flush_recalc || */ (ob->sculpt && ob->sculpt->bm)) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); } if (me->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) { /* Dynamic topology must be disabled before exiting sculpt * mode to ensure the undo stack stays in a consistent * state */ sculpt_dynamic_topology_disable_with_undo(depsgraph, scene, ob); /* store so we know to re-enable when entering sculpt mode */ me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY; } /* Leave sculptmode */ ob->mode &= ~mode_flag; BKE_sculptsession_free(ob); paint_cursor_delete_textures(); /* Never leave derived meshes behind. */ BKE_object_free_derived_caches(ob); /* Flush object mode. */ DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); } void ED_object_sculptmode_exit(bContext *C) { Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = OBACT(view_layer); ED_object_sculptmode_exit_ex(depsgraph, scene, ob); } static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) { struct wmMsgBus *mbus = CTX_wm_message_bus(C); Main *bmain = CTX_data_main(C); Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = OBACT(view_layer); const int mode_flag = OB_MODE_SCULPT; const bool is_mode_set = (ob->mode & mode_flag) != 0; if (!is_mode_set) { if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { return OPERATOR_CANCELLED; } } if (is_mode_set) { ED_object_sculptmode_exit_ex(depsgraph, scene, ob); } else { ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, false, op->reports); BKE_paint_toolslots_brush_validate(bmain, &ts->sculpt->paint); } WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene); WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode); WM_toolsystem_update_from_context_view3d(C); return OPERATOR_FINISHED; } static void SCULPT_OT_sculptmode_toggle(wmOperatorType *ot) { /* identifiers */ ot->name = "Sculpt Mode"; ot->idname = "SCULPT_OT_sculptmode_toggle"; ot->description = "Sculpt Mode\nToggle sculpt mode in 3D view"; /* api callbacks */ ot->exec = sculpt_mode_toggle_exec; ot->poll = ED_operator_object_active_editable_mesh; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; } static bool sculpt_and_constant_or_manual_detail_poll(bContext *C) { Object *ob = CTX_data_active_object(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; return sculpt_mode_poll(C) && ob->sculpt->bm && (sd->flags & (SCULPT_DYNTOPO_DETAIL_CONSTANT | SCULPT_DYNTOPO_DETAIL_MANUAL)); } static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *UNUSED(op)) { Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; float size; float bb_min[3], bb_max[3], center[3], dim[3]; int i, totnodes; PBVHNode **nodes; BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnodes); if (!totnodes) { return OPERATOR_CANCELLED; } for (i = 0; i < totnodes; i++) { BKE_pbvh_node_mark_topology_update(nodes[i]); } /* get the bounding box, it's center and size */ BKE_pbvh_bounding_box(ob->sculpt->pbvh, bb_min, bb_max); add_v3_v3v3(center, bb_min, bb_max); mul_v3_fl(center, 0.5f); sub_v3_v3v3(dim, bb_max, bb_min); size = max_fff(dim[0], dim[1], dim[2]); /* update topology size */ float object_space_constant_detail = 1.0f / (sd->constant_detail * mat4_to_scale(ob->obmat)); BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail); sculpt_undo_push_begin("Dynamic topology flood fill"); sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_COORDS); while (BKE_pbvh_bmesh_update_topology( ss->pbvh, PBVH_Collapse | PBVH_Subdivide, center, NULL, size, false, false)) { for (i = 0; i < totnodes; i++) { BKE_pbvh_node_mark_topology_update(nodes[i]); } } MEM_freeN(nodes); sculpt_undo_push_end(); /* force rebuild of pbvh for better BB placement */ sculpt_pbvh_clear(ob); /* Redraw */ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); return OPERATOR_FINISHED; } static void SCULPT_OT_detail_flood_fill(wmOperatorType *ot) { /* identifiers */ ot->name = "Detail Flood Fill"; ot->idname = "SCULPT_OT_detail_flood_fill"; ot->description = "Detail Flood Fill\nFlood fill the mesh with the selected detail setting"; /* api callbacks */ ot->exec = sculpt_detail_flood_fill_exec; ot->poll = sculpt_and_constant_or_manual_detail_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static void sample_detail(bContext *C, int mx, int my) { /* Find 3D view to pick from. */ bScreen *screen = CTX_wm_screen(C); ScrArea *sa = BKE_screen_find_area_xy(screen, SPACE_VIEW3D, mx, my); ARegion *ar = (sa) ? BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my) : NULL; if (ar == NULL) { return; } /* Set context to 3D view. */ ScrArea *prev_sa = CTX_wm_area(C); ARegion *prev_ar = CTX_wm_region(C); CTX_wm_area_set(C, sa); CTX_wm_region_set(C, ar); ViewContext vc; ED_view3d_viewcontext_init(C, &vc); /* Pick sample detail. */ Sculpt *sd = CTX_data_tool_settings(C)->sculpt; Object *ob = vc.obact; Brush *brush = BKE_paint_brush(&sd->paint); sculpt_stroke_modifiers_check(C, ob, brush); float mouse[2] = {mx - ar->winrct.xmin, my - ar->winrct.ymin}; float ray_start[3], ray_end[3], ray_normal[3]; float depth = sculpt_raycast_init(&vc, mouse, ray_start, ray_end, ray_normal, false); SculptDetailRaycastData srd; srd.hit = 0; srd.ray_start = ray_start; srd.ray_normal = ray_normal; srd.depth = depth; srd.edge_length = 0.0f; BKE_pbvh_raycast(ob->sculpt->pbvh, sculpt_raycast_detail_cb, &srd, ray_start, ray_normal, false); if (srd.hit && srd.edge_length > 0.0f) { /* Convert edge length to world space detail resolution. */ sd->constant_detail = 1 / (srd.edge_length * mat4_to_scale(ob->obmat)); } /* Restore context. */ CTX_wm_area_set(C, prev_sa); CTX_wm_region_set(C, prev_ar); } static int sculpt_sample_detail_size_exec(bContext *C, wmOperator *op) { int ss_co[2]; RNA_int_get_array(op->ptr, "location", ss_co); sample_detail(C, ss_co[0], ss_co[1]); return OPERATOR_FINISHED; } static int sculpt_sample_detail_size_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e)) { ED_workspace_status_text(C, "Click on the mesh to set the detail"); WM_cursor_modal_set(CTX_wm_window(C), BC_EYEDROPPER_CURSOR); WM_event_add_modal_handler(C, op); return OPERATOR_RUNNING_MODAL; } static int sculpt_sample_detail_size_modal(bContext *C, wmOperator *op, const wmEvent *event) { switch (event->type) { case LEFTMOUSE: if (event->val == KM_PRESS) { int ss_co[2] = {event->x, event->y}; sample_detail(C, ss_co[0], ss_co[1]); RNA_int_set_array(op->ptr, "location", ss_co); WM_cursor_modal_restore(CTX_wm_window(C)); ED_workspace_status_text(C, NULL); WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL); return OPERATOR_FINISHED; } break; case RIGHTMOUSE: { WM_cursor_modal_restore(CTX_wm_window(C)); ED_workspace_status_text(C, NULL); return OPERATOR_CANCELLED; } } return OPERATOR_RUNNING_MODAL; } static void SCULPT_OT_sample_detail_size(wmOperatorType *ot) { /* identifiers */ ot->name = "Sample Detail Size"; ot->idname = "SCULPT_OT_sample_detail_size"; ot->description = "Sample Detail Size\nSample the mesh detail on clicked point"; /* api callbacks */ ot->invoke = sculpt_sample_detail_size_invoke; ot->exec = sculpt_sample_detail_size_exec; ot->modal = sculpt_sample_detail_size_modal; ot->poll = sculpt_and_constant_or_manual_detail_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_int_array(ot->srna, "location", 2, NULL, 0, SHRT_MAX, "Location", "Screen Coordinates of sampling", 0, SHRT_MAX); } /* Dynamic-topology detail size * * This should be improved further, perhaps by showing a triangle * grid rather than brush alpha */ static void set_brush_rc_props(PointerRNA *ptr, const char *prop) { char *path = BLI_sprintfN("tool_settings.sculpt.brush.%s", prop); RNA_string_set(ptr, "data_path_primary", path); MEM_freeN(path); } static int sculpt_set_detail_size_exec(bContext *C, wmOperator *UNUSED(op)) { Sculpt *sd = CTX_data_tool_settings(C)->sculpt; PointerRNA props_ptr; wmOperatorType *ot = WM_operatortype_find("WM_OT_radial_control", true); WM_operator_properties_create_ptr(&props_ptr, ot); if (sd->flags & (SCULPT_DYNTOPO_DETAIL_CONSTANT | SCULPT_DYNTOPO_DETAIL_MANUAL)) { set_brush_rc_props(&props_ptr, "constant_detail_resolution"); RNA_string_set( &props_ptr, "data_path_primary", "tool_settings.sculpt.constant_detail_resolution"); } else if (sd->flags & SCULPT_DYNTOPO_DETAIL_BRUSH) { set_brush_rc_props(&props_ptr, "constant_detail_resolution"); RNA_string_set(&props_ptr, "data_path_primary", "tool_settings.sculpt.detail_percent"); } else { set_brush_rc_props(&props_ptr, "detail_size"); RNA_string_set(&props_ptr, "data_path_primary", "tool_settings.sculpt.detail_size"); } WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr); WM_operator_properties_free(&props_ptr); return OPERATOR_FINISHED; } static void SCULPT_OT_set_detail_size(wmOperatorType *ot) { /* identifiers */ ot->name = "Set Detail Size"; ot->idname = "SCULPT_OT_set_detail_size"; ot->description = "Set Detail Size\nSet the mesh detail (either relative or constant one, depending on " "current dyntopo mode)"; /* api callbacks */ ot->exec = sculpt_set_detail_size_exec; ot->poll = sculpt_and_dynamic_topology_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } void ED_operatortypes_sculpt(void) { WM_operatortype_append(SCULPT_OT_brush_stroke); WM_operatortype_append(SCULPT_OT_sculptmode_toggle); WM_operatortype_append(SCULPT_OT_set_persistent_base); WM_operatortype_append(SCULPT_OT_dynamic_topology_toggle); WM_operatortype_append(SCULPT_OT_optimize); WM_operatortype_append(SCULPT_OT_symmetrize); WM_operatortype_append(SCULPT_OT_detail_flood_fill); WM_operatortype_append(SCULPT_OT_sample_detail_size); WM_operatortype_append(SCULPT_OT_set_detail_size); }
560396.c
int main() { return (5 + (!!(6 / -2) + 3)) / 2 + 6 * (3 - 2) / 2; }
168836.c
/* * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include <stdint.h> #include <string.h> #include "libavutil/attributes.h" #include "libavutil/avassert.h" #include "rl.h" av_cold void ff_rl_init(RLTable *rl, uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3]) { int8_t max_level[MAX_RUN + 1], max_run[MAX_LEVEL + 1]; uint8_t index_run[MAX_RUN + 1]; int last, run, level, start, end, i; /* If rl->max_level[0] is set, this RLTable has already been initialized */ if (rl->max_level[0]) return; /* compute max_level[], max_run[] and index_run[] */ for (last = 0; last < 2; last++) { if (last == 0) { start = 0; end = rl->last; } else { start = rl->last; end = rl->n; } memset(max_level, 0, MAX_RUN + 1); memset(max_run, 0, MAX_LEVEL + 1); memset(index_run, rl->n, MAX_RUN + 1); for (i = start; i < end; i++) { run = rl->table_run[i]; level = rl->table_level[i]; if (index_run[run] == rl->n) index_run[run] = i; if (level > max_level[run]) max_level[run] = level; if (run > max_run[level]) max_run[level] = run; } rl->max_level[last] = static_store[last]; memcpy(rl->max_level[last], max_level, MAX_RUN + 1); rl->max_run[last] = static_store[last] + MAX_RUN + 1; memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1); rl->index_run[last] = static_store[last] + MAX_RUN + MAX_LEVEL + 2; memcpy(rl->index_run[last], index_run, MAX_RUN + 1); } } av_cold void ff_rl_init_vlc(RLTable *rl, unsigned static_size) { int i, q; VLC_TYPE table[1500][2] = {{0}}; VLC vlc = { .table = table, .table_allocated = static_size }; av_assert0(static_size <= FF_ARRAY_ELEMS(table)); init_vlc(&vlc, 9, rl->n + 1, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC); for (q = 0; q < 32; q++) { int qmul = q * 2; int qadd = (q - 1) | 1; if (!rl->rl_vlc[q]) return; if (q == 0) { qmul = 1; qadd = 0; } for (i = 0; i < vlc.table_size; i++) { int code = vlc.table[i][0]; int len = vlc.table[i][1]; int level, run; if (len == 0) { // illegal code run = 66; level = MAX_LEVEL; } else if (len < 0) { // more bits needed run = 0; level = code; } else { if (code == rl->n) { // esc run = 66; level = 0; } else { run = rl->table_run[code] + 1; level = rl->table_level[code] * qmul + qadd; if (code >= rl->last) run += 192; } } rl->rl_vlc[q][i].len = len; rl->rl_vlc[q][i].level = level; rl->rl_vlc[q][i].run = run; } } }
387226.c
#include <stdlib.h> #include <stdio.h> #include <assert.h> #include "config.h" #include "values.h" #include "gc.h" /* A "space" describes one generation of the generational collector. */ struct space { value *start, *next, *limit; }; /* Either start==NULL (meaning that this generation has not yet been created), or start <= next <= limit. The words in start..next are allocated and initialized, and the words from next..limit are available to allocate. */ #define MAX_SPACES 10 /* how many generations */ #ifndef RATIO #define RATIO 2 /* size of generation i+1 / size of generation i */ /* Using RATIO=2 is faster than larger ratios, empirically */ #endif #ifndef NURSERY_SIZE #define NURSERY_SIZE ((1<<21)/sizeof(value)) /* 2 megabytes */ #endif /* The size of generation 0 (the "nursery") should approximately match the size of the level-2 cache of the machine, according to: Cache Performance of Fast-Allocating Programs, by Marcelo J. R. Goncalves and Andrew W. Appel. 7th Int'l Conf. on Functional Programming and Computer Architecture, pp. 293-305, ACM Press, June 1995. We estimate this as 256 kilobytes (which is the size of the Intel Core i7 per-core L2 cache). http://www.tomshardware.com/reviews/Intel-i7-nehalem-cpu,2041-10.html https://en.wikipedia.org/wiki/Nehalem_(microarchitecture) Notwithstanding those results, empirical measurements show that 2 megabytes works fastest. */ #ifndef DEPTH #define DEPTH 0 /* how much depth-first search to do */ #endif struct heap { /* A heap is an array of generations; generation 0 must be already-created */ struct space spaces[MAX_SPACES]; }; #ifdef DEBUG int in_heap(struct heap *h, value v) { int i; for (i=0; i<MAX_SPACES; i++) if (h->spaces[i].start != NULL) if (h->spaces[i].start <= (value*)v && (value *)v <= h->spaces[i].limit) return 1; return 0; } void printtree(FILE *f, struct heap *h, value v) { if(Is_block(v)) if (in_heap(h,v)) { header_t hd = Field(v,-1); int sz = Wosize_hd(hd); int i; fprintf(f,"%d(", Tag_hd(hd)); for(i=0; i<sz-1; i++) { printtree(f,h,Field(v,i)); fprintf(f,","); } if (i<sz) printtree(f,h,Field(v,i)); fprintf(f,")"); } else { fprintf(f,"%8x",v); } else fprintf(f,"%d",v>>1); } void printroots (FILE *f, struct heap *h, fun_info fi, /* which args contain live roots? */ struct thread_info *ti) /* where's the args array? */ { value *args; int n; uintnat i, *roots; roots = fi+2; n = fi[1]; args = ti->args; for(i = 0; i < n; i++) { fprintf(f,"%d[%8x]:",roots[i],args[roots[i]]); printtree(f, h, args[roots[i]]); fprintf(f,"\n"); } fprintf(f,"\n"); } #endif #define No_scan_tag 251 #define No_scan(t) ((t) >= No_scan_tag) void abort_with(char *s) { fprintf(stderr, s); exit(1); } #define Is_from(from_start, from_limit, v) \ (from_start <= (value*)(v) && (value*)(v) < from_limit) /* Assuming v is a pointer (Is_block(v)), tests whether v points somewhere into the "from-space" defined by from_start and from_limit */ void forward (value *from_start, /* beginning of from-space */ value *from_limit, /* end of from-space */ value **next, /* next available spot in to-space */ value *p, /* location of word to forward */ int depth) /* how much depth-first search to do */ /* What it does: If *p is a pointer, AND it points into from-space, then make *p point at the corresponding object in to-space. If such an object did not already exist, create it at address *next (and increment *next by the size of the object). If *p is not a pointer into from-space, then leave it alone. The depth parameter may be set to 0 for ordinary breadth-first collection. Setting depth to a small integer (perhaps 10) may improve the cache locality of the copied graph. */ { value v = *p; if(Is_block(v)) { if(Is_from(from_start, from_limit, v)) { header_t hd = Hd_val(v); int tag = Tag_hd(hd); if(hd == 0) { /* already forwarded */ *p = Field(v,0); } else { int i; int sz; value *new; sz = Wosize_hd(hd); new = *next+1; *next = new+sz; for(i = -1; i < sz; i++) { Field(new, i) = Field(v, i); } Hd_val(v) = 0; Field(v, 0) = (value)new; *p = (value)new; if (depth>0) for (i=0; i<sz; i++) forward(from_start, from_limit, next, &Field(new,i), depth-1); } } } } void forward_roots (value *from_start, /* beginning of from-space */ value *from_limit, /* end of from-space */ value **next, /* next available spot in to-space */ fun_info fi, /* which args contain live roots? */ struct thread_info *ti) /* where's the args array? */ /* Forward each live root in the args array */ { value *args; int n; uintnat i; const uintnat *roots = fi+2; n = fi[1]; args = ti->args; for(i = 0; i < n; i++) forward(from_start, from_limit, next, args+roots[i], DEPTH); } void do_scan(value *from_start, /* beginning of from-space */ value *from_limit, /* end of from-space */ value *scan, /* start of unforwarded part of to-space */ value **next) /* next available spot in to-space */ /* Forward each word in the to-space between scan and *next. In the process, next may increase, so keep doing it until scan catches up. Leave alone: header words, and "no_scan" (nonpointer) data. */ { value *s; s = scan; while(s < *next) { header_t hd = *s; mlsize_t sz = Wosize_hd(hd); int tag = Tag_hd(hd); if (!No_scan(tag)) { intnat j; for(j = 1; j <= sz; j++) { forward (from_start, from_limit, next, &Field(s, j), DEPTH); } } s += 1+sz; } } void do_generation (struct space *from, /* descriptor of from-space */ struct space *to, /* descriptor of to-space */ fun_info fi, /* which args contain live roots? */ struct thread_info *ti) /* where's the args array? */ /* Copy the live objects out of the "from" space, into the "to" space, using fi and ti to determine the roots of liveness. */ { assert(from->next-from->start <= to->limit-to->next); forward_roots(from->start, from->limit, &to->next, fi, ti); do_scan(from->start, from->limit, to->start, &to->next); from->next=from->start; } #if 0 /* This "gensize" function is only useful if the desired ratio is >2, but empirical measurements show that ratio=2 is better than ratio>2. */ uintnat gensize(uintnat words) /* words is size of one generation; calculate size of the next generation */ { uintnat maxint = 0u-1u; uintnat n,d; /* The next few lines calculate a value "n" that's at least words*2, preferably words*RATIO, and without overflowing the size of an unsigned integer. */ /* minor bug: this assumes sizeof(uintnat)==sizeof(void*)==sizeof(value) */ if (words > maxint/(2*sizeof(value))) abort_with("Next generation would be too big for address space\n"); d = maxint/RATIO; if (words<d) d=words; n = d*RATIO; assert (n >= 2*words); return n; } #endif void create_space(struct space *s, /* which generation to create */ uintnat n) /* size of the generation */ /* malloc an array of words for generation "s", and set s->start and s->next to the beginning, and s->limit to the end. */ { value *p; p = (value *)malloc(n * sizeof(value)); if (p==NULL) abort_with ("Could not create the next generation\n"); /* fprintf(stderr, "Created a generation of %d words\n", n); */ s->start=p; s->next=p; s->limit = p+n; } struct heap *create_heap() /* To create a heap, first malloc the array of space-descriptors, then create only generation 0. */ { int i; struct heap *h = (struct heap *)malloc(sizeof (struct heap)); if (h==NULL) abort_with("Could not create the heap\n"); create_space(h->spaces+0, NURSERY_SIZE); for(i=1; i<MAX_SPACES; i++) { h->spaces[i].start = NULL; h->spaces[i].next = NULL; h->spaces[i].limit = NULL; } return h; } void resume(fun_info fi, struct thread_info *ti) /* When the garbage collector is all done, it does not "return" to the mutator; instead, it uses this function (which does not return) to resume the mutator by invoking the continuation, fi->fun. But first, "resume" informs the mutator of the new values for the alloc and limit pointers. */ { struct heap *h = ti->heap; value *lo, *hi; uintnat num_allocs = fi[0]; assert (h); lo = h->spaces[0].start; hi = h->spaces[0].limit; if (hi-lo < num_allocs) abort_with ("Nursery is too small for function's num_allocs\n"); *ti->alloc = lo; *ti->limit = hi; } void garbage_collect(fun_info fi, struct thread_info *ti) /* See the header file for the interface-spec of this function. */ { struct heap *h = ti->heap; if (h==NULL) { /* If the heap has not yet been initialized, create it and resume */ h = create_heap(); ti->heap = h; resume(fi,ti); return; } else { int i; assert (h->spaces[0].limit == *ti->limit); h->spaces[0].next = *ti->alloc; /* this line is probably unnecessary */ for (i=0; i<MAX_SPACES-1; i++) { /* Starting with the youngest generation, collect each generation into the next-older generation. Usually, when doing that, there will be enough space left in the next-older generation so that we can break the loop by resuming the mutator. */ /* If the next generation does not yet exist, create it */ if (h->spaces[i+1].start==NULL) { int w = h->spaces[i].limit-h->spaces[i].start; create_space(h->spaces+(i+1), RATIO*w); } /* Copy all the objects in generation i, into generation i+1 */ do_generation(h->spaces+i, h->spaces+(i+1), fi, ti); /* If there's enough space in gen i+1 to guarantee that the NEXT collection into i+1 will succeed, we can stop here */ if (h->spaces[i].limit - h->spaces[i].start <= h->spaces[i+1].limit - h->spaces[i+1].next) { resume(fi,ti); return; } } /* If we get to i==MAX_SPACES, that's bad news */ abort_with("Ran out of generations\n"); } /* Can't reach this point */ assert(0); } /* REMARK. The generation-management policy in the garbage_collect function has a potential flaw. Whenever a record is copied, it is promoted to a higher generation. This is generally a good idea. But there is a bounded number of generations. A useful improvement would be: when it's time to collect the oldest generation (and we can tell it's the oldest, at least because create_space() fails), do some reorganization instead of failing. */ void reset_heap (struct heap *h) { int i; for (i=0; i<MAX_SPACES; i++) h->spaces[i].next = h->spaces[i].start; } void free_heap (struct heap *h) { int i; for (i=0; i<MAX_SPACES; i++) { value *p = h->spaces[i].start; if (p!=NULL) free(p); } free (h); }
249053.c
/* * Allwinner SoCs SRAM Controller Driver * * Copyright (C) 2015 Maxime Ripard * * Author: Maxime Ripard <[email protected]> * * This file is licensed under the terms of the GNU General Public * License version 2. This program is licensed "as is" without any * warranty of any kind, whether express or implied. */ #include <linux/debugfs.h> #include <linux/io.h> #include <linux/module.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/soc/sunxi/sunxi_sram.h> struct sunxi_sram_func { char *func; u8 val; u32 reg_val; }; struct sunxi_sram_data { char *name; u8 reg; u8 offset; u8 width; struct sunxi_sram_func *func; struct list_head list; }; struct sunxi_sram_desc { struct sunxi_sram_data data; bool claimed; }; #define SUNXI_SRAM_MAP(_reg_val, _val, _func) \ { \ .func = _func, \ .val = _val, \ .reg_val = _reg_val, \ } #define SUNXI_SRAM_DATA(_name, _reg, _off, _width, ...) \ { \ .name = _name, \ .reg = _reg, \ .offset = _off, \ .width = _width, \ .func = (struct sunxi_sram_func[]){ \ __VA_ARGS__, { } }, \ } static struct sunxi_sram_desc sun4i_a10_sram_a3_a4 = { .data = SUNXI_SRAM_DATA("A3-A4", 0x4, 0x4, 2, SUNXI_SRAM_MAP(0, 0, "cpu"), SUNXI_SRAM_MAP(1, 1, "emac")), }; static struct sunxi_sram_desc sun4i_a10_sram_c1 = { .data = SUNXI_SRAM_DATA("C1", 0x0, 0x0, 31, SUNXI_SRAM_MAP(0, 0, "cpu"), SUNXI_SRAM_MAP(0x7fffffff, 1, "ve")), }; static struct sunxi_sram_desc sun4i_a10_sram_d = { .data = SUNXI_SRAM_DATA("D", 0x4, 0x0, 1, SUNXI_SRAM_MAP(0, 0, "cpu"), SUNXI_SRAM_MAP(1, 1, "usb-otg")), }; static struct sunxi_sram_desc sun50i_a64_sram_c = { .data = SUNXI_SRAM_DATA("C", 0x4, 24, 1, SUNXI_SRAM_MAP(0, 1, "cpu"), SUNXI_SRAM_MAP(1, 0, "de2")), }; static const struct of_device_id sunxi_sram_dt_ids[] = { { .compatible = "allwinner,sun4i-a10-sram-a3-a4", .data = &sun4i_a10_sram_a3_a4.data, }, { .compatible = "allwinner,sun4i-a10-sram-c1", .data = &sun4i_a10_sram_c1.data, }, { .compatible = "allwinner,sun4i-a10-sram-d", .data = &sun4i_a10_sram_d.data, }, { .compatible = "allwinner,sun50i-a64-sram-c", .data = &sun50i_a64_sram_c.data, }, {} }; static struct device *sram_dev; static LIST_HEAD(claimed_sram); static DEFINE_SPINLOCK(sram_lock); static void __iomem *base; static int sunxi_sram_show(struct seq_file *s, void *data) { struct device_node *sram_node, *section_node; const struct sunxi_sram_data *sram_data; const struct of_device_id *match; struct sunxi_sram_func *func; const __be32 *sram_addr_p, *section_addr_p; u32 val; seq_puts(s, "Allwinner sunXi SRAM\n"); seq_puts(s, "--------------------\n\n"); for_each_child_of_node(sram_dev->of_node, sram_node) { sram_addr_p = of_get_address(sram_node, 0, NULL, NULL); seq_printf(s, "sram@%08x\n", be32_to_cpu(*sram_addr_p)); for_each_child_of_node(sram_node, section_node) { match = of_match_node(sunxi_sram_dt_ids, section_node); if (!match) continue; sram_data = match->data; section_addr_p = of_get_address(section_node, 0, NULL, NULL); seq_printf(s, "\tsection@%04x\t(%s)\n", be32_to_cpu(*section_addr_p), sram_data->name); val = readl(base + sram_data->reg); val >>= sram_data->offset; val &= GENMASK(sram_data->width - 1, 0); for (func = sram_data->func; func->func; func++) { seq_printf(s, "\t\t%s%c\n", func->func, func->reg_val == val ? '*' : ' '); } } seq_puts(s, "\n"); } return 0; } DEFINE_SHOW_ATTRIBUTE(sunxi_sram); static inline struct sunxi_sram_desc *to_sram_desc(const struct sunxi_sram_data *data) { return container_of(data, struct sunxi_sram_desc, data); } static const struct sunxi_sram_data *sunxi_sram_of_parse(struct device_node *node, unsigned int *reg_value) { const struct of_device_id *match; const struct sunxi_sram_data *data; struct sunxi_sram_func *func; struct of_phandle_args args; u8 val; int ret; ret = of_parse_phandle_with_fixed_args(node, "allwinner,sram", 1, 0, &args); if (ret) return ERR_PTR(ret); if (!of_device_is_available(args.np)) { ret = -EBUSY; goto err; } val = args.args[0]; match = of_match_node(sunxi_sram_dt_ids, args.np); if (!match) { ret = -EINVAL; goto err; } data = match->data; if (!data) { ret = -EINVAL; goto err; } for (func = data->func; func->func; func++) { if (val == func->val) { if (reg_value) *reg_value = func->reg_val; break; } } if (!func->func) { ret = -EINVAL; goto err; } of_node_put(args.np); return match->data; err: of_node_put(args.np); return ERR_PTR(ret); } int sunxi_sram_claim(struct device *dev) { const struct sunxi_sram_data *sram_data; struct sunxi_sram_desc *sram_desc; unsigned int device; u32 val, mask; if (IS_ERR(base)) return PTR_ERR(base); if (!base) return -EPROBE_DEFER; if (!dev || !dev->of_node) return -EINVAL; sram_data = sunxi_sram_of_parse(dev->of_node, &device); if (IS_ERR(sram_data)) return PTR_ERR(sram_data); sram_desc = to_sram_desc(sram_data); spin_lock(&sram_lock); if (sram_desc->claimed) { spin_unlock(&sram_lock); return -EBUSY; } mask = GENMASK(sram_data->offset + sram_data->width - 1, sram_data->offset); val = readl(base + sram_data->reg); val &= ~mask; writel(val | ((device << sram_data->offset) & mask), base + sram_data->reg); spin_unlock(&sram_lock); return 0; } EXPORT_SYMBOL(sunxi_sram_claim); int sunxi_sram_release(struct device *dev) { const struct sunxi_sram_data *sram_data; struct sunxi_sram_desc *sram_desc; if (!dev || !dev->of_node) return -EINVAL; sram_data = sunxi_sram_of_parse(dev->of_node, NULL); if (IS_ERR(sram_data)) return -EINVAL; sram_desc = to_sram_desc(sram_data); spin_lock(&sram_lock); sram_desc->claimed = false; spin_unlock(&sram_lock); return 0; } EXPORT_SYMBOL(sunxi_sram_release); struct sunxi_sramc_variant { int num_emac_clocks; }; static const struct sunxi_sramc_variant sun4i_a10_sramc_variant = { /* Nothing special */ }; static const struct sunxi_sramc_variant sun8i_h3_sramc_variant = { .num_emac_clocks = 1, }; static const struct sunxi_sramc_variant sun50i_a64_sramc_variant = { .num_emac_clocks = 1, }; static const struct sunxi_sramc_variant sun50i_h616_sramc_variant = { .num_emac_clocks = 2, }; #define SUNXI_SRAM_EMAC_CLOCK_REG 0x30 static bool sunxi_sram_regmap_accessible_reg(struct device *dev, unsigned int reg) { const struct sunxi_sramc_variant *variant; variant = of_device_get_match_data(dev); if (reg < SUNXI_SRAM_EMAC_CLOCK_REG) return false; if (reg > SUNXI_SRAM_EMAC_CLOCK_REG + variant->num_emac_clocks * 4) return false; return true; } static struct regmap_config sunxi_sram_emac_clock_regmap = { .reg_bits = 32, .val_bits = 32, .reg_stride = 4, /* last defined register */ .max_register = SUNXI_SRAM_EMAC_CLOCK_REG + 4, /* other devices have no business accessing other registers */ .readable_reg = sunxi_sram_regmap_accessible_reg, .writeable_reg = sunxi_sram_regmap_accessible_reg, }; static int sunxi_sram_probe(struct platform_device *pdev) { struct resource *res; struct dentry *d; struct regmap *emac_clock; const struct sunxi_sramc_variant *variant; sram_dev = &pdev->dev; variant = of_device_get_match_data(&pdev->dev); if (!variant) return -EINVAL; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(base)) return PTR_ERR(base); of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); d = debugfs_create_file("sram", S_IRUGO, NULL, NULL, &sunxi_sram_fops); if (!d) return -ENOMEM; if (variant->num_emac_clocks > 0) { emac_clock = devm_regmap_init_mmio(&pdev->dev, base, &sunxi_sram_emac_clock_regmap); if (IS_ERR(emac_clock)) return PTR_ERR(emac_clock); } return 0; } static const struct of_device_id sunxi_sram_dt_match[] = { { .compatible = "allwinner,sun4i-a10-sram-controller", .data = &sun4i_a10_sramc_variant, }, { .compatible = "allwinner,sun4i-a10-system-control", .data = &sun4i_a10_sramc_variant, }, { .compatible = "allwinner,sun5i-a13-system-control", .data = &sun4i_a10_sramc_variant, }, { .compatible = "allwinner,sun8i-a23-system-control", .data = &sun4i_a10_sramc_variant, }, { .compatible = "allwinner,sun8i-h3-system-control", .data = &sun8i_h3_sramc_variant, }, { .compatible = "allwinner,sun50i-a64-sram-controller", .data = &sun50i_a64_sramc_variant, }, { .compatible = "allwinner,sun50i-a64-system-control", .data = &sun50i_a64_sramc_variant, }, { .compatible = "allwinner,sun50i-h5-system-control", .data = &sun50i_a64_sramc_variant, }, { .compatible = "allwinner,sun50i-h616-system-control", .data = &sun50i_h616_sramc_variant, }, { }, }; MODULE_DEVICE_TABLE(of, sunxi_sram_dt_match); static struct platform_driver sunxi_sram_driver = { .driver = { .name = "sunxi-sram", .of_match_table = sunxi_sram_dt_match, }, .probe = sunxi_sram_probe, }; module_platform_driver(sunxi_sram_driver); MODULE_AUTHOR("Maxime Ripard <[email protected]>"); MODULE_DESCRIPTION("Allwinner sunXi SRAM Controller Driver"); MODULE_LICENSE("GPL");
546758.c
// zhaixinggong.c 摘星功 based on xiaoyaoyou.c // modified by Venus Oct.1997 // by yucao inherit SKILL; string *dodge_msg = ({ "$n一个「天外摘星」,跃起数尺,躲过了$N这一招。\n", "$n身形向后一纵,使出一招「飘然出尘」,避过了$N的攻击。\n", "$n使出「天狼涉水」,恰好躲过了$N的攻势。\n", "$n一招「织女穿梭」,姿态美妙地躲了开去。\n" }); int valid_enable(string usage) { return (usage == "dodge") || (usage == "move"); } int valid_learn(object me) { return 1; } string query_dodge_msg(string limb) { return dodge_msg[random(sizeof(dodge_msg))]; } int practice_skill(object me) { if( (int)me->query("qi") < 50 ) return notify_fail("你的体力太差了,不能练摘星功。\n"); me->receive_damage("qi", 40); return 1; }
31728.c
/* packet-aim-chatnav.c * Routines for AIM Instant Messenger (OSCAR) dissection * Copyright 2004, Jelmer Vernooij <[email protected]> * * Wireshark - Network traffic analyzer * By Gerald Combs <[email protected]> * Copyright 1998 Gerald Combs * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" #include <epan/packet.h> #include "packet-aim.h" void proto_register_aim_chatnav(void); void proto_reg_handoff_aim_chatnav(void); #define FAMILY_CHAT_NAV 0x000D static const aim_subtype aim_fnac_family_chatnav[] = { { 0x0001, "Error", dissect_aim_snac_error }, { 0x0002, "Request Limits", NULL }, { 0x0003, "Request Exchange", NULL }, { 0x0004, "Request Room Information", NULL }, { 0x0005, "Request Extended Room Information", NULL }, { 0x0006, "Request Member List", NULL }, { 0x0007, "Search Room", NULL }, { 0x0008, "Create", NULL }, { 0x0009, "Info", NULL }, { 0, NULL, NULL } }; /* Initialize the protocol and registered fields */ static int proto_aim_chatnav = -1; static int ett_aim_chatnav = -1; /* Register the protocol with Wireshark */ void proto_register_aim_chatnav(void) { /* Setup list of header fields */ #if 0 /*FIXME*/ static hf_register_info hf[] = { }; #endif /* Setup protocol subtree array */ static gint *ett[] = { &ett_aim_chatnav, }; /* Register the protocol name and description */ proto_aim_chatnav = proto_register_protocol("AIM Chat Navigation", "AIM ChatNav", "aim_chatnav"); /* Required function calls to register the header fields and subtrees used */ /*FIXME proto_register_field_array(proto_aim_chatnav, hf, array_length(hf));*/ proto_register_subtree_array(ett, array_length(ett)); } void proto_reg_handoff_aim_chatnav(void) { aim_init_family(proto_aim_chatnav, ett_aim_chatnav, FAMILY_CHAT_NAV, aim_fnac_family_chatnav); } /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * * Local variables: * c-basic-offset: 8 * tab-width: 8 * indent-tabs-mode: t * End: * * vi: set shiftwidth=8 tabstop=8 noexpandtab: * :indentSize=8:tabSize=8:noTabs=false: */
220999.c
/* $XdotOrg: xc/lib/font/fontfile/fontfile.c,v 1.4 2005/07/03 07:01:00 daniels Exp $ */ /* $Xorg: fontfile.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ /* Copyright 1991, 1998 The Open Group Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ /* $XFree86: xc/lib/font/fontfile/fontfile.c,v 3.21 2003/12/02 19:50:40 dawes Exp $ */ /* * Author: Keith Packard, MIT X Consortium */ /* $NCDXorg: @(#)fontfile.c,v 1.6 1991/07/02 17:00:46 lemke Exp $ */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <X11/fonts/fntfilst.h> #ifdef WIN32 #include <ctype.h> #endif /* * Map FPE functions to renderer functions */ static int FontFileOpenBitmapNCF (FontPathElementPtr fpe, FontPtr *pFont, int flags, FontEntryPtr entry, fsBitmapFormat format, fsBitmapFormatMask fmask, FontPtr non_cachable_font); int FontFileNameCheck (char *name) { #ifndef NCD #if defined(__UNIXOS2__) || defined(WIN32) /* OS/2 uses D:/... as a path name for fonts, so accept this as a valid * path if it starts with a letter and a colon. Same applies for WIN32 */ if (isalpha(*name) && name[1]==':') return TRUE; #endif return *name == '/'; #else return ((strcmp(name, "built-ins") == 0) || (*name == '/')); #endif } int FontFileInitFPE (FontPathElementPtr fpe) { int status; FontDirectoryPtr dir; status = FontFileReadDirectory (fpe->name, &dir); if (status == Successful) { if (dir->nonScalable.used > 0) if (!FontFileRegisterBitmapSource (fpe)) { FontFileFreeFPE (fpe); return AllocError; } fpe->private = (pointer) dir; } return status; } /* ARGSUSED */ int FontFileResetFPE (FontPathElementPtr fpe) { FontDirectoryPtr dir; dir = (FontDirectoryPtr) fpe->private; /* * The reset must fail for bitmap fonts because they get cleared when * the path is set. */ if (FontFileDirectoryChanged (dir)) { /* can't do it, so tell the caller to close and re-open */ return FPEResetFailed; } else { if (dir->nonScalable.used > 0) if (!FontFileRegisterBitmapSource (fpe)) { return FPEResetFailed; } return Successful; } } int FontFileFreeFPE (FontPathElementPtr fpe) { FontFileUnregisterBitmapSource (fpe); FontFileFreeDir ((FontDirectoryPtr) fpe->private); return Successful; } static int transfer_values_to_alias(char *entryname, int entrynamelength, char *resolvedname, char **aliasName, FontScalablePtr vals) { static char aliasname[MAXFONTNAMELEN]; int nameok = 1, len; char lowerName[MAXFONTNAMELEN]; *aliasName = resolvedname; if ((len = strlen(*aliasName)) <= MAXFONTNAMELEN && (entrynamelength < MAXFONTNAMELEN) && FontFileCountDashes (*aliasName, len) == 14) { FontScalableRec tmpVals; FontScalableRec tmpVals2; tmpVals2 = *vals; /* If we're aliasing a scalable name, transfer values from the name into the destination alias, multiplying by matrices that appear in the alias. */ CopyISOLatin1Lowered (lowerName, entryname, entrynamelength); lowerName[entrynamelength] = '\0'; if (FontParseXLFDName(lowerName, &tmpVals, FONT_XLFD_REPLACE_NONE) && !tmpVals.values_supplied && FontParseXLFDName(*aliasName, &tmpVals, FONT_XLFD_REPLACE_NONE)) { double *matrix = 0, tempmatrix[4]; /* Use a matrix iff exactly one is defined */ if ((tmpVals.values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY && !(tmpVals.values_supplied & POINTSIZE_MASK)) matrix = tmpVals.pixel_matrix; else if ((tmpVals.values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY && !(tmpVals.values_supplied & PIXELSIZE_MASK)) matrix = tmpVals.point_matrix; /* If matrix given in the alias, compute new point and/or pixel matrices */ if (matrix) { /* Complete the XLFD name to avoid potential gotchas */ if (FontFileCompleteXLFD(&tmpVals2, &tmpVals2)) { tempmatrix[0] = matrix[0] * tmpVals2.point_matrix[0] + matrix[1] * tmpVals2.point_matrix[2]; tempmatrix[1] = matrix[0] * tmpVals2.point_matrix[1] + matrix[1] * tmpVals2.point_matrix[3]; tempmatrix[2] = matrix[2] * tmpVals2.point_matrix[0] + matrix[3] * tmpVals2.point_matrix[2]; tempmatrix[3] = matrix[2] * tmpVals2.point_matrix[1] + matrix[3] * tmpVals2.point_matrix[3]; tmpVals2.point_matrix[0] = tempmatrix[0]; tmpVals2.point_matrix[1] = tempmatrix[1]; tmpVals2.point_matrix[2] = tempmatrix[2]; tmpVals2.point_matrix[3] = tempmatrix[3]; tempmatrix[0] = matrix[0] * tmpVals2.pixel_matrix[0] + matrix[1] * tmpVals2.pixel_matrix[2]; tempmatrix[1] = matrix[0] * tmpVals2.pixel_matrix[1] + matrix[1] * tmpVals2.pixel_matrix[3]; tempmatrix[2] = matrix[2] * tmpVals2.pixel_matrix[0] + matrix[3] * tmpVals2.pixel_matrix[2]; tempmatrix[3] = matrix[2] * tmpVals2.pixel_matrix[1] + matrix[3] * tmpVals2.pixel_matrix[3]; tmpVals2.pixel_matrix[0] = tempmatrix[0]; tmpVals2.pixel_matrix[1] = tempmatrix[1]; tmpVals2.pixel_matrix[2] = tempmatrix[2]; tmpVals2.pixel_matrix[3] = tempmatrix[3]; tmpVals2.values_supplied = (tmpVals2.values_supplied & ~(PIXELSIZE_MASK | POINTSIZE_MASK)) | PIXELSIZE_ARRAY | POINTSIZE_ARRAY; } else nameok = 0; } CopyISOLatin1Lowered (aliasname, *aliasName, len + 1); if (nameok && FontParseXLFDName(aliasname, &tmpVals2, FONT_XLFD_REPLACE_VALUE)) /* Return a version of the aliasname that has had the vals stuffed into it. To avoid memory leak, this alias name lives in a static buffer. The caller needs to be done with this buffer before this procedure is called again to avoid reentrancy problems. */ *aliasName = aliasname; } } return nameok; } /* ARGSUSED */ int FontFileOpenFont (pointer client, FontPathElementPtr fpe, Mask flags, char *name, int namelen, fsBitmapFormat format, fsBitmapFormatMask fmask, XID id, FontPtr *pFont, char **aliasName, FontPtr non_cachable_font) { FontDirectoryPtr dir; char lowerName[MAXFONTNAMELEN]; char fileName[MAXFONTFILENAMELEN*2 + 1]; FontNameRec tmpName; FontEntryPtr entry; FontScalableRec vals; FontScalableEntryPtr scalable; FontScaledPtr scaled; FontBitmapEntryPtr bitmap; int ret; Bool noSpecificSize; int nranges; fsRange *ranges; if (namelen >= MAXFONTNAMELEN) return AllocError; dir = (FontDirectoryPtr) fpe->private; /* Match non-scalable pattern */ CopyISOLatin1Lowered (lowerName, name, namelen); lowerName[namelen] = '\0'; ranges = FontParseRanges(lowerName, &nranges); tmpName.name = lowerName; tmpName.length = namelen; tmpName.ndashes = FontFileCountDashes (lowerName, namelen); if (!FontParseXLFDName(lowerName, &vals, FONT_XLFD_REPLACE_NONE)) bzero(&vals, sizeof(vals)); if (!(entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName)) && tmpName.ndashes == 14 && FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO)) { tmpName.length = strlen(lowerName); entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName); } if (entry) { switch (entry->type) { case FONT_ENTRY_BITMAP: bitmap = &entry->u.bitmap; if (bitmap->pFont) { *pFont = bitmap->pFont; (*pFont)->fpe = fpe; ret = Successful; } else { ret = FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask, non_cachable_font); if (ret == Successful && *pFont) (*pFont)->fpe = fpe; } break; case FONT_ENTRY_ALIAS: vals.nranges = nranges; vals.ranges = ranges; transfer_values_to_alias(entry->name.name, entry->name.length, entry->u.alias.resolved, aliasName, &vals); ret = FontNameAlias; break; #ifdef NOTYET case FONT_ENTRY_BC: bc = &entry->u.bc; entry = bc->entry; ret = (*scalable->renderer->OpenScalable) (fpe, pFont, flags, entry, &bc->vals, format, fmask, non_cachable_font); if (ret == Successful && *pFont) (*pFont)->fpe = fpe; break; #endif default: ret = BadFontName; } } else { ret = BadFontName; } if (ret != BadFontName) { if (ranges) xfree(ranges); return ret; } /* Match XLFD patterns */ CopyISOLatin1Lowered (lowerName, name, namelen); lowerName[namelen] = '\0'; tmpName.name = lowerName; tmpName.length = namelen; tmpName.ndashes = FontFileCountDashes (lowerName, namelen); if (!FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO) || !(tmpName.length = strlen (lowerName), entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals))) { CopyISOLatin1Lowered (lowerName, name, namelen); lowerName[namelen] = '\0'; tmpName.name = lowerName; tmpName.length = namelen; tmpName.ndashes = FontFileCountDashes (lowerName, namelen); entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals); if (entry) { strcpy(lowerName, entry->name.name); tmpName.name = lowerName; tmpName.length = entry->name.length; tmpName.ndashes = entry->name.ndashes; } } if (entry) { noSpecificSize = FALSE; /* TRUE breaks XLFD enhancements */ if (entry->type == FONT_ENTRY_SCALABLE && FontFileCompleteXLFD (&vals, &entry->u.scalable.extra->defaults)) { scalable = &entry->u.scalable; if ((vals.values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY || (vals.values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY || (vals.values_supplied & ~SIZE_SPECIFY_MASK & ~CHARSUBSET_SPECIFIED)) scaled = 0; else scaled = FontFileFindScaledInstance (entry, &vals, noSpecificSize); /* * A scaled instance can occur one of two ways: * * Either the font has been scaled to this * size already, in which case scaled->pFont * will point at that font. * * Or a bitmap instance in this size exists, * which is handled as if we got a pattern * matching the bitmap font name. */ if (scaled) { if (scaled->pFont) { *pFont = scaled->pFont; (*pFont)->fpe = fpe; ret = Successful; } else if (scaled->bitmap) { entry = scaled->bitmap; bitmap = &entry->u.bitmap; if (bitmap->pFont) { *pFont = bitmap->pFont; (*pFont)->fpe = fpe; ret = Successful; } else { ret = FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask, non_cachable_font); if (ret == Successful && *pFont) (*pFont)->fpe = fpe; } } else /* "cannot" happen */ { ret = BadFontName; } } else { ret = FontFileMatchBitmapSource (fpe, pFont, flags, entry, &tmpName, &vals, format, fmask, noSpecificSize); if (ret != Successful) { char origName[MAXFONTNAMELEN]; CopyISOLatin1Lowered (origName, name, namelen); origName[namelen] = '\0'; /* Pass the original XLFD name in the vals structure; the rasterizer is free to examine it for hidden meanings. This information will not be saved in the scaled-instances table. */ vals.xlfdName = origName; vals.ranges = ranges; vals.nranges = nranges; if (strlen(dir->directory) + strlen(scalable->fileName) >= sizeof(fileName)) { ret = BadFontName; } else { strcpy (fileName, dir->directory); strcat (fileName, scalable->fileName); if (scalable->renderer->OpenScalable) { ret = (*scalable->renderer->OpenScalable) (fpe, pFont, flags, entry, fileName, &vals, format, fmask, non_cachable_font); } else if (scalable->renderer->OpenBitmap) { ret = (*scalable->renderer->OpenBitmap) (fpe, pFont, flags, entry, fileName, format, fmask, non_cachable_font); } } /* In case rasterizer does something bad because of charset subsetting... */ if (ret == Successful && ((*pFont)->info.firstCol > (*pFont)->info.lastCol || (*pFont)->info.firstRow > (*pFont)->info.lastRow)) { (*(*pFont)->unload_font)(*pFont); ret = BadFontName; } /* Save the instance */ if (ret == Successful) { if (FontFileAddScaledInstance (entry, &vals, *pFont, (char *) 0)) ranges = 0; else (*pFont)->fpePrivate = (pointer) 0; (*pFont)->fpe = fpe; } } } } } else ret = BadFontName; if (ranges) xfree(ranges); return ret; } /* ARGSUSED */ void FontFileCloseFont (FontPathElementPtr fpe, FontPtr pFont) { FontEntryPtr entry; if ((entry = (FontEntryPtr) pFont->fpePrivate)) { switch (entry->type) { case FONT_ENTRY_SCALABLE: FontFileRemoveScaledInstance (entry, pFont); break; case FONT_ENTRY_BITMAP: entry->u.bitmap.pFont = 0; break; default: /* "cannot" happen */ break; } pFont->fpePrivate = 0; } (*pFont->unload_font) (pFont); } static int FontFileOpenBitmapNCF (FontPathElementPtr fpe, FontPtr *pFont, int flags, FontEntryPtr entry, fsBitmapFormat format, fsBitmapFormatMask fmask, FontPtr non_cachable_font) { FontBitmapEntryPtr bitmap; char fileName[MAXFONTFILENAMELEN*2+1]; int ret; FontDirectoryPtr dir; dir = (FontDirectoryPtr) fpe->private; bitmap = &entry->u.bitmap; if(!bitmap || !bitmap->renderer->OpenBitmap) return BadFontName; if (strlen(dir->directory) + strlen(bitmap->fileName) >= sizeof(fileName)) return BadFontName; strcpy (fileName, dir->directory); strcat (fileName, bitmap->fileName); ret = (*bitmap->renderer->OpenBitmap) (fpe, pFont, flags, entry, fileName, format, fmask, non_cachable_font); if (ret == Successful) { bitmap->pFont = *pFont; (*pFont)->fpePrivate = (pointer) entry; } return ret; } int FontFileOpenBitmap (FontPathElementPtr fpe, FontPtr *pFont, int flags, FontEntryPtr entry, fsBitmapFormat format, fsBitmapFormatMask fmask) { return FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask, (FontPtr)0); } static int FontFileGetInfoBitmap (FontPathElementPtr fpe, FontInfoPtr pFontInfo, FontEntryPtr entry) { FontBitmapEntryPtr bitmap; char fileName[MAXFONTFILENAMELEN*2+1]; int ret; FontDirectoryPtr dir; dir = (FontDirectoryPtr) fpe->private; bitmap = &entry->u.bitmap; if (!bitmap || !bitmap->renderer->GetInfoBitmap) return BadFontName; if (strlen(dir->directory) + strlen(bitmap->fileName) >= sizeof(fileName)) return BadFontName; strcpy (fileName, dir->directory); strcat (fileName, bitmap->fileName); ret = (*bitmap->renderer->GetInfoBitmap) (fpe, pFontInfo, entry, fileName); return ret; } static void _FontFileAddScalableNames(FontNamesPtr names, FontNamesPtr scaleNames, FontNamePtr nameptr, char *zeroChars, FontScalablePtr vals, fsRange *ranges, int nranges, int *max) { int i; FontScalableRec zeroVals, tmpVals; for (i = 0; i < scaleNames->nnames; i++) { char nameChars[MAXFONTNAMELEN]; if (!*max) return; FontParseXLFDName (scaleNames->names[i], &zeroVals, FONT_XLFD_REPLACE_NONE); tmpVals = *vals; if (FontFileCompleteXLFD (&tmpVals, &zeroVals)) { --*max; strcpy (nameChars, scaleNames->names[i]); if ((vals->values_supplied & PIXELSIZE_MASK) || !(vals->values_supplied & PIXELSIZE_WILDCARD) || vals->y == 0) { tmpVals.values_supplied = (tmpVals.values_supplied & ~PIXELSIZE_MASK) | (vals->values_supplied & PIXELSIZE_MASK); tmpVals.pixel_matrix[0] = vals->pixel_matrix[0]; tmpVals.pixel_matrix[1] = vals->pixel_matrix[1]; tmpVals.pixel_matrix[2] = vals->pixel_matrix[2]; tmpVals.pixel_matrix[3] = vals->pixel_matrix[3]; } if ((vals->values_supplied & POINTSIZE_MASK) || !(vals->values_supplied & POINTSIZE_WILDCARD) || vals->y == 0) { tmpVals.values_supplied = (tmpVals.values_supplied & ~POINTSIZE_MASK) | (vals->values_supplied & POINTSIZE_MASK); tmpVals.point_matrix[0] = vals->point_matrix[0]; tmpVals.point_matrix[1] = vals->point_matrix[1]; tmpVals.point_matrix[2] = vals->point_matrix[2]; tmpVals.point_matrix[3] = vals->point_matrix[3]; } if (vals->width <= 0) tmpVals.width = 0; if (vals->x == 0) tmpVals.x = 0; if (vals->y == 0) tmpVals.y = 0; tmpVals.ranges = ranges; tmpVals.nranges = nranges; FontParseXLFDName (nameChars, &tmpVals, FONT_XLFD_REPLACE_VALUE); /* If we're marking aliases with negative lengths, we need to concoct a valid target name to follow it. Otherwise we're done. */ if (scaleNames->length[i] >= 0) { (void) AddFontNamesName (names, nameChars, strlen (nameChars)); /* If our original pattern matches the name from the table and that name doesn't duplicate what we just added, add the name from the table */ if (strcmp(nameChars, scaleNames->names[i]) && FontFileMatchName(scaleNames->names[i], scaleNames->length[i], nameptr) && *max) { --*max; (void) AddFontNamesName (names, scaleNames->names[i], scaleNames->length[i]); } } else { char *aliasName; vals->ranges = ranges; vals->nranges = nranges; if (transfer_values_to_alias(zeroChars, strlen(zeroChars), scaleNames->names[++i], &aliasName, vals)) { (void) AddFontNamesName (names, nameChars, strlen (nameChars)); names->length[names->nnames - 1] = -names->length[names->nnames - 1]; (void) AddFontNamesName (names, aliasName, strlen (aliasName)); /* If our original pattern matches the name from the table and that name doesn't duplicate what we just added, add the name from the table */ if (strcmp(nameChars, scaleNames->names[i - 1]) && FontFileMatchName(scaleNames->names[i - 1], -scaleNames->length[i - 1], nameptr) && *max) { --*max; (void) AddFontNamesName (names, scaleNames->names[i - 1], -scaleNames->length[i - 1]); names->length[names->nnames - 1] = -names->length[names->nnames - 1]; (void) AddFontNamesName (names, aliasName, strlen (aliasName)); } } } } } } /* ARGSUSED */ static int _FontFileListFonts (pointer client, FontPathElementPtr fpe, char *pat, int len, int max, FontNamesPtr names, int mark_aliases) { FontDirectoryPtr dir; char lowerChars[MAXFONTNAMELEN], zeroChars[MAXFONTNAMELEN]; FontNameRec lowerName; FontNameRec zeroName; FontNamesPtr scaleNames; FontScalableRec vals; fsRange *ranges; int nranges; int result = BadFontName; if (len >= MAXFONTNAMELEN) return AllocError; dir = (FontDirectoryPtr) fpe->private; CopyISOLatin1Lowered (lowerChars, pat, len); lowerChars[len] = '\0'; lowerName.name = lowerChars; lowerName.length = len; lowerName.ndashes = FontFileCountDashes (lowerChars, len); /* Match XLFD patterns */ strcpy (zeroChars, lowerChars); if (lowerName.ndashes == 14 && FontParseXLFDName (zeroChars, &vals, FONT_XLFD_REPLACE_ZERO)) { ranges = FontParseRanges(lowerChars, &nranges); result = FontFileFindNamesInScalableDir (&dir->nonScalable, &lowerName, max, names, (FontScalablePtr)0, (mark_aliases ? LIST_ALIASES_AND_TARGET_NAMES : NORMAL_ALIAS_BEHAVIOR) | IGNORE_SCALABLE_ALIASES, &max); zeroName.name = zeroChars; zeroName.length = strlen (zeroChars); zeroName.ndashes = lowerName.ndashes; /* Look for scalable names and aliases, adding scaled instances of them to the output */ /* Scalable names... */ scaleNames = MakeFontNamesRecord (0); if (!scaleNames) { if (ranges) xfree(ranges); return AllocError; } FontFileFindNamesInScalableDir (&dir->scalable, &zeroName, max, scaleNames, &vals, mark_aliases ? LIST_ALIASES_AND_TARGET_NAMES : NORMAL_ALIAS_BEHAVIOR, (int *)0); _FontFileAddScalableNames(names, scaleNames, &lowerName, zeroChars, &vals, ranges, nranges, &max); FreeFontNames (scaleNames); /* Scalable aliases... */ scaleNames = MakeFontNamesRecord (0); if (!scaleNames) { if (ranges) xfree(ranges); return AllocError; } FontFileFindNamesInScalableDir (&dir->nonScalable, &zeroName, max, scaleNames, &vals, mark_aliases ? LIST_ALIASES_AND_TARGET_NAMES : NORMAL_ALIAS_BEHAVIOR, (int *)0); _FontFileAddScalableNames(names, scaleNames, &lowerName, zeroChars, &vals, ranges, nranges, &max); FreeFontNames (scaleNames); if (ranges) xfree(ranges); } else { result = FontFileFindNamesInScalableDir (&dir->nonScalable, &lowerName, max, names, (FontScalablePtr)0, mark_aliases ? LIST_ALIASES_AND_TARGET_NAMES : NORMAL_ALIAS_BEHAVIOR, &max); if (result == Successful) result = FontFileFindNamesInScalableDir (&dir->scalable, &lowerName, max, names, (FontScalablePtr)0, mark_aliases ? LIST_ALIASES_AND_TARGET_NAMES : NORMAL_ALIAS_BEHAVIOR, (int *)0); } return result; } typedef struct _LFWIData { FontNamesPtr names; int current; } LFWIDataRec, *LFWIDataPtr; int FontFileListFonts (pointer client, FontPathElementPtr fpe, char *pat, int len, int max, FontNamesPtr names) { return _FontFileListFonts (client, fpe, pat, len, max, names, 0); } int FontFileStartListFontsWithInfo(pointer client, FontPathElementPtr fpe, char *pat, int len, int max, pointer *privatep) { LFWIDataPtr data; int ret; data = (LFWIDataPtr) xalloc (sizeof *data); if (!data) return AllocError; data->names = MakeFontNamesRecord (0); if (!data->names) { xfree (data); return AllocError; } ret = FontFileListFonts (client, fpe, pat, len, max, data->names); if (ret != Successful) { FreeFontNames (data->names); xfree (data); return ret; } data->current = 0; *privatep = (pointer) data; return Successful; } /* ARGSUSED */ static int FontFileListOneFontWithInfo (pointer client, FontPathElementPtr fpe, char **namep, int *namelenp, FontInfoPtr *pFontInfo) { FontDirectoryPtr dir; char lowerName[MAXFONTNAMELEN]; char fileName[MAXFONTFILENAMELEN*2 + 1]; FontNameRec tmpName; FontEntryPtr entry; FontScalableRec vals; FontScalableEntryPtr scalable; FontScaledPtr scaled; FontBitmapEntryPtr bitmap; int ret; Bool noSpecificSize; int nranges; fsRange *ranges; char *name = *namep; int namelen = *namelenp; if (namelen >= MAXFONTNAMELEN) return AllocError; dir = (FontDirectoryPtr) fpe->private; /* Match non-scalable pattern */ CopyISOLatin1Lowered (lowerName, name, namelen); lowerName[namelen] = '\0'; ranges = FontParseRanges(lowerName, &nranges); tmpName.name = lowerName; tmpName.length = namelen; tmpName.ndashes = FontFileCountDashes (lowerName, namelen); if (!FontParseXLFDName(lowerName, &vals, FONT_XLFD_REPLACE_NONE)) bzero(&vals, sizeof(vals)); if (!(entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName)) && tmpName.ndashes == 14 && FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO)) { tmpName.length = strlen(lowerName); entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName); } if (entry) { switch (entry->type) { case FONT_ENTRY_BITMAP: bitmap = &entry->u.bitmap; if (bitmap->pFont) { *pFontInfo = &bitmap->pFont->info; ret = Successful; } else { ret = FontFileGetInfoBitmap (fpe, *pFontInfo, entry); } break; case FONT_ENTRY_ALIAS: vals.nranges = nranges; vals.ranges = ranges; transfer_values_to_alias(entry->name.name, entry->name.length, entry->u.alias.resolved, namep, &vals); *namelenp = strlen (*namep); ret = FontNameAlias; break; #ifdef NOTYET case FONT_ENTRY_BC: /* no LFWI for this yet */ bc = &entry->u.bc; entry = bc->entry; /* Make a new scaled instance */ if (strlen(dir->directory) + strlen(scalable->fileName) >= sizeof(fileName)) { ret = BadFontName; } else { strcpy (fileName, dir->directory); strcat (fileName, scalable->fileName); ret = (*scalable->renderer->GetInfoScalable) (fpe, *pFontInfo, entry, tmpName, fileName, &bc->vals); } break; #endif default: ret = BadFontName; } } else { ret = BadFontName; } if (ret != BadFontName) { if (ranges) xfree(ranges); return ret; } /* Match XLFD patterns */ CopyISOLatin1Lowered (lowerName, name, namelen); lowerName[namelen] = '\0'; tmpName.name = lowerName; tmpName.length = namelen; tmpName.ndashes = FontFileCountDashes (lowerName, namelen); if (!FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO) || !(tmpName.length = strlen (lowerName), entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals))) { CopyISOLatin1Lowered (lowerName, name, namelen); lowerName[namelen] = '\0'; tmpName.name = lowerName; tmpName.length = namelen; tmpName.ndashes = FontFileCountDashes (lowerName, namelen); entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals); if (entry) { strcpy(lowerName, entry->name.name); tmpName.name = lowerName; tmpName.length = entry->name.length; tmpName.ndashes = entry->name.ndashes; } } if (entry) { noSpecificSize = FALSE; /* TRUE breaks XLFD enhancements */ if (entry && entry->type == FONT_ENTRY_SCALABLE && FontFileCompleteXLFD (&vals, &entry->u.scalable.extra->defaults)) { scalable = &entry->u.scalable; scaled = FontFileFindScaledInstance (entry, &vals, noSpecificSize); /* * A scaled instance can occur one of two ways: * * Either the font has been scaled to this * size already, in which case scaled->pFont * will point at that font. * * Or a bitmap instance in this size exists, * which is handled as if we got a pattern * matching the bitmap font name. */ if (scaled) { if (scaled->pFont) { *pFontInfo = &scaled->pFont->info; ret = Successful; } else if (scaled->bitmap) { entry = scaled->bitmap; bitmap = &entry->u.bitmap; if (bitmap->pFont) { *pFontInfo = &bitmap->pFont->info; ret = Successful; } else { ret = FontFileGetInfoBitmap (fpe, *pFontInfo, entry); } } else /* "cannot" happen */ { ret = BadFontName; } } else { #ifdef NOTDEF /* no special case yet */ ret = FontFileMatchBitmapSource (fpe, pFont, flags, entry, &vals, format, fmask, noSpecificSize); if (ret != Successful) #endif { char origName[MAXFONTNAMELEN]; CopyISOLatin1Lowered (origName, name, namelen); origName[namelen] = '\0'; vals.xlfdName = origName; vals.ranges = ranges; vals.nranges = nranges; /* Make a new scaled instance */ if (strlen(dir->directory) + strlen(scalable->fileName) >= sizeof(fileName)) { ret = BadFontName; } else { strcpy (fileName, dir->directory); strcat (fileName, scalable->fileName); if (scalable->renderer->GetInfoScalable) ret = (*scalable->renderer->GetInfoScalable) (fpe, *pFontInfo, entry, &tmpName, fileName, &vals); else if (scalable->renderer->GetInfoBitmap) ret = (*scalable->renderer->GetInfoBitmap) (fpe, *pFontInfo, entry, fileName); } if (ranges) { xfree(ranges); ranges = NULL; } } } if (ret == Successful) return ret; } CopyISOLatin1Lowered (lowerName, name, namelen); tmpName.length = namelen; } else ret = BadFontName; if (ranges) xfree(ranges); return ret; } int FontFileListNextFontWithInfo(pointer client, FontPathElementPtr fpe, char **namep, int *namelenp, FontInfoPtr *pFontInfo, int *numFonts, pointer private) { LFWIDataPtr data = (LFWIDataPtr) private; int ret; char *name; int namelen; if (data->current == data->names->nnames) { FreeFontNames (data->names); xfree (data); return BadFontName; } name = data->names->names[data->current]; namelen = data->names->length[data->current]; ret = FontFileListOneFontWithInfo (client, fpe, &name, &namelen, pFontInfo); if (ret == BadFontName) ret = AllocError; *namep = name; *namelenp = namelen; ++data->current; *numFonts = data->names->nnames - data->current; return ret; } int FontFileStartListFontsAndAliases(pointer client, FontPathElementPtr fpe, char *pat, int len, int max, pointer *privatep) { LFWIDataPtr data; int ret; data = (LFWIDataPtr) xalloc (sizeof *data); if (!data) return AllocError; data->names = MakeFontNamesRecord (0); if (!data->names) { xfree (data); return AllocError; } ret = _FontFileListFonts (client, fpe, pat, len, max, data->names, 1); if (ret != Successful) { FreeFontNames (data->names); xfree (data); return ret; } data->current = 0; *privatep = (pointer) data; return Successful; } int FontFileListNextFontOrAlias(pointer client, FontPathElementPtr fpe, char **namep, int *namelenp, char **resolvedp, int *resolvedlenp, pointer private) { LFWIDataPtr data = (LFWIDataPtr) private; int ret; char *name; int namelen; if (data->current == data->names->nnames) { FreeFontNames (data->names); xfree (data); return BadFontName; } name = data->names->names[data->current]; namelen = data->names->length[data->current]; /* If this is a real font name... */ if (namelen >= 0) { *namep = name; *namelenp = namelen; ret = Successful; } /* Else if an alias */ else { /* Tell the caller that this is an alias... let him resolve it to see if it's valid */ *namep = name; *namelenp = -namelen; *resolvedp = data->names->names[++data->current]; *resolvedlenp = data->names->length[data->current]; ret = FontNameAlias; } ++data->current; return ret; } void FontFileRegisterLocalFpeFunctions (void) { RegisterFPEFunctions(FontFileNameCheck, FontFileInitFPE, FontFileFreeFPE, FontFileResetFPE, FontFileOpenFont, FontFileCloseFont, FontFileListFonts, FontFileStartListFontsWithInfo, FontFileListNextFontWithInfo, NULL, NULL, NULL, FontFileStartListFontsAndAliases, FontFileListNextFontOrAlias, FontFileEmptyBitmapSource); }
100274.c
/* * FreeRTOS V202002.00 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * http://aws.amazon.com/freertos * http://www.FreeRTOS.org */ /** * @file aws_iot_demo_shadow.c * @brief Demonstrates usage of the Thing Shadow library. * * This program demonstrates the using Shadow documents to toggle a state called * "powerOn" in a remote device. */ /* The config header is always included first. */ #include "iot_config.h" /* Standard includes. */ #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> /* Set up logging for this demo. */ #include "iot_demo_logging.h" /* Platform layer includes. */ #include "platform/iot_clock.h" #include "platform/iot_threads.h" /* MQTT include. */ #include "iot_mqtt.h" /* Shadow include. */ #include "aws_iot_shadow.h" /* JSON utilities include. */ #include "iot_json_utils.h" #include "bsp/bsp.h" static void GetShadow(IotSemaphore_t * pDeltaSemaphore, IotMqttConnection_t mqttConnection, const char * const pThingName, size_t thingNameLength); /** * @cond DOXYGEN_IGNORE * Doxygen should ignore this section. * * Provide default values for undefined configuration settings. */ #ifndef AWS_IOT_DEMO_SHADOW_UPDATE_COUNT #define AWS_IOT_DEMO_SHADOW_UPDATE_COUNT ( 20 ) #endif #ifndef AWS_IOT_DEMO_SHADOW_UPDATE_PERIOD_MS #define AWS_IOT_DEMO_SHADOW_UPDATE_PERIOD_MS ( 3000 ) #endif /** @endcond */ /* Validate Shadow demo configuration settings. */ #if AWS_IOT_DEMO_SHADOW_UPDATE_COUNT <= 0 #error "AWS_IOT_DEMO_SHADOW_UPDATE_COUNT cannot be 0 or negative." #endif #if AWS_IOT_DEMO_SHADOW_UPDATE_PERIOD_MS <= 0 #error "AWS_IOT_DEMO_SHADOW_UPDATE_PERIOD_MS cannot be 0 or negative." #endif /** * @brief The keep-alive interval used for this demo. * * An MQTT ping request will be sent periodically at this interval. */ #define KEEP_ALIVE_SECONDS ( 60 ) /** * @brief The timeout for Shadow and MQTT operations in this demo. */ #define TIMEOUT_MS ( 5000 ) /** * @brief Format string representing a Shadow document with a "desired" state. * * Note the client token, which is required for all Shadow updates. The client * token must be unique at any given time, but may be reused once the update is * completed. For this demo, a timestamp is used for a client token. */ #define SHADOW_DESIRED_JSON \ "{" \ "\"state\":{" \ "\"desired\":{" \ "\"powerOn\":%01d" \ "}" \ "}," \ "\"clientToken\":\"%06lu\"" \ "}" /** * @brief The expected size of #SHADOW_DESIRED_JSON. * * Because all the format specifiers in #SHADOW_DESIRED_JSON include a length, * its full size is known at compile-time. */ #define EXPECTED_DESIRED_JSON_SIZE ( sizeof( SHADOW_DESIRED_JSON ) - 3 ) /** * @brief Format string representing a Shadow document with a "reported" state. * * Note the client token, which is required for all Shadow updates. The client * token must be unique at any given time, but may be reused once the update is * completed. For this demo, a timestamp is used for a client token. */ #define SHADOW_REPORTED_JSON \ "{" \ "\"state\":{" \ "\"reported\":{" \ "\"powerOn\":%01d" \ "}" \ "}," \ "\"clientToken\":\"%06lu\"" \ "}" /** * @brief The expected size of #SHADOW_REPORTED_JSON. * * Because all the format specifiers in #SHADOW_REPORTED_JSON include a length, * its full size is known at compile-time. */ #define EXPECTED_REPORTED_JSON_SIZE ( sizeof( SHADOW_REPORTED_JSON ) - 3 ) /*-----------------------------------------------------------*/ /* Declaration of demo function. */ int RunShadowDemo( bool awsIotMqttMode, const char * pIdentifier, void * pNetworkServerInfo, void * pNetworkCredentialInfo, const IotNetworkInterface_t * pNetworkInterface ); /*-----------------------------------------------------------*/ /** * @brief Parses a key in the "state" section of a Shadow delta document. * * @param[in] pDeltaDocument The Shadow delta document to parse. * @param[in] deltaDocumentLength The length of `pDeltaDocument`. * @param[in] pDeltaKey The key in the delta document to find. Must be NULL-terminated. * @param[out] pDelta Set to the first character in the delta key. * @param[out] pDeltaLength The length of the delta key. * * @return `true` if the given delta key is found; `false` otherwise. */ static bool _getDelta( const char * pDeltaDocument, size_t deltaDocumentLength, const char * pDeltaKey, const char ** pDelta, size_t * pDeltaLength ) { bool stateFound = false, deltaFound = false; const size_t deltaKeyLength = strlen( pDeltaKey ); const char * pState = NULL; size_t stateLength = 0; /* Find the "state" key in the delta document. */ stateFound = IotJsonUtils_FindJsonValue( pDeltaDocument, deltaDocumentLength, "state", 5, &pState, &stateLength ); if( stateFound == true ) { /* Find the delta key within the "state" section. */ deltaFound = IotJsonUtils_FindJsonValue( pState, stateLength, pDeltaKey, deltaKeyLength, pDelta, pDeltaLength ); } else { IotLogWarn( "Failed to find \"state\" in Shadow delta document." ); } return deltaFound; } /*-----------------------------------------------------------*/ /** * @brief Parses the "state" key from the "previous" or "current" sections of a * Shadow updated document. * * @param[in] pUpdatedDocument The Shadow updated document to parse. * @param[in] updatedDocumentLength The length of `pUpdatedDocument`. * @param[in] pSectionKey Either "previous" or "current". Must be NULL-terminated. * @param[out] pState Set to the first character in "state". * @param[out] pStateLength Length of the "state" section. * * @return `true` if the "state" was found; `false` otherwise. */ static bool _getUpdatedState( const char * pUpdatedDocument, size_t updatedDocumentLength, const char * pSectionKey, const char ** pState, size_t * pStateLength ) { bool sectionFound = false, stateFound = false; const size_t sectionKeyLength = strlen( pSectionKey ); const char * pSection = NULL; size_t sectionLength = 0; /* Find the given section in the updated document. */ sectionFound = IotJsonUtils_FindJsonValue( pUpdatedDocument, updatedDocumentLength, pSectionKey, sectionKeyLength, &pSection, &sectionLength ); if( sectionFound == true ) { /* Find the "state" key within the "previous" or "current" section. */ stateFound = IotJsonUtils_FindJsonValue( pSection, sectionLength, "state", 5, pState, pStateLength ); } else { IotLogWarn( "Failed to find section %s in Shadow updated document.", pSectionKey ); } return stateFound; } /*-----------------------------------------------------------*/ /** * @brief Shadow delta callback, invoked when the desired and updates Shadow * states differ. * * This function simulates a device updating its state in response to a Shadow. * * @param[in] pCallbackContext Not used. * @param[in] pCallbackParam The received Shadow delta document. */ static void _shadowDeltaCallback( void * pCallbackContext, AwsIotShadowCallbackParam_t * pCallbackParam ) { bool deltaFound = false; const char * pDelta = NULL; size_t deltaLength = 0; IotSemaphore_t * pDeltaSemaphore = pCallbackContext; int updateDocumentLength = 0; AwsIotShadowError_t updateStatus = AWS_IOT_SHADOW_STATUS_PENDING; AwsIotShadowDocumentInfo_t updateDocument = AWS_IOT_SHADOW_DOCUMENT_INFO_INITIALIZER; /* Stored state. */ static int32_t currentState = 0; static int32_t OldState = 0; int iDelta=0; /* A buffer containing the update document. It has static duration to prevent * it from being placed on the call stack. */ static char pUpdateDocument[ EXPECTED_REPORTED_JSON_SIZE + 1 ] = { 0 }; /* Check if there is a different "powerOn" state in the Shadow. */ deltaFound = _getDelta( pCallbackParam->u.callback.pDocument, pCallbackParam->u.callback.documentLength, "powerOn", &pDelta, &deltaLength ); if( deltaFound == true ) { iDelta = *pDelta - '0'; /* Change the current state based on the value in the delta document. */ if( iDelta < 0 || iDelta > 3 ) { LED1_Off(); LED2_Off(); IotLogInfo( "%.*s changing state from %d to 0.", pCallbackParam->thingNameLength, pCallbackParam->pThingName, currentState ); OldState = currentState; currentState = 0; } else { if(iDelta & 0x01) LED1_On(); else LED1_Off(); if(iDelta & 0x02) LED2_On(); else LED2_Off(); IotLogInfo( "%.*s changing state from %d to iDelta.", pCallbackParam->thingNameLength, pCallbackParam->pThingName, OldState, iDelta ); OldState = currentState; currentState = iDelta; } /* Set the common members to report the new state. */ updateDocument.pThingName = pCallbackParam->pThingName; updateDocument.thingNameLength = pCallbackParam->thingNameLength; updateDocument.u.update.pUpdateDocument = pUpdateDocument; updateDocument.u.update.updateDocumentLength = EXPECTED_REPORTED_JSON_SIZE; /* Generate a Shadow document for the reported state. To keep the client * token within 6 characters, it is modded by 1000000. */ updateDocumentLength = snprintf( pUpdateDocument, EXPECTED_REPORTED_JSON_SIZE + 1, SHADOW_REPORTED_JSON, ( int ) currentState, ( long unsigned ) ( IotClock_GetTimeMs() % 1000000 ) ); if( ( size_t ) updateDocumentLength != EXPECTED_REPORTED_JSON_SIZE ) { IotLogError( "Failed to generate reported state document for Shadow update." ); } else { /* Send the Shadow update. Its result is not checked, as the Shadow updated * callback will report if the Shadow was successfully updated. Because the * Shadow is constantly updated in this demo, the "Keep Subscriptions" flag * is passed to this function. */ updateStatus = AwsIotShadow_Update( pCallbackParam->mqttConnection, &updateDocument, AWS_IOT_SHADOW_FLAG_KEEP_SUBSCRIPTIONS, NULL, NULL ); if( updateStatus != AWS_IOT_SHADOW_STATUS_PENDING ) { IotLogWarn( "%.*s failed to report new state.", pCallbackParam->thingNameLength, pCallbackParam->pThingName ); } else { IotLogInfo( "%.*s sent new state report.", pCallbackParam->thingNameLength, pCallbackParam->pThingName ); } } } else { IotLogWarn( "Failed to parse powerOn state from delta document." ); } /* Post to the delta semaphore to unblock the thread sending Shadow updates. */ IotSemaphore_Post( pDeltaSemaphore ); } /*-----------------------------------------------------------*/ /** * @brief Shadow updated callback, invoked when the Shadow document changes. * * This function reports when a Shadow has been updated. * * @param[in] pCallbackContext Not used. * @param[in] pCallbackParam The received Shadow updated document. */ static void _shadowUpdatedCallback( void * pCallbackContext, AwsIotShadowCallbackParam_t * pCallbackParam ) { bool previousFound = false, currentFound = false; const char * pPrevious = NULL, * pCurrent = NULL; size_t previousLength = 0, currentLength = 0; /* Silence warnings about unused parameters. */ ( void ) pCallbackContext; /* Find the previous Shadow document. */ previousFound = _getUpdatedState( pCallbackParam->u.callback.pDocument, pCallbackParam->u.callback.documentLength, "previous", &pPrevious, &previousLength ); /* Find the current Shadow document. */ currentFound = _getUpdatedState( pCallbackParam->u.callback.pDocument, pCallbackParam->u.callback.documentLength, "current", &pCurrent, &currentLength ); /* Log the previous and current states. */ if( ( previousFound == true ) && ( currentFound == true ) ) { IotLogInfo( "Shadow was updated!\r\n" "Previous: {\"state\":%.*s}\r\n" "Current: {\"state\":%.*s}", previousLength, pPrevious, currentLength, pCurrent ); } else { if( previousFound == false ) { IotLogWarn( "Previous state not found in Shadow updated document." ); } if( currentFound == false ) { IotLogWarn( "Current state not found in Shadow updated document." ); } } } /*-----------------------------------------------------------*/ /** * @brief Initialize the the MQTT library and the Shadow library. * * @return `EXIT_SUCCESS` if all libraries were successfully initialized; * `EXIT_FAILURE` otherwise. */ static int _initializeDemo( void ) { int status = EXIT_SUCCESS; IotMqttError_t mqttInitStatus = IOT_MQTT_SUCCESS; AwsIotShadowError_t shadowInitStatus = AWS_IOT_SHADOW_SUCCESS; /* Flags to track cleanup on error. */ bool mqttInitialized = false; /* Initialize the MQTT library. */ mqttInitStatus = IotMqtt_Init(); if( mqttInitStatus == IOT_MQTT_SUCCESS ) { mqttInitialized = true; } else { status = EXIT_FAILURE; } /* Initialize the Shadow library. */ if( status == EXIT_SUCCESS ) { /* Use the default MQTT timeout. */ shadowInitStatus = AwsIotShadow_Init( 0 ); if( shadowInitStatus != AWS_IOT_SHADOW_SUCCESS ) { status = EXIT_FAILURE; } } /* Clean up on error. */ if( status == EXIT_FAILURE ) { if( mqttInitialized == true ) { IotMqtt_Cleanup(); } } return status; } /*-----------------------------------------------------------*/ /** * @brief Clean up the the MQTT library and the Shadow library. */ static void _cleanupDemo( void ) { AwsIotShadow_Cleanup(); IotMqtt_Cleanup(); } /*-----------------------------------------------------------*/ /** * @brief Establish a new connection to the MQTT server for the Shadow demo. * * @param[in] pIdentifier NULL-terminated MQTT client identifier. The Shadow * demo will use the Thing Name as the client identifier. * @param[in] pNetworkServerInfo Passed to the MQTT connect function when * establishing the MQTT connection. * @param[in] pNetworkCredentialInfo Passed to the MQTT connect function when * establishing the MQTT connection. * @param[in] pNetworkInterface The network interface to use for this demo. * @param[out] pMqttConnection Set to the handle to the new MQTT connection. * * @return `EXIT_SUCCESS` if the connection is successfully established; `EXIT_FAILURE` * otherwise. */ static int _establishMqttConnection( const char * pIdentifier, void * pNetworkServerInfo, void * pNetworkCredentialInfo, const IotNetworkInterface_t * pNetworkInterface, IotMqttConnection_t * pMqttConnection ) { int status = EXIT_SUCCESS; IotMqttError_t connectStatus = IOT_MQTT_STATUS_PENDING; IotMqttNetworkInfo_t networkInfo = IOT_MQTT_NETWORK_INFO_INITIALIZER; IotMqttConnectInfo_t connectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER; if( pIdentifier == NULL ) { IotLogError( "Shadow Thing Name must be provided." ); status = EXIT_FAILURE; } if( status == EXIT_SUCCESS ) { /* Set the members of the network info not set by the initializer. This * struct provided information on the transport layer to the MQTT connection. */ networkInfo.createNetworkConnection = true; networkInfo.u.setup.pNetworkServerInfo = pNetworkServerInfo; networkInfo.u.setup.pNetworkCredentialInfo = pNetworkCredentialInfo; networkInfo.pNetworkInterface = pNetworkInterface; #if ( IOT_MQTT_ENABLE_SERIALIZER_OVERRIDES == 1 ) && defined( IOT_DEMO_MQTT_SERIALIZER ) networkInfo.pMqttSerializer = IOT_DEMO_MQTT_SERIALIZER; #endif /* Set the members of the connection info not set by the initializer. */ connectInfo.awsIotMqttMode = true; connectInfo.cleanSession = true; connectInfo.keepAliveSeconds = KEEP_ALIVE_SECONDS; /* AWS IoT recommends the use of the Thing Name as the MQTT client ID. */ connectInfo.pClientIdentifier = pIdentifier; connectInfo.clientIdentifierLength = ( uint16_t ) strlen( pIdentifier ); IotLogInfo( "Shadow Thing Name is %.*s (length %hu).", connectInfo.clientIdentifierLength, connectInfo.pClientIdentifier, connectInfo.clientIdentifierLength ); /* Establish the MQTT connection. */ connectStatus = IotMqtt_Connect( &networkInfo, &connectInfo, TIMEOUT_MS, pMqttConnection ); if( connectStatus != IOT_MQTT_SUCCESS ) { IotLogError( "MQTT CONNECT returned error %s.", IotMqtt_strerror( connectStatus ) ); status = EXIT_FAILURE; } } return status; } /*-----------------------------------------------------------*/ /** * @brief Set the Shadow callback functions used in this demo. * * @param[in] pDeltaSemaphore Used to synchronize Shadow updates with the delta * callback. * @param[in] mqttConnection The MQTT connection used for Shadows. * @param[in] pThingName The Thing Name for Shadows in this demo. * @param[in] thingNameLength The length of `pThingName`. * * @return `EXIT_SUCCESS` if all Shadow callbacks were set; `EXIT_FAILURE` * otherwise. */ static int _setShadowCallbacks( IotSemaphore_t * pDeltaSemaphore, IotMqttConnection_t mqttConnection, const char * pThingName, size_t thingNameLength ) { int status = EXIT_SUCCESS; AwsIotShadowError_t callbackStatus = AWS_IOT_SHADOW_STATUS_PENDING; AwsIotShadowCallbackInfo_t deltaCallback = AWS_IOT_SHADOW_CALLBACK_INFO_INITIALIZER, updatedCallback = AWS_IOT_SHADOW_CALLBACK_INFO_INITIALIZER; /* Set the functions for callbacks. */ deltaCallback.pCallbackContext = pDeltaSemaphore; deltaCallback.function = _shadowDeltaCallback; updatedCallback.function = _shadowUpdatedCallback; /* Set the delta callback, which notifies of different desired and reported * Shadow states. */ callbackStatus = AwsIotShadow_SetDeltaCallback( mqttConnection, pThingName, thingNameLength, 0, &deltaCallback ); if( callbackStatus == AWS_IOT_SHADOW_SUCCESS ) { /* Set the updated callback, which notifies when a Shadow document is * changed. */ callbackStatus = AwsIotShadow_SetUpdatedCallback( mqttConnection, pThingName, thingNameLength, 0, &updatedCallback ); } if( callbackStatus != AWS_IOT_SHADOW_SUCCESS ) { IotLogError( "Failed to set demo shadow callback, error %s.", AwsIotShadow_strerror( callbackStatus ) ); status = EXIT_FAILURE; } return status; } /*-----------------------------------------------------------*/ /** * @brief Try to delete any Shadow document in the cloud. * * @param[in] mqttConnection The MQTT connection used for Shadows. * @param[in] pThingName The Shadow Thing Name to delete. * @param[in] thingNameLength The length of `pThingName`. */ static void _clearShadowDocument( IotMqttConnection_t mqttConnection, const char * const pThingName, size_t thingNameLength ) { AwsIotShadowError_t deleteStatus = AWS_IOT_SHADOW_STATUS_PENDING; /* Delete any existing Shadow document so that this demo starts with an empty * Shadow. */ deleteStatus = AwsIotShadow_TimedDelete( mqttConnection, pThingName, thingNameLength, 0, TIMEOUT_MS ); /* Check for return values of "SUCCESS" and "NOT FOUND". Both of these values * mean that the Shadow document is now empty. */ if( ( deleteStatus == AWS_IOT_SHADOW_SUCCESS ) || ( deleteStatus == AWS_IOT_SHADOW_NOT_FOUND ) ) { IotLogInfo( "Successfully cleared Shadow of %.*s.", thingNameLength, pThingName ); } else { IotLogWarn( "Shadow of %.*s not cleared.", thingNameLength, pThingName ); } } static void GetShadow(IotSemaphore_t * pDeltaSemaphore, IotMqttConnection_t mqttConnection, const char * const pThingName, size_t thingNameLength) { vTaskDelay(100); } /*-----------------------------------------------------------*/ /** * @brief Send the Shadow updates that will trigger the Shadow callbacks. * * @param[in] pDeltaSemaphore Used to synchronize Shadow updates with the delta * callback. * @param[in] mqttConnection The MQTT connection used for Shadows. * @param[in] pThingName The Thing Name for Shadows in this demo. * @param[in] thingNameLength The length of `pThingName`. * * @return `EXIT_SUCCESS` if all Shadow updates were sent; `EXIT_FAILURE` * otherwise. */ static int _sendShadowUpdates( IotSemaphore_t * pDeltaSemaphore, IotMqttConnection_t mqttConnection, const char * const pThingName, size_t thingNameLength ) { int status = EXIT_SUCCESS; int32_t i = 0, desiredState = 0; AwsIotShadowError_t updateStatus = AWS_IOT_SHADOW_STATUS_PENDING; AwsIotShadowDocumentInfo_t updateDocument = AWS_IOT_SHADOW_DOCUMENT_INFO_INITIALIZER; /* A buffer containing the update document. It has static duration to prevent * it from being placed on the call stack. */ static char pUpdateDocument[ EXPECTED_DESIRED_JSON_SIZE + 1 ] = { 0 }; /* Set the common members of the Shadow update document info. */ updateDocument.pThingName = pThingName; updateDocument.thingNameLength = thingNameLength; updateDocument.u.update.pUpdateDocument = pUpdateDocument; updateDocument.u.update.updateDocumentLength = EXPECTED_DESIRED_JSON_SIZE; /* Publish Shadow updates at a set period. */ for( i = 1; i <= AWS_IOT_DEMO_SHADOW_UPDATE_COUNT; i++ ) { /* Toggle the desired state. */ desiredState = !( desiredState ); /* Generate a Shadow desired state document, using a timestamp for the client * token. To keep the client token within 6 characters, it is modded by 1000000. */ status = snprintf( pUpdateDocument, EXPECTED_DESIRED_JSON_SIZE + 1, SHADOW_DESIRED_JSON, ( int ) desiredState, ( long unsigned ) ( IotClock_GetTimeMs() % 1000000 ) ); /* Check for errors from snprintf. The expected value is the length of * the desired JSON document less the format specifier for the state. */ if( ( size_t ) status != EXPECTED_DESIRED_JSON_SIZE ) { IotLogError( "Failed to generate desired state document for Shadow update" " %d of %d.", i, AWS_IOT_DEMO_SHADOW_UPDATE_COUNT ); status = EXIT_FAILURE; break; } else { status = EXIT_SUCCESS; } IotLogInfo( "Sending Shadow update %d of %d: %s", i, AWS_IOT_DEMO_SHADOW_UPDATE_COUNT, pUpdateDocument ); /* Send the Shadow update. Because the Shadow is constantly updated in * this demo, the "Keep Subscriptions" flag is passed to this function. * Note that this flag only needs to be passed on the first call, but * passing it for subsequent calls is fine. */ updateStatus = AwsIotShadow_TimedUpdate( mqttConnection, &updateDocument, AWS_IOT_SHADOW_FLAG_KEEP_SUBSCRIPTIONS, TIMEOUT_MS ); /* Check the status of the Shadow update. */ if( updateStatus != AWS_IOT_SHADOW_SUCCESS ) { IotLogError( "Failed to send Shadow update %d of %d, error %s.", i, AWS_IOT_DEMO_SHADOW_UPDATE_COUNT, AwsIotShadow_strerror( updateStatus ) ); status = EXIT_FAILURE; break; } else { IotLogInfo( "Successfully sent Shadow update %d of %d.", i, AWS_IOT_DEMO_SHADOW_UPDATE_COUNT ); /* Wait for the delta callback to change its state before continuing. */ if( IotSemaphore_TimedWait( pDeltaSemaphore, TIMEOUT_MS ) == false ) { IotLogError( "Timed out waiting on delta callback to change state." ); status = EXIT_FAILURE; break; } } IotClock_SleepMs( AWS_IOT_DEMO_SHADOW_UPDATE_PERIOD_MS ); } return status; } /*-----------------------------------------------------------*/ /** * @brief The function that runs the Shadow demo, called by the demo runner. * * @param[in] awsIotMqttMode Ignored for the Shadow demo. * @param[in] pIdentifier NULL-terminated Shadow Thing Name. * @param[in] pNetworkServerInfo Passed to the MQTT connect function when * establishing the MQTT connection for Shadows. * @param[in] pNetworkCredentialInfo Passed to the MQTT connect function when * establishing the MQTT connection for Shadows. * @param[in] pNetworkInterface The network interface to use for this demo. * * @return `EXIT_SUCCESS` if the demo completes successfully; `EXIT_FAILURE` otherwise. */ int RunShadowDemo( bool awsIotMqttMode, const char * pIdentifier, void * pNetworkServerInfo, void * pNetworkCredentialInfo, const IotNetworkInterface_t * pNetworkInterface ) { /* Return value of this function and the exit status of this program. */ int status = 0; /* Handle of the MQTT connection used in this demo. */ IotMqttConnection_t mqttConnection = IOT_MQTT_CONNECTION_INITIALIZER; /* Length of Shadow Thing Name. */ size_t thingNameLength = 0; /* Allows the Shadow update function to wait for the delta callback to complete * a state change before continuing. */ IotSemaphore_t deltaSemaphore; /* Flags for tracking which cleanup functions must be called. */ bool librariesInitialized = false, connectionEstablished = false, deltaSemaphoreCreated = false; /* The first parameter of this demo function is not used. Shadows are specific * to AWS IoT, so this value is hardcoded to true whenever needed. */ ( void ) awsIotMqttMode; /* Determine the length of the Thing Name. */ if( pIdentifier != NULL ) { thingNameLength = strlen( pIdentifier ); if( thingNameLength == 0 ) { IotLogError( "The length of the Thing Name (identifier) must be nonzero." ); status = EXIT_FAILURE; } } else { IotLogError( "A Thing Name (identifier) must be provided for the Shadow demo." ); status = EXIT_FAILURE; } /* Initialize the libraries required for this demo. */ if( status == EXIT_SUCCESS ) { status = _initializeDemo(); } if( status == EXIT_SUCCESS ) { /* Mark the libraries as initialized. */ librariesInitialized = true; /* Establish a new MQTT connection. */ status = _establishMqttConnection( pIdentifier, pNetworkServerInfo, pNetworkCredentialInfo, pNetworkInterface, &mqttConnection ); } if( status == EXIT_SUCCESS ) { /* Mark the MQTT connection as established. */ connectionEstablished = true; /* Create the semaphore that synchronizes with the delta callback. */ deltaSemaphoreCreated = IotSemaphore_Create( &deltaSemaphore, 0, 1 ); if( deltaSemaphoreCreated == false ) { status = EXIT_FAILURE; } } if( status == EXIT_SUCCESS ) { /* Set the Shadow callbacks for this demo. */ status = _setShadowCallbacks( &deltaSemaphore, mqttConnection, pIdentifier, thingNameLength ); } if( status == EXIT_SUCCESS ) { /* Clear the Shadow document so that this demo starts with no existing * Shadow. */ _clearShadowDocument( mqttConnection, pIdentifier, thingNameLength ); { /* Send Shadow updates. */ status = _sendShadowUpdates( &deltaSemaphore, mqttConnection, pIdentifier, thingNameLength ); } for(;;) GetShadow(&deltaSemaphore, mqttConnection, pIdentifier, thingNameLength ); /* Delete the Shadow document created by this demo to clean up. */ _clearShadowDocument( mqttConnection, pIdentifier, thingNameLength ); } /* Disconnect the MQTT connection if it was established. */ if( connectionEstablished == true ) { IotMqtt_Disconnect( mqttConnection, 0 ); } /* Clean up libraries if they were initialized. */ if( librariesInitialized == true ) { _cleanupDemo(); } /* Destroy the delta semaphore if it was created. */ if( deltaSemaphoreCreated == true ) { IotSemaphore_Destroy( &deltaSemaphore ); } return status; } /*-----------------------------------------------------------*/
127532.c
#include "object/roa.h" #include <errno.h> #include <arpa/inet.h> #include <sys/socket.h> #include "config.h" #include "log.h" #include "thread_var.h" #include "asn1/decode.h" #include "asn1/oid.h" #include "asn1/asn1c/RouteOriginAttestation.h" #include "object/signed_object.h" static int decode_roa(struct signed_object *sobj, struct RouteOriginAttestation **result) { return asn1_decode_octet_string( sobj->sdata.decoded->encapContentInfo.eContent, &asn_DEF_RouteOriginAttestation, (void **) result, true, false ); } static int ____handle_roa_v4(struct resources *parent, unsigned long asn, struct ROAIPAddress *roa_addr) { struct ipv4_prefix prefix; unsigned long max_length; int error; error = prefix4_decode(&roa_addr->address, &prefix); if (error) return error; pr_val_debug("ROAIPAddress {"); pr_val_debug("address: %s/%u", v4addr2str(&prefix.addr), prefix.len); if (roa_addr->maxLength != NULL) { error = asn_INTEGER2ulong(roa_addr->maxLength, &max_length); if (error) { if (errno) { pr_val_err("Error casting ROA's IPv4 maxLength: %s", strerror(errno)); } error = pr_val_err("The ROA's IPv4 maxLength isn't a valid unsigned long"); goto end_error; } pr_val_debug("maxLength: %lu", max_length); if (max_length > 32) { error = pr_val_err("maxLength (%lu) is out of bounds (0-32).", max_length); goto end_error; } if (prefix.len > max_length) { error = pr_val_err("Prefix length (%u) > maxLength (%lu)", prefix.len, max_length); goto end_error; } } else { max_length = prefix.len; } if (!resources_contains_ipv4(parent, &prefix)) { error = pr_val_err("ROA is not allowed to advertise %s/%u.", v4addr2str(&prefix.addr), prefix.len); goto end_error; } pr_val_debug("}"); return vhandler_handle_roa_v4(asn, &prefix, max_length); end_error: pr_val_debug("}"); return error; } static int ____handle_roa_v6(struct resources *parent, unsigned long asn, struct ROAIPAddress *roa_addr) { struct ipv6_prefix prefix; unsigned long max_length; int error; error = prefix6_decode(&roa_addr->address, &prefix); if (error) return error; pr_val_debug("ROAIPAddress {"); pr_val_debug("address: %s/%u", v6addr2str(&prefix.addr), prefix.len); if (roa_addr->maxLength != NULL) { error = asn_INTEGER2ulong(roa_addr->maxLength, &max_length); if (error) { if (errno) { pr_val_err("Error casting ROA's IPv6 maxLength: %s", strerror(errno)); } error = pr_val_err("The ROA's IPv6 maxLength isn't a valid unsigned long"); goto end_error; } pr_val_debug("maxLength: %lu", max_length); if (max_length > 128) { error = pr_val_err("maxLength (%lu) is out of bounds (0-128).", max_length); goto end_error; } if (prefix.len > max_length) { error = pr_val_err("Prefix length (%u) > maxLength (%lu)", prefix.len, max_length); goto end_error; } } else { max_length = prefix.len; } if (!resources_contains_ipv6(parent, &prefix)) { error = pr_val_err("ROA is not allowed to advertise %s/%u.", v6addr2str(&prefix.addr), prefix.len); goto end_error; } pr_val_debug("}"); return vhandler_handle_roa_v6(asn, &prefix, max_length); end_error: pr_val_debug("}"); return error; } static int ____handle_roa(struct resources *parent, unsigned long asn, uint8_t family, struct ROAIPAddress *roa_addr) { switch (family) { case 1: /* IPv4 */ return ____handle_roa_v4(parent, asn, roa_addr); case 2: /* IPv6 */ return ____handle_roa_v6(parent, asn, roa_addr); } return pr_val_err("Unknown family value: %u", family); } static int __handle_roa(struct RouteOriginAttestation *roa, struct resources *parent) { struct ROAIPAddressFamily *block; unsigned long version; unsigned long asn; int b; int a; int error; pr_val_debug("eContent {"); if (roa->version != NULL) { error = asn_INTEGER2ulong(roa->version, &version); if (error) { if (errno) { pr_val_err("Error casting ROA's version: %s", strerror(errno)); } error = pr_val_err("The ROA's version isn't a valid long"); goto end_error; } /* rfc6482#section-3.1 */ if (version != 0) { error = pr_val_err("ROA's version (%lu) is nonzero.", version); goto end_error; } } /* rfc6482#section-3.2 */ if (asn_INTEGER2ulong(&roa->asID, &asn) != 0) { if (errno) { pr_val_err("Error casting ROA's AS ID value: %s", strerror(errno)); } error = pr_val_err("ROA's AS ID couldn't be parsed as unsigned long"); goto end_error; } if (asn > UINT32_MAX) { error = pr_val_err("AS value (%lu) is out of range.", asn); goto end_error; } pr_val_debug("asID: %lu", asn); /* rfc6482#section-3.3 */ if (roa->ipAddrBlocks.list.array == NULL) { error = pr_val_err("ipAddrBlocks array is NULL."); goto end_error; } pr_val_debug("ipAddrBlocks {"); for (b = 0; b < roa->ipAddrBlocks.list.count; b++) { block = roa->ipAddrBlocks.list.array[b]; if (block == NULL) { error = pr_val_err("Address block array element is NULL."); goto ip_error; } if (block->addressFamily.size != 2) goto family_error; if (block->addressFamily.buf[0] != 0) goto family_error; if (block->addressFamily.buf[1] != 1 && block->addressFamily.buf[1] != 2) goto family_error; pr_val_debug("%s {", block->addressFamily.buf[1] == 1 ? "v4" : "v6"); if (block->addresses.list.array == NULL) { error = pr_val_err("ROA's address list array is NULL."); pr_val_debug("}"); goto ip_error; } for (a = 0; a < block->addresses.list.count; a++) { error = ____handle_roa(parent, asn, block->addressFamily.buf[1], block->addresses.list.array[a]); if (error) { pr_val_debug("}"); goto ip_error; } } pr_val_debug("}"); } /* Error 0 it's ok */ error = 0; goto ip_error; family_error: error = pr_val_err("ROA's IP family is not v4 or v6."); ip_error: pr_val_debug("}"); end_error: pr_val_debug("}"); return error; } int roa_traverse(struct rpki_uri *uri, struct rpp *pp) { static OID oid = OID_ROA; struct oid_arcs arcs = OID2ARCS("roa", oid); struct signed_object sobj; struct signed_object_args sobj_args; struct RouteOriginAttestation *roa; STACK_OF(X509_CRL) *crl; int error; /* Prepare */ pr_val_debug("ROA '%s' {", uri_val_get_printable(uri)); fnstack_push_uri(uri); /* Decode */ error = signed_object_decode(&sobj, uri); if (error) goto revert_log; error = decode_roa(&sobj, &roa); if (error) goto revert_sobj; /* Prepare validation arguments */ error = rpp_crl(pp, &crl); if (error) goto revert_roa; error = signed_object_args_init(&sobj_args, uri, crl, false); if (error) goto revert_roa; /* Validate and handle everything */ error = signed_object_validate(&sobj, &arcs, &sobj_args); if (error) goto revert_args; error = __handle_roa(roa, sobj_args.res); if (error) goto revert_args; error = refs_validate_ee(&sobj_args.refs, pp, sobj_args.uri); revert_args: signed_object_args_cleanup(&sobj_args); revert_roa: ASN_STRUCT_FREE(asn_DEF_RouteOriginAttestation, roa); revert_sobj: signed_object_cleanup(&sobj); revert_log: fnstack_pop(); pr_val_debug("}"); return error; }
628239.c
/* * drivers/rtc/rtc-pl031.c * * Real Time Clock interface for ARM AMBA PrimeCell 031 RTC * * Author: Deepak Saxena <[email protected]> * * Copyright 2006 (c) MontaVista Software, Inc. * * Author: Mian Yousaf Kaukab <[email protected]> * Copyright 2010 (c) ST-Ericsson AB * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/module.h> #include <linux/rtc.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/amba/bus.h> #include <linux/io.h> #include <linux/bcd.h> #include <linux/delay.h> #include <linux/slab.h> /* * Register definitions */ #define RTC_DR 0x00 /* Data read register */ #define RTC_MR 0x04 /* Match register */ #define RTC_LR 0x08 /* Data load register */ #define RTC_CR 0x0c /* Control register */ #define RTC_IMSC 0x10 /* Interrupt mask and set register */ #define RTC_RIS 0x14 /* Raw interrupt status register */ #define RTC_MIS 0x18 /* Masked interrupt status register */ #define RTC_ICR 0x1c /* Interrupt clear register */ /* ST variants have additional timer functionality */ #define RTC_TDR 0x20 /* Timer data read register */ #define RTC_TLR 0x24 /* Timer data load register */ #define RTC_TCR 0x28 /* Timer control register */ #define RTC_YDR 0x30 /* Year data read register */ #define RTC_YMR 0x34 /* Year match register */ #define RTC_YLR 0x38 /* Year data load register */ #define RTC_CR_CWEN (1 << 26) /* Clockwatch enable bit */ #define RTC_TCR_EN (1 << 1) /* Periodic timer enable bit */ /* Common bit definitions for Interrupt status and control registers */ #define RTC_BIT_AI (1 << 0) /* Alarm interrupt bit */ #define RTC_BIT_PI (1 << 1) /* Periodic interrupt bit. ST variants only. */ /* Common bit definations for ST v2 for reading/writing time */ #define RTC_SEC_SHIFT 0 #define RTC_SEC_MASK (0x3F << RTC_SEC_SHIFT) /* Second [0-59] */ #define RTC_MIN_SHIFT 6 #define RTC_MIN_MASK (0x3F << RTC_MIN_SHIFT) /* Minute [0-59] */ #define RTC_HOUR_SHIFT 12 #define RTC_HOUR_MASK (0x1F << RTC_HOUR_SHIFT) /* Hour [0-23] */ #define RTC_WDAY_SHIFT 17 #define RTC_WDAY_MASK (0x7 << RTC_WDAY_SHIFT) /* Day of Week [1-7] 1=Sunday */ #define RTC_MDAY_SHIFT 20 #define RTC_MDAY_MASK (0x1F << RTC_MDAY_SHIFT) /* Day of Month [1-31] */ #define RTC_MON_SHIFT 25 #define RTC_MON_MASK (0xF << RTC_MON_SHIFT) /* Month [1-12] 1=January */ #define RTC_TIMER_FREQ 32768 struct pl031_local { struct rtc_device *rtc; void __iomem *base; u8 hw_designer; u8 hw_revision:4; }; static int pl031_alarm_irq_enable(struct device *dev, unsigned int enabled) { struct pl031_local *ldata = dev_get_drvdata(dev); unsigned long imsc; /* Clear any pending alarm interrupts. */ writel(RTC_BIT_AI, ldata->base + RTC_ICR); imsc = readl(ldata->base + RTC_IMSC); if (enabled == 1) writel(imsc | RTC_BIT_AI, ldata->base + RTC_IMSC); else writel(imsc & ~RTC_BIT_AI, ldata->base + RTC_IMSC); return 0; } /* * Convert Gregorian date to ST v2 RTC format. */ static int pl031_stv2_tm_to_time(struct device *dev, struct rtc_time *tm, unsigned long *st_time, unsigned long *bcd_year) { int year = tm->tm_year + 1900; int wday = tm->tm_wday; /* wday masking is not working in hardware so wday must be valid */ if (wday < -1 || wday > 6) { dev_err(dev, "invalid wday value %d\n", tm->tm_wday); return -EINVAL; } else if (wday == -1) { /* wday is not provided, calculate it here */ unsigned long time; struct rtc_time calc_tm; rtc_tm_to_time(tm, &time); rtc_time_to_tm(time, &calc_tm); wday = calc_tm.tm_wday; } *bcd_year = (bin2bcd(year % 100) | bin2bcd(year / 100) << 8); *st_time = ((tm->tm_mon + 1) << RTC_MON_SHIFT) | (tm->tm_mday << RTC_MDAY_SHIFT) | ((wday + 1) << RTC_WDAY_SHIFT) | (tm->tm_hour << RTC_HOUR_SHIFT) | (tm->tm_min << RTC_MIN_SHIFT) | (tm->tm_sec << RTC_SEC_SHIFT); return 0; } /* * Convert ST v2 RTC format to Gregorian date. */ static int pl031_stv2_time_to_tm(unsigned long st_time, unsigned long bcd_year, struct rtc_time *tm) { tm->tm_year = bcd2bin(bcd_year) + (bcd2bin(bcd_year >> 8) * 100); tm->tm_mon = ((st_time & RTC_MON_MASK) >> RTC_MON_SHIFT) - 1; tm->tm_mday = ((st_time & RTC_MDAY_MASK) >> RTC_MDAY_SHIFT); tm->tm_wday = ((st_time & RTC_WDAY_MASK) >> RTC_WDAY_SHIFT) - 1; tm->tm_hour = ((st_time & RTC_HOUR_MASK) >> RTC_HOUR_SHIFT); tm->tm_min = ((st_time & RTC_MIN_MASK) >> RTC_MIN_SHIFT); tm->tm_sec = ((st_time & RTC_SEC_MASK) >> RTC_SEC_SHIFT); tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); tm->tm_year -= 1900; return 0; } static int pl031_stv2_read_time(struct device *dev, struct rtc_time *tm) { struct pl031_local *ldata = dev_get_drvdata(dev); pl031_stv2_time_to_tm(readl(ldata->base + RTC_DR), readl(ldata->base + RTC_YDR), tm); return 0; } static int pl031_stv2_set_time(struct device *dev, struct rtc_time *tm) { unsigned long time; unsigned long bcd_year; struct pl031_local *ldata = dev_get_drvdata(dev); int ret; ret = pl031_stv2_tm_to_time(dev, tm, &time, &bcd_year); if (ret == 0) { writel(bcd_year, ldata->base + RTC_YLR); writel(time, ldata->base + RTC_LR); } return ret; } static int pl031_stv2_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct pl031_local *ldata = dev_get_drvdata(dev); int ret; ret = pl031_stv2_time_to_tm(readl(ldata->base + RTC_MR), readl(ldata->base + RTC_YMR), &alarm->time); alarm->pending = readl(ldata->base + RTC_RIS) & RTC_BIT_AI; alarm->enabled = readl(ldata->base + RTC_IMSC) & RTC_BIT_AI; return ret; } static int pl031_stv2_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct pl031_local *ldata = dev_get_drvdata(dev); unsigned long time; unsigned long bcd_year; int ret; /* At the moment, we can only deal with non-wildcarded alarm times. */ ret = rtc_valid_tm(&alarm->time); if (ret == 0) { ret = pl031_stv2_tm_to_time(dev, &alarm->time, &time, &bcd_year); if (ret == 0) { writel(bcd_year, ldata->base + RTC_YMR); writel(time, ldata->base + RTC_MR); pl031_alarm_irq_enable(dev, alarm->enabled); } } return ret; } static irqreturn_t pl031_interrupt(int irq, void *dev_id) { struct pl031_local *ldata = dev_id; unsigned long rtcmis; unsigned long events = 0; rtcmis = readl(ldata->base + RTC_MIS); if (rtcmis) { writel(rtcmis, ldata->base + RTC_ICR); if (rtcmis & RTC_BIT_AI) events |= (RTC_AF | RTC_IRQF); /* Timer interrupt is only available in ST variants */ if ((rtcmis & RTC_BIT_PI) && (ldata->hw_designer == AMBA_VENDOR_ST)) events |= (RTC_PF | RTC_IRQF); rtc_update_irq(ldata->rtc, 1, events); return IRQ_HANDLED; } return IRQ_NONE; } static int pl031_read_time(struct device *dev, struct rtc_time *tm) { struct pl031_local *ldata = dev_get_drvdata(dev); rtc_time_to_tm(readl(ldata->base + RTC_DR), tm); return 0; } static int pl031_set_time(struct device *dev, struct rtc_time *tm) { unsigned long time; struct pl031_local *ldata = dev_get_drvdata(dev); int ret; ret = rtc_tm_to_time(tm, &time); if (ret == 0) writel(time, ldata->base + RTC_LR); return ret; } static int pl031_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct pl031_local *ldata = dev_get_drvdata(dev); rtc_time_to_tm(readl(ldata->base + RTC_MR), &alarm->time); alarm->pending = readl(ldata->base + RTC_RIS) & RTC_BIT_AI; alarm->enabled = readl(ldata->base + RTC_IMSC) & RTC_BIT_AI; return 0; } static int pl031_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) { struct pl031_local *ldata = dev_get_drvdata(dev); unsigned long time; int ret; /* At the moment, we can only deal with non-wildcarded alarm times. */ ret = rtc_valid_tm(&alarm->time); if (ret == 0) { ret = rtc_tm_to_time(&alarm->time, &time); if (ret == 0) { writel(time, ldata->base + RTC_MR); pl031_alarm_irq_enable(dev, alarm->enabled); } } return ret; } static int pl031_remove(struct amba_device *adev) { struct pl031_local *ldata = dev_get_drvdata(&adev->dev); amba_set_drvdata(adev, NULL); free_irq(adev->irq[0], ldata->rtc); rtc_device_unregister(ldata->rtc); iounmap(ldata->base); kfree(ldata); amba_release_regions(adev); return 0; } static int pl031_probe(struct amba_device *adev, const struct amba_id *id) { int ret; struct pl031_local *ldata; struct rtc_class_ops *ops = id->data; unsigned long time; ret = amba_request_regions(adev, NULL); if (ret) goto err_req; ldata = kzalloc(sizeof(struct pl031_local), GFP_KERNEL); if (!ldata) { ret = -ENOMEM; goto out; } ldata->base = ioremap(adev->res.start, resource_size(&adev->res)); if (!ldata->base) { ret = -ENOMEM; goto out_no_remap; } amba_set_drvdata(adev, ldata); ldata->hw_designer = amba_manf(adev); ldata->hw_revision = amba_rev(adev); dev_dbg(&adev->dev, "designer ID = 0x%02x\n", ldata->hw_designer); dev_dbg(&adev->dev, "revision = 0x%01x\n", ldata->hw_revision); /* Enable the clockwatch on ST Variants */ if (ldata->hw_designer == AMBA_VENDOR_ST) writel(readl(ldata->base + RTC_CR) | RTC_CR_CWEN, ldata->base + RTC_CR); /* * On ST PL031 variants, the RTC reset value does not provide correct * weekday for 2000-01-01. Correct the erroneous sunday to saturday. */ if (ldata->hw_designer == AMBA_VENDOR_ST) { if (readl(ldata->base + RTC_YDR) == 0x2000) { time = readl(ldata->base + RTC_DR); if ((time & (RTC_MON_MASK | RTC_MDAY_MASK | RTC_WDAY_MASK)) == 0x02120000) { time = time | (0x7 << RTC_WDAY_SHIFT); writel(0x2000, ldata->base + RTC_YLR); writel(time, ldata->base + RTC_LR); } } } ldata->rtc = rtc_device_register("pl031", &adev->dev, ops, THIS_MODULE); if (IS_ERR(ldata->rtc)) { ret = PTR_ERR(ldata->rtc); goto out_no_rtc; } if (request_irq(adev->irq[0], pl031_interrupt, IRQF_DISABLED, "rtc-pl031", ldata)) { ret = -EIO; goto out_no_irq; } return 0; out_no_irq: rtc_device_unregister(ldata->rtc); out_no_rtc: iounmap(ldata->base); amba_set_drvdata(adev, NULL); out_no_remap: kfree(ldata); out: amba_release_regions(adev); err_req: return ret; } /* Operations for the original ARM version */ static struct rtc_class_ops arm_pl031_ops = { .read_time = pl031_read_time, .set_time = pl031_set_time, .read_alarm = pl031_read_alarm, .set_alarm = pl031_set_alarm, .alarm_irq_enable = pl031_alarm_irq_enable, }; /* The First ST derivative */ static struct rtc_class_ops stv1_pl031_ops = { .read_time = pl031_read_time, .set_time = pl031_set_time, .read_alarm = pl031_read_alarm, .set_alarm = pl031_set_alarm, .alarm_irq_enable = pl031_alarm_irq_enable, }; /* And the second ST derivative */ static struct rtc_class_ops stv2_pl031_ops = { .read_time = pl031_stv2_read_time, .set_time = pl031_stv2_set_time, .read_alarm = pl031_stv2_read_alarm, .set_alarm = pl031_stv2_set_alarm, .alarm_irq_enable = pl031_alarm_irq_enable, }; static struct amba_id pl031_ids[] = { { .id = 0x00041031, .mask = 0x000fffff, .data = &arm_pl031_ops, }, /* ST Micro variants */ { .id = 0x00180031, .mask = 0x00ffffff, .data = &stv1_pl031_ops, }, { .id = 0x00280031, .mask = 0x00ffffff, .data = &stv2_pl031_ops, }, {0, 0}, }; static struct amba_driver pl031_driver = { .drv = { .name = "rtc-pl031", }, .id_table = pl031_ids, .probe = pl031_probe, .remove = pl031_remove, }; static int __init pl031_init(void) { return amba_driver_register(&pl031_driver); } static void __exit pl031_exit(void) { amba_driver_unregister(&pl031_driver); } module_init(pl031_init); module_exit(pl031_exit); MODULE_AUTHOR("Deepak Saxena <[email protected]"); MODULE_DESCRIPTION("ARM AMBA PL031 RTC Driver"); MODULE_LICENSE("GPL");
367760.c
/* Copyright (c) INRIA and Microsoft Corporation. All rights reserved. Licensed under the Apache 2.0 License. */ #include "Prims.h" #include "FStar_Int32.h" Prims_string Prims_string_of_int(krml_checked_int_t i) { return FStar_Int32_to_string(i); } Prims_string Prims_strcat(Prims_string s0, Prims_string s1) { size_t len = strlen(s0) + strlen(s1) + 1; char *dest = KRML_HOST_CALLOC(len, 1); #ifdef _MSC_VER strcat_s(dest, len, s0); strcat_s(dest, len, s1); #else strcat(dest, s0); strcat(dest, s1); #endif return (Prims_string)dest; } bool __eq__Prims_string(Prims_string s1, Prims_string s2) { return (strcmp(s1, s2) == 0); } inline Prims_string Prims_string_of_bool(bool b) { if (b) { return "true"; } else { return "false"; } } bool Prims_op_GreaterThanOrEqual(int32_t x, int32_t y) { return x >= y; } bool Prims_op_LessThanOrEqual(int32_t x, int32_t y) { return x <= y; } bool Prims_op_GreaterThan(int32_t x, int32_t y) { return x > y; } bool Prims_op_LessThan(int32_t x, int32_t y) { return x < y; } int32_t Prims_pow2(int32_t x) { /* FIXME incorrect bounds check here */ RETURN_OR((int64_t)1 << (int64_t)x); } int32_t Prims_op_Multiply(int32_t x, int32_t y) { RETURN_OR((int64_t)x * (int64_t)y); } int32_t Prims_op_Addition(int32_t x, int32_t y) { RETURN_OR((int64_t)x + (int64_t)y); } int32_t Prims_op_Subtraction(int32_t x, int32_t y) { RETURN_OR((int64_t)x - (int64_t)y); } int32_t Prims_op_Division(int32_t x, int32_t y) { RETURN_OR((int64_t)x / (int64_t)y); } int32_t Prims_op_Modulus(int32_t x, int32_t y) { RETURN_OR((int64_t)x % (int64_t)y); }
340026.c
/* Copyright Statement: * * This software/firmware and related documentation ("MediaTek Software") are * protected under relevant copyright laws. The information contained herein * is confidential and proprietary to MediaTek Inc. and/or its licensors. * Without the prior written permission of MediaTek inc. and/or its licensors, * any reproduction, modification, use or disclosure of MediaTek Software, * and information contained herein, in whole or in part, shall be strictly prohibited. */ /* MediaTek Inc. (C) 2015. All rights reserved. * * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. */ #define LOG_TAG "LCM" #ifndef BUILD_LK #include <linux/string.h> #include <linux/kernel.h> #endif #include "lcm_drv.h" #ifdef MTK_ROUND_CORNER_SUPPORT #include "data_rgba4444_roundedpattern.h" #endif #ifdef BUILD_LK #include <platform/upmu_common.h> #include <platform/mt_gpio.h> #include <platform/mt_i2c.h> #include <platform/mt_pmic.h> #include <string.h> #ifndef MACH_FPGA #include <lcm_pmic.h> #endif #elif defined(BUILD_UBOOT) #include <asm/arch/mt_gpio.h> #else #include <mach/mt_pm_ldo.h> #include <mach/mt_gpio.h> #endif #ifdef BUILD_LK #define LCM_LOGI(string, args...) dprintf(0, "[LK/"LOG_TAG"]"string, ##args) #define LCM_LOGD(string, args...) dprintf(1, "[LK/"LOG_TAG"]"string, ##args) #else #define LCM_LOGI(fmt, args...) pr_notice("[KERNEL/"LOG_TAG"]"fmt, ##args) #define LCM_LOGD(fmt, args...) pr_debug("[KERNEL/"LOG_TAG"]"fmt, ##args) #endif #define LCM_ID_NT35695 (0xf5) static const unsigned int BL_MIN_LEVEL = 20; static LCM_UTIL_FUNCS lcm_util; #define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v))) #define MDELAY(n) (lcm_util.mdelay(n)) #define UDELAY(n) (lcm_util.udelay(n)) /* --------------------------------------------------------------------------- */ /* Local Functions */ /* --------------------------------------------------------------------------- */ #define dsi_set_cmdq_V2(cmd, count, ppara, force_update) \ lcm_util.dsi_set_cmdq_V2(cmd, count, ppara, force_update) #define dsi_set_cmdq(pdata, queue_size, force_update) \ lcm_util.dsi_set_cmdq(pdata, queue_size, force_update) #define wrtie_cmd(cmd) lcm_util.dsi_write_cmd(cmd) #define write_regs(addr, pdata, byte_nums) \ lcm_util.dsi_write_regs(addr, pdata, byte_nums) #define read_reg(cmd) \ lcm_util.dsi_dcs_read_lcm_reg(cmd) #define read_reg_v2(cmd, buffer, buffer_size) \ lcm_util.dsi_dcs_read_lcm_reg_v2(cmd, buffer, buffer_size) #ifndef BUILD_LK #include <linux/kernel.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/slab.h> #include <linux/init.h> #include <linux/list.h> #include <linux/i2c.h> #include <linux/irq.h> /* #include <linux/jiffies.h> */ /* #include <linux/delay.h> */ #include <linux/uaccess.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/platform_device.h> #endif /* static unsigned char lcd_id_pins_value = 0xFF; */ static const unsigned char LCD_MODULE_ID = 0x01; /* --------------------------------------------------------------------------- */ /* Local Constants */ /* --------------------------------------------------------------------------- */ #define LCM_DSI_CMD_MODE 0 #define FRAME_WIDTH (720) #define FRAME_HEIGHT (1600) #define VIRTUAL_WIDTH (1080) #define VIRTUAL_HEIGHT (1920) #ifndef MACH_FPGA #define GPIO_65132_EN GPIO_LCD_BIAS_ENP_PIN #endif #define REGFLAG_DELAY 0xFFFC #define REGFLAG_UDELAY 0xFFFB #define REGFLAG_END_OF_TABLE 0xFFFD #define REGFLAG_RESET_LOW 0xFFFE #define REGFLAG_RESET_HIGH 0xFFFF #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif struct LCM_setting_table { unsigned int cmd; unsigned char count; unsigned char para_list[64]; }; static struct LCM_setting_table lcm_suspend_setting[] = { {0x28, 0, {} }, {0x10, 0, {} }, {REGFLAG_DELAY, 120, {} }, {0x4F, 1, {0x01} }, {REGFLAG_DELAY, 120, {} } }; static struct LCM_setting_table init_setting[] = { {0xFF, 1, {0x24} }, {0xFB, 1, {0x01} }, {0x2D, 1, {0x08} }, {0xFF, 1, {0x24} }, /* Return To CMD1 */ {0x6E, 1, {0x10} }, /* Return To CMD1 */ {0xFB, 1, {0x01} }, /* Return To CMD1 */ {0xFF, 1, {0x10} }, /* Return To CMD1 */ {0xFF, 1, {0x10} }, /* Return To CMD1 */ {REGFLAG_UDELAY, 1, {} }, #if (LCM_DSI_CMD_MODE) {0xBB, 1, {0x10} },/*CMD MODE*/ #else {0xBB, 1, {0x03} },/*VDO MODE*/ #endif {0x3B, 5, {0x03, 0x0A, 0x0A, 0x0A, 0x0A} }, {0x53, 1, {0x24} }, {0x55, 1, {0x00} }, {0x5E, 1, {0x00} }, {0xFF, 1, {0x24} }, /* CMD2 Page4 Entrance */ {REGFLAG_UDELAY, 1, {} }, {0xC2, 1, {0x00} }, {0xFB, 1, {0x01} }, {0x9D, 1, {0xB0} }, {0x72, 1, {0x00} }, {0x93, 1, {0x04} }, {0x94, 1, {0x04} }, {0x9B, 1, {0x0F} }, {0x8A, 1, {0x33} }, {0x86, 1, {0x1B} }, {0x87, 1, {0x39} }, {0x88, 1, {0x1B} }, {0x89, 1, {0x39} }, {0x8B, 1, {0xF4} }, {0x8C, 1, {0x01} }, /* Change for 695 RTN Start */ {0x90, 1, {0x95} }, {0x91, 1, {0xC8} }, /* modify to 0x77 to see whether fps is higher */ /* {0x92,1,{0x79}}, */ {0x92, 1, {0x95} }, {0x93, 1, {0x02} }, {0x94, 1, {0x08} }, {0x95, 1, {0x2B} }, {0x96, 1, {0x95} }, /* Change for 695 RTN End */ {0xDE, 1, {0xFF} }, {0xDF, 1, {0x82} }, {0x00, 1, {0x0F} }, {0x01, 1, {0x00} }, {0x02, 1, {0x00} }, {0x03, 1, {0x00} }, {0x04, 1, {0x0B} }, {0x05, 1, {0x0C} }, {0x06, 1, {0x00} }, {0x07, 1, {0x00} }, {0x08, 1, {0x00} }, {0x09, 1, {0x00} }, {0x0A, 1, {0X03} }, {0x0B, 1, {0X04} }, {0x0C, 1, {0x01} }, {0x0D, 1, {0x13} }, {0x0E, 1, {0x15} }, {0x0F, 1, {0x17} }, {0x10, 1, {0x0F} }, {0x11, 1, {0x00} }, {0x12, 1, {0x00} }, {0x13, 1, {0x00} }, {0x14, 1, {0x0B} }, {0x15, 1, {0x0C} }, {0x16, 1, {0x00} }, {0x17, 1, {0x00} }, {0x18, 1, {0x00} }, {0x19, 1, {0x00} }, {0x1A, 1, {0x03} }, {0x1B, 1, {0X04} }, {0x1C, 1, {0x01} }, {0x1D, 1, {0x13} }, {0x1E, 1, {0x15} }, {0x1F, 1, {0x17} }, {0x20, 1, {0x09} }, {0x21, 1, {0x01} }, {0x22, 1, {0x00} }, {0x23, 1, {0x00} }, {0x24, 1, {0x00} }, {0x25, 1, {0x6D} }, {0x26, 1, {0x00} }, {0x27, 1, {0x00} }, {0x2F, 1, {0x02} }, {0x30, 1, {0x04} }, {0x31, 1, {0x49} }, {0x32, 1, {0x23} }, {0x33, 1, {0x01} }, {0x34, 1, {0x00} }, /* Change for 695 */ {0x35, 1, {0x83} }, {0x36, 1, {0x00} }, {0x37, 1, {0x2D} }, {0x38, 1, {0x08} }, {0x39, 1, {0x00} }, /* Change for 695 */ {0x3A, 1, {0x83} }, {0x29, 1, {0x58} }, {0x2A, 1, {0x16} }, {0x5B, 1, {0x00} }, {0x5F, 1, {0x75} }, {0x63, 1, {0x00} }, {0x67, 1, {0x04} }, /* Change for 695 */ {0x74, 1, {0x14} }, /* Change for 695 */ {0x75, 1, {0x1F} }, {0x7B, 1, {0x80} }, {0x7C, 1, {0xD8} }, {0x7D, 1, {0x60} }, /* Change for 695 */ {0x7E, 1, {0x14} }, /* Change for 695 */ {0x7F, 1, {0x1F} }, {0x80, 1, {0x00} }, {0x81, 1, {0x06} }, {0x82, 1, {0x03} }, {0x83, 1, {0x00} }, {0x84, 1, {0x03} }, {0x85, 1, {0x07} }, {0x74, 1, {0x10} }, {0x75, 1, {0x19} }, {0x76, 1, {0x06} }, {0x77, 1, {0x03} }, {0x78, 1, {0x00} }, {0x79, 1, {0x00} }, {0x99, 1, {0x33} }, {0x98, 1, {0x00} }, {0xB3, 1, {0x28} }, {0xB4, 1, {0x05} }, {0xB5, 1, {0x10} }, {0xFF, 1, {0x20} }, /* Page 0,1,{ power-related setting */ {REGFLAG_UDELAY, 1, {} }, {0x00, 1, {0x01} }, {0x01, 1, {0x55} }, {0x02, 1, {0x45} }, {0x03, 1, {0x55} }, {0x05, 1, {0x50} }, {0x06, 1, {0x9E} }, {0x07, 1, {0xA8} }, {0x08, 1, {0x0C} }, {0x0B, 1, {0x96} }, {0x0C, 1, {0x96} }, {0x0E, 1, {0x00} }, {0x0F, 1, {0x00} }, {0x11, 1, {0x29} }, {0x12, 1, {0x29} }, {0x13, 1, {0x03} }, {0x14, 1, {0x0A} }, {0x15, 1, {0x99} }, {0x16, 1, {0x99} }, /* Change for 695 */ {0x6D, 1, {0x68} }, {0x58, 1, {0x05} }, {0x59, 1, {0x05} }, {0x5A, 1, {0x05} }, {0x5B, 1, {0x05} }, {0x5C, 1, {0x00} }, {0x5D, 1, {0x00} }, {0x5E, 1, {0x00} }, {0x5F, 1, {0x00} }, {0x1B, 1, {0x39} }, {0x1C, 1, {0x39} }, {0x1D, 1, {0x47} }, {0xFF, 1, {0x20} }, /* Page 0,1,{ power-related setting */ {REGFLAG_UDELAY, 1, {} }, /* R+ ,1,{}}, */ {0x75, 1, {0x00} }, {0x76, 1, {0x00} }, {0x77, 1, {0x00} }, {0x78, 1, {0x3e} }, {0x79, 1, {0x00} }, {0x7A, 1, {0x6f} }, {0x7B, 1, {0x00} }, {0x7C, 1, {0x8f} }, {0x7D, 1, {0x00} }, {0x7E, 1, {0xa7} }, {0x7F, 1, {0x00} }, {0x80, 1, {0xbc} }, {0x81, 1, {0x00} }, {0x82, 1, {0xce} }, {0x83, 1, {0x00} }, {0x84, 1, {0xdd} }, {0x85, 1, {0x00} }, {0x86, 1, {0xec} }, {0x87, 1, {0x01} }, {0x88, 1, {0x1a} }, {0x89, 1, {0x01} }, {0x8A, 1, {0x3e} }, {0x8B, 1, {0x01} }, {0x8C, 1, {0x76} }, {0x8D, 1, {0x01} }, {0x8E, 1, {0xa3} }, {0x8F, 1, {0x01} }, {0x90, 1, {0xe9} }, {0x91, 1, {0x02} }, {0x92, 1, {0x20} }, {0x93, 1, {0x02} }, {0x94, 1, {0x22} }, {0x95, 1, {0x02} }, {0x96, 1, {0x56} }, {0x97, 1, {0x02} }, {0x98, 1, {0x8f} }, {0x99, 1, {0x02} }, {0x9A, 1, {0xb2} }, {0x9B, 1, {0x02} }, {0x9C, 1, {0xe2} }, {0x9D, 1, {0x03} }, {0x9E, 1, {0x02} }, {0x9F, 1, {0x03} }, {0xA0, 1, {0x2d} }, {0xA2, 1, {0x03} }, {0xA3, 1, {0x3a} }, {0xA4, 1, {0x03} }, {0xA5, 1, {0x48} }, {0xA6, 1, {0x03} }, {0xA7, 1, {0x58} }, {0xA9, 1, {0x03} }, {0xAA, 1, {0x6a} }, {0xAB, 1, {0x03} }, {0xAC, 1, {0x80} }, {0xAD, 1, {0x03} }, {0xAE, 1, {0x9d} }, {0xAF, 1, {0x03} }, {0xB0, 1, {0xb7} }, {0xB1, 1, {0x03} }, {0xB2, 1, {0xFF} }, /* R- ,1,{}}, */ {0xB3, 1, {0x00} }, {0xB4, 1, {0x00} }, {0xB5, 1, {0x00} }, {0xB6, 1, {0x3e} }, {0xB7, 1, {0x00} }, {0xB8, 1, {0x6f} }, {0xB9, 1, {0x00} }, {0xBA, 1, {0x8f} }, {0xBB, 1, {0x00} }, {0xBC, 1, {0xa7} }, {0xBD, 1, {0x00} }, {0xBE, 1, {0xbc} }, {0xBF, 1, {0x00} }, {0xC0, 1, {0xce} }, {0xC1, 1, {0x00} }, {0xC2, 1, {0xdd} }, {0xC3, 1, {0x00} }, {0xC4, 1, {0xec} }, {0xC5, 1, {0x01} }, {0xC6, 1, {0x1a} }, {0xC7, 1, {0x01} }, {0xC8, 1, {0x3e} }, {0xC9, 1, {0x01} }, {0xCA, 1, {0x76} }, {0xCB, 1, {0x01} }, {0xCC, 1, {0xa3} }, {0xCD, 1, {0x01} }, {0xCE, 1, {0xe9} }, {0xCF, 1, {0x02} }, {0xD0, 1, {0x20} }, {0xD1, 1, {0x02} }, {0xD2, 1, {0x22} }, {0xD3, 1, {0x02} }, {0xD4, 1, {0x56} }, {0xD5, 1, {0x02} }, {0xD6, 1, {0x8f} }, {0xD7, 1, {0x02} }, {0xD8, 1, {0xb2} }, {0xD9, 1, {0x02} }, {0xDA, 1, {0xe2} }, {0xDB, 1, {0x03} }, {0xDC, 1, {0x02} }, {0xDD, 1, {0x03} }, {0xDE, 1, {0x2d} }, {0xDF, 1, {0x03} }, {0xE0, 1, {0x3a} }, {0xE1, 1, {0x03} }, {0xE2, 1, {0x48} }, {0xE3, 1, {0x03} }, {0xE4, 1, {0x58} }, {0xE5, 1, {0x03} }, {0xE6, 1, {0x6a} }, {0xE7, 1, {0x03} }, {0xE8, 1, {0x80} }, {0xE9, 1, {0x03} }, {0xEA, 1, {0x9d} }, {0xEB, 1, {0x03} }, {0xEC, 1, {0xb7} }, {0xED, 1, {0x03} }, {0xEE, 1, {0xFF} }, /* G+ ,1,{}}, */ {0xEF, 1, {0x00} }, {0xF0, 1, {0x00} }, {0xF1, 1, {0x00} }, {0xF2, 1, {0x3e} }, {0xF3, 1, {0x00} }, {0xF4, 1, {0x6f} }, {0xF5, 1, {0x00} }, {0xF6, 1, {0x8f} }, {0xF7, 1, {0x00} }, {0xF8, 1, {0xa7} }, {0xF9, 1, {0x00} }, {0xFA, 1, {0xbc} }, {0xFF, 1, {0x21} }, /* Page 0,1,{ power-related setting */ {REGFLAG_UDELAY, 1, {} }, {0x00, 1, {0x00} }, {0x01, 1, {0xce} }, {0x02, 1, {0x00} }, {0x03, 1, {0xdd} }, {0x04, 1, {0x00} }, {0x05, 1, {0xec} }, {0x06, 1, {0x01} }, {0x07, 1, {0x1a} }, {0x08, 1, {0x01} }, {0x09, 1, {0x3e} }, {0x0A, 1, {0x01} }, {0x0B, 1, {0x76} }, {0x0C, 1, {0x01} }, {0x0D, 1, {0xa3} }, {0x0E, 1, {0x01} }, {0x0F, 1, {0xe9} }, {0x10, 1, {0x02} }, {0x11, 1, {0x20} }, {0x12, 1, {0x02} }, {0x13, 1, {0x22} }, {0x14, 1, {0x02} }, {0x15, 1, {0x56} }, {0x16, 1, {0x02} }, {0x17, 1, {0x8f} }, {0x18, 1, {0x02} }, {0x19, 1, {0xb2} }, {0x1A, 1, {0x02} }, {0x1B, 1, {0xe2} }, {0x1C, 1, {0x03} }, {0x1D, 1, {0x02} }, {0x1E, 1, {0x03} }, {0x1F, 1, {0x2d} }, {0x20, 1, {0x03} }, {0x21, 1, {0x3a} }, {0x22, 1, {0x03} }, {0x23, 1, {0x48} }, {0x24, 1, {0x03} }, {0x25, 1, {0x58} }, {0x26, 1, {0x03} }, {0x27, 1, {0x6a} }, {0x28, 1, {0x03} }, {0x29, 1, {0x80} }, {0x2A, 1, {0x03} }, {0x2B, 1, {0x9d} }, {0x2D, 1, {0x03} }, {0x2F, 1, {0xb7} }, {0x30, 1, {0x03} }, {0x31, 1, {0xFF} }, /* G- ,1,{}}, */ {0x32, 1, {0x00} }, {0x33, 1, {0x00} }, {0x34, 1, {0x00} }, {0x35, 1, {0x3e} }, {0x36, 1, {0x00} }, {0x37, 1, {0x6f} }, {0x38, 1, {0x00} }, {0x39, 1, {0x8f} }, {0x3A, 1, {0x00} }, {0x3B, 1, {0xa7} }, {0x3D, 1, {0x00} }, {0x3F, 1, {0xbc} }, {0x40, 1, {0x00} }, {0x41, 1, {0xce} }, {0x42, 1, {0x00} }, {0x43, 1, {0xdd} }, {0x44, 1, {0x00} }, {0x45, 1, {0xec} }, {0x46, 1, {0x01} }, {0x47, 1, {0x1a} }, {0x48, 1, {0x01} }, {0x49, 1, {0x3e} }, {0x4A, 1, {0x01} }, {0x4B, 1, {0x76} }, {0x4C, 1, {0x01} }, {0x4D, 1, {0xa3} }, {0x4E, 1, {0x01} }, {0x4F, 1, {0xe9} }, {0x50, 1, {0x02} }, {0x51, 1, {0x20} }, {0x52, 1, {0x02} }, {0x53, 1, {0x22} }, {0x54, 1, {0x02} }, {0x55, 1, {0x56} }, {0x56, 1, {0x02} }, {0x58, 1, {0x8f} }, {0x59, 1, {0x02} }, {0x5A, 1, {0xb2} }, {0x5B, 1, {0x02} }, {0x5C, 1, {0xe2} }, {0x5D, 1, {0x03} }, {0x5E, 1, {0x02} }, {0x5F, 1, {0x03} }, {0x60, 1, {0x2d} }, {0x61, 1, {0x03} }, {0x62, 1, {0x3a} }, {0x63, 1, {0x03} }, {0x64, 1, {0x48} }, {0x65, 1, {0x03} }, {0x66, 1, {0x58} }, {0x67, 1, {0x03} }, {0x68, 1, {0x6a} }, {0x69, 1, {0x03} }, {0x6A, 1, {0x80} }, {0x6B, 1, {0x03} }, {0x6C, 1, {0x9d} }, {0x6D, 1, {0x03} }, {0x6E, 1, {0xb7} }, {0x6F, 1, {0x03} }, {0x70, 1, {0xFF} }, /* B+ ,1,{}}, */ {0x71, 1, {0x00} }, {0x72, 1, {0x00} }, {0x73, 1, {0x00} }, {0x74, 1, {0x3e} }, {0x75, 1, {0x00} }, {0x76, 1, {0x6f} }, {0x77, 1, {0x00} }, {0x78, 1, {0x8f} }, {0x79, 1, {0x00} }, {0x7A, 1, {0xa7} }, {0x7B, 1, {0x00} }, {0x7C, 1, {0xbc} }, {0x7D, 1, {0x00} }, {0x7E, 1, {0xce} }, {0x7F, 1, {0x00} }, {0x80, 1, {0xdd} }, {0x81, 1, {0x00} }, {0x82, 1, {0xec} }, {0x83, 1, {0x01} }, {0x84, 1, {0x1a} }, {0x85, 1, {0x01} }, {0x86, 1, {0x3e} }, {0x87, 1, {0x01} }, {0x88, 1, {0x76} }, {0x89, 1, {0x01} }, {0x8A, 1, {0xa3} }, {0x8B, 1, {0x01} }, {0x8C, 1, {0xe9} }, {0x8D, 1, {0x02} }, {0x8E, 1, {0x20} }, {0x8F, 1, {0x02} }, {0x90, 1, {0x22} }, {0x91, 1, {0x02} }, {0x92, 1, {0x56} }, {0x93, 1, {0x02} }, {0x94, 1, {0x8f} }, {0x95, 1, {0x02} }, {0x96, 1, {0xb2} }, {0x97, 1, {0x02} }, {0x98, 1, {0xe2} }, {0x99, 1, {0x03} }, {0x9A, 1, {0x02} }, {0x9B, 1, {0x03} }, {0x9C, 1, {0x2d} }, {0x9D, 1, {0x03} }, {0x9E, 1, {0x3a} }, {0x9F, 1, {0x03} }, {0xA0, 1, {0x48} }, {0xA2, 1, {0x03} }, {0xA3, 1, {0x58} }, {0xA4, 1, {0x03} }, {0xA5, 1, {0x6a} }, {0xA6, 1, {0x03} }, {0xA7, 1, {0x80} }, {0xA9, 1, {0x03} }, {0xAA, 1, {0x9d} }, {0xAB, 1, {0x03} }, {0xAC, 1, {0xb7} }, {0xAD, 1, {0x03} }, {0xAE, 1, {0xFF} }, /* B- ,1,{}}, */ {0xAF, 1, {0x00} }, {0xB0, 1, {0x00} }, {0xB1, 1, {0x00} }, {0xB2, 1, {0x3e} }, {0xB3, 1, {0x00} }, {0xB4, 1, {0x6f} }, {0xB5, 1, {0x00} }, {0xB6, 1, {0x8f} }, {0xB7, 1, {0x00} }, {0xB8, 1, {0xa7} }, {0xB9, 1, {0x00} }, {0xBA, 1, {0xbc} }, {0xBB, 1, {0x00} }, {0xBC, 1, {0xce} }, {0xBD, 1, {0x00} }, {0xBE, 1, {0xdd} }, {0xBF, 1, {0x00} }, {0xC0, 1, {0xec} }, {0xC1, 1, {0x01} }, {0xC2, 1, {0x1a} }, {0xC3, 1, {0x01} }, {0xC4, 1, {0x3e} }, {0xC5, 1, {0x01} }, {0xC6, 1, {0x76} }, {0xC7, 1, {0x01} }, {0xC8, 1, {0xa3} }, {0xC9, 1, {0x01} }, {0xCA, 1, {0xe9} }, {0xCB, 1, {0x02} }, {0xCC, 1, {0x20} }, {0xCD, 1, {0x02} }, {0xCE, 1, {0x22} }, {0xCF, 1, {0x02} }, {0xD0, 1, {0x56} }, {0xD1, 1, {0x02} }, {0xD2, 1, {0x8f} }, {0xD3, 1, {0x02} }, {0xD4, 1, {0xb2} }, {0xD5, 1, {0x02} }, {0xD6, 1, {0xe2} }, {0xD7, 1, {0x03} }, {0xD8, 1, {0x02} }, {0xD9, 1, {0x03} }, {0xDA, 1, {0x2d} }, {0xDB, 1, {0x03} }, {0xDC, 1, {0x3a} }, {0xDD, 1, {0x03} }, {0xDE, 1, {0x48} }, {0xDF, 1, {0x03} }, {0xE0, 1, {0x58} }, {0xE1, 1, {0x03} }, {0xE2, 1, {0x6a} }, {0xE3, 1, {0x03} }, {0xE4, 1, {0x80} }, {0xE5, 1, {0x03} }, {0xE6, 1, {0x9d} }, {0xE7, 1, {0x03} }, {0xE8, 1, {0xb7} }, {0xE9, 1, {0x03} }, {0xEA, 1, {0xFF} }, {0xFF, 1, {0x21} }, /* Page ,1,{ Gamma Default Update */ {REGFLAG_UDELAY, 1, {} }, {0xEB, 1, {0x30} }, {0xEC, 1, {0x17} }, {0xED, 1, {0x20} }, {0xEE, 1, {0x0F} }, {0xEF, 1, {0x1F} }, {0xF0, 1, {0x0F} }, {0xF1, 1, {0x0F} }, {0xF2, 1, {0x07} }, {0xFF, 1, {0x23} }, /* CMD2 Page 3 Entrance */ {REGFLAG_UDELAY, 1, {} }, {0x08, 1, {0x04} }, /* image.first */ {0xFF, 1, {0x10} }, /* Return To CMD1 */ {REGFLAG_UDELAY, 1, {} }, {0x35, 1, {0x00} }, {0x44, 2, {0x05, 0x00} }, {0x11, 0, {} }, #ifndef LCM_SET_DISPLAY_ON_DELAY {REGFLAG_DELAY, 120, {} }, {0x29, 0, {} }, #endif /* {0x51,1,{0xFF}},//writedisplay brightness */ }; #ifdef LCM_SET_DISPLAY_ON_DELAY /* to reduce init time, we move 120ms delay to lcm_set_display_on() !! */ static struct LCM_setting_table set_display_on[] = { {0x29, 0, {} }, }; #endif #if 0 static struct LCM_setting_table lcm_set_window[] = { {0x2A, 4, {0x00, 0x00, (FRAME_WIDTH >> 8), (FRAME_WIDTH & 0xFF)} }, {0x2B, 4, {0x00, 0x00, (FRAME_HEIGHT >> 8), (FRAME_HEIGHT & 0xFF)} }, {REGFLAG_END_OF_TABLE, 0x00, {} } }; #endif #if 0 static struct LCM_setting_table lcm_sleep_out_setting[] = { /* Sleep Out */ {0x11, 1, {0x00} }, {REGFLAG_DELAY, 120, {} }, /* Display ON */ {0x29, 1, {0x00} }, {REGFLAG_DELAY, 20, {} }, {REGFLAG_END_OF_TABLE, 0x00, {} } }; static struct LCM_setting_table lcm_deep_sleep_mode_in_setting[] = { /* Display off sequence */ {0x28, 1, {0x00} }, {REGFLAG_DELAY, 20, {} }, /* Sleep Mode On */ {0x10, 1, {0x00} }, {REGFLAG_DELAY, 120, {} }, {REGFLAG_END_OF_TABLE, 0x00, {} } }; #endif static struct LCM_setting_table bl_level[] = { {0x51, 1, {0xFF} }, {REGFLAG_END_OF_TABLE, 0x00, {} } }; static void push_table(struct LCM_setting_table *table, unsigned int count, unsigned char force_update) { unsigned int i; for (i = 0; i < count; i++) { unsigned cmd; cmd = table[i].cmd; switch (cmd) { case REGFLAG_DELAY: if (table[i].count <= 10) MDELAY(table[i].count); else MDELAY(table[i].count); break; case REGFLAG_UDELAY: UDELAY(table[i].count); break; case REGFLAG_END_OF_TABLE: break; default: dsi_set_cmdq_V2(cmd, table[i].count, table[i].para_list, force_update); } } } /* --------------------------------------------------------------------------- */ /* LCM Driver Implementations */ /* --------------------------------------------------------------------------- */ static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util) { memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS)); } static void lcm_get_params(LCM_PARAMS *params) { memset(params, 0, sizeof(LCM_PARAMS)); params->type = LCM_TYPE_DSI; params->width = FRAME_WIDTH; params->height = FRAME_HEIGHT; params->virtual_width = VIRTUAL_WIDTH; params->virtual_height = VIRTUAL_HEIGHT; #if (LCM_DSI_CMD_MODE) params->dsi.mode = CMD_MODE; params->dsi.switch_mode = SYNC_PULSE_VDO_MODE; #else params->dsi.mode = SYNC_PULSE_VDO_MODE; params->dsi.switch_mode = CMD_MODE; #endif params->dsi.switch_mode_enable = 0; /* DSI */ /* Command mode setting */ params->dsi.LANE_NUM = LCM_FOUR_LANE; /* The following defined the fomat for data coming from LCD engine. */ params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB; params->dsi.data_format.trans_seq = LCM_DSI_TRANS_SEQ_MSB_FIRST; params->dsi.data_format.padding = LCM_DSI_PADDING_ON_LSB; params->dsi.data_format.format = LCM_DSI_FORMAT_RGB888; /* Highly depends on LCD driver capability. */ params->dsi.packet_size = 256; /* video mode timing */ params->dsi.PS = LCM_PACKED_PS_24BIT_RGB888; params->dsi.vertical_sync_active = 2; params->dsi.vertical_backporch = 8; params->dsi.vertical_frontporch = 10; params->dsi.vertical_frontporch_for_low_power = 400; params->dsi.vertical_active_line = VIRTUAL_HEIGHT; params->dsi.horizontal_sync_active = 10; params->dsi.horizontal_backporch = 20; params->dsi.horizontal_frontporch = 40; params->dsi.horizontal_active_pixel = VIRTUAL_WIDTH; params->dsi.ssc_disable = 1; #ifndef MACH_FPGA #if (LCM_DSI_CMD_MODE) params->dsi.PLL_CLOCK = 420; /* this value must be in MTK suggested table */ #else params->dsi.PLL_CLOCK = 440; /* this value must be in MTK suggested table */ #endif #else params->dsi.pll_div1 = 0; params->dsi.pll_div2 = 0; params->dsi.fbk_div = 0x1; #endif params->dsi.CLK_HS_POST = 36; params->dsi.clk_lp_per_line_enable = 0; params->dsi.esd_check_enable = 1; params->dsi.customization_esd_check_enable = 0; params->dsi.lcm_esd_check_table[0].cmd = 0x53; params->dsi.lcm_esd_check_table[0].count = 1; params->dsi.lcm_esd_check_table[0].para_list[0] = 0x24; #ifdef MTK_ROUND_CORNER_SUPPORT params->round_corner_params.round_corner_en = 1; params->round_corner_params.full_content = 0; params->round_corner_params.w = ROUND_CORNER_W; params->round_corner_params.h = ROUND_CORNER_H; params->round_corner_params.lt_addr = left_top; params->round_corner_params.lb_addr = left_bottom; params->round_corner_params.rt_addr = right_top; params->round_corner_params.rb_addr = right_bottom; #endif } static void lcm_init_power(void) { /*#ifndef MACH_FPGA #ifdef BUILD_LK mt6325_upmu_set_rg_vgp1_en(1); #else LCM_LOGI("%s, begin\n", __func__); hwPowerOn(MT6325_POWER_LDO_VGP1, VOL_DEFAULT, "LCM_DRV"); LCM_LOGI("%s, end\n", __func__); #endif #endif*/ } static void lcm_suspend_power(void) { /*#ifndef MACH_FPGA #ifdef BUILD_LK mt6325_upmu_set_rg_vgp1_en(0); #else LCM_LOGI("%s, begin\n", __func__); hwPowerDown(MT6325_POWER_LDO_VGP1, "LCM_DRV"); LCM_LOGI("%s, end\n", __func__); #endif #endif*/ } static void lcm_resume_power(void) { /*#ifndef MACH_FPGA #ifdef BUILD_LK mt6325_upmu_set_rg_vgp1_en(1); #else LCM_LOGI("%s, begin\n", __func__); hwPowerOn(MT6325_POWER_LDO_VGP1, VOL_DEFAULT, "LCM_DRV"); LCM_LOGI("%s, end\n", __func__); #endif #endif*/ } #ifdef LCM_SET_DISPLAY_ON_DELAY static U32 lcm_init_tick = 0; static int is_display_on = 0; #endif static void lcm_init(void) { int ret = 0; SET_RESET_PIN(0); #ifndef MACH_FPGA /*config rt5081 register 0xB2[7:6]=0x3, that is set db_delay=4ms.*/ ret = PMU_REG_MASK(0xB2, (0x3 << 6), (0x3 << 6)); /* set AVDD 5.4v, (4v+28*0.05v) */ /*ret = RT5081_write_byte(0xB3, (1 << 6) | 28);*/ ret = PMU_REG_MASK(0xB3, 28, (0x3F << 0)); if (ret < 0) LCM_LOGI("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB3); else LCM_LOGI("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB3); /* set AVEE */ /*ret = RT5081_write_byte(0xB4, (1 << 6) | 28);*/ ret = PMU_REG_MASK(0xB4, 28, (0x3F << 0)); if (ret < 0) LCM_LOGI("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB4); else LCM_LOGI("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB4); /* enable AVDD & AVEE */ /* 0x12--default value; bit3--Vneg; bit6--Vpos; */ /*ret = RT5081_write_byte(0xB1, 0x12 | (1<<3) | (1<<6));*/ ret = PMU_REG_MASK(0xB1, (1<<3) | (1<<6), (1<<3) | (1<<6)); if (ret < 0) LCM_LOGI("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB1); else LCM_LOGI("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB1); MDELAY(15); #endif SET_RESET_PIN(1); MDELAY(1); SET_RESET_PIN(0); MDELAY(10); SET_RESET_PIN(1); MDELAY(10); push_table(init_setting, sizeof(init_setting) / sizeof(struct LCM_setting_table), 1); #ifdef LCM_SET_DISPLAY_ON_DELAY lcm_init_tick = gpt4_get_current_tick(); is_display_on = 0; #endif } #ifdef LCM_SET_DISPLAY_ON_DELAY static int lcm_set_display_on(void) { U32 timeout_tick, i = 0; if (is_display_on) return 0; /* we need to wait 120ms after lcm init to set display on */ timeout_tick = gpt4_time2tick_ms(120); while(!gpt4_timeout_tick(lcm_init_tick, timeout_tick)) { i++; if (i % 1000 == 0) { LCM_LOGI("nt35695B %s error: i=%u,lcm_init_tick=%u,cur_tick=%u\n", __func__, i, lcm_init_tick, gpt4_get_current_tick()); } } push_table(set_display_on, sizeof(set_display_on) / sizeof(struct LCM_setting_table), 1); is_display_on = 1; return 0; } #endif static void lcm_suspend(void) { int ret; push_table(lcm_suspend_setting, sizeof(lcm_suspend_setting) / sizeof(struct LCM_setting_table), 1); #ifndef MACH_FPGA /* enable AVDD & AVEE */ /* 0x12--default value; bit3--Vneg; bit6--Vpos; */ /*ret = RT5081_write_byte(0xB1, 0x12);*/ ret = PMU_REG_MASK(0xB1, (0<<3) | (0<<6), (1<<3) | (1<<6)); if (ret < 0) LCM_LOGI("nt35695----tps6132----cmd=%0x--i2c write error----\n", 0xB1); else LCM_LOGI("nt35695----tps6132----cmd=%0x--i2c write success----\n", 0xB1); MDELAY(5); #endif SET_RESET_PIN(0); MDELAY(10); } static void lcm_resume(void) { lcm_init(); } static void lcm_update(unsigned int x, unsigned int y, unsigned int width, unsigned int height) { unsigned int x0 = x; unsigned int y0 = y; unsigned int x1 = x0 + width - 1; unsigned int y1 = y0 + height - 1; unsigned char x0_MSB = ((x0 >> 8) & 0xFF); unsigned char x0_LSB = (x0 & 0xFF); unsigned char x1_MSB = ((x1 >> 8) & 0xFF); unsigned char x1_LSB = (x1 & 0xFF); unsigned char y0_MSB = ((y0 >> 8) & 0xFF); unsigned char y0_LSB = (y0 & 0xFF); unsigned char y1_MSB = ((y1 >> 8) & 0xFF); unsigned char y1_LSB = (y1 & 0xFF); unsigned int data_array[16]; #ifdef LCM_SET_DISPLAY_ON_DELAY lcm_set_display_on(); #endif data_array[0] = 0x00053902; data_array[1] = (x1_MSB << 24) | (x0_LSB << 16) | (x0_MSB << 8) | 0x2a; data_array[2] = (x1_LSB); dsi_set_cmdq(data_array, 3, 1); data_array[0] = 0x00053902; data_array[1] = (y1_MSB << 24) | (y0_LSB << 16) | (y0_MSB << 8) | 0x2b; data_array[2] = (y1_LSB); dsi_set_cmdq(data_array, 3, 1); data_array[0] = 0x002c3909; dsi_set_cmdq(data_array, 1, 0); } static unsigned int lcm_compare_id(void) { unsigned int id = 0; unsigned int version_id; unsigned char buffer[2]; unsigned int array[16]; SET_RESET_PIN(1); SET_RESET_PIN(0); MDELAY(1); SET_RESET_PIN(1); MDELAY(20); array[0] = 0x00023700; /* read id return two byte,version and id */ dsi_set_cmdq(array, 1, 1); read_reg_v2(0xF4, buffer, 2); id = buffer[0]; /* we only need ID */ read_reg_v2(0xDB, buffer, 1); version_id = buffer[0]; LCM_LOGI("%s,nt35695_id=0x%08x,version_id=0x%x\n", __func__, id, version_id); if (id == LCM_ID_NT35695 && version_id == 0x80) return 1; else return 0; } /* return TRUE: need recovery */ /* return FALSE: No need recovery */ static unsigned int lcm_esd_check(void) { #ifndef BUILD_LK char buffer[3]; int array[4]; array[0] = 0x00013700; dsi_set_cmdq(array, 1, 1); read_reg_v2(0x53, buffer, 1); if (buffer[0] != 0x24) { LCM_LOGI("[LCM ERROR] [0x53]=0x%02x\n", buffer[0]); return TRUE; } else { LCM_LOGI("[LCM NORMAL] [0x53]=0x%02x\n", buffer[0]); return FALSE; } #else return FALSE; #endif } static unsigned int lcm_ata_check(unsigned char *buffer) { #ifndef BUILD_LK unsigned int ret = 0; unsigned int x0 = FRAME_WIDTH / 4; unsigned int x1 = FRAME_WIDTH * 3 / 4; unsigned char x0_MSB = ((x0 >> 8) & 0xFF); unsigned char x0_LSB = (x0 & 0xFF); unsigned char x1_MSB = ((x1 >> 8) & 0xFF); unsigned char x1_LSB = (x1 & 0xFF); unsigned int data_array[3]; unsigned char read_buf[4]; LCM_LOGI("ATA check size = 0x%x,0x%x,0x%x,0x%x\n", x0_MSB, x0_LSB, x1_MSB, x1_LSB); data_array[0] = 0x0005390A; /* HS packet */ data_array[1] = (x1_MSB << 24) | (x0_LSB << 16) | (x0_MSB << 8) | 0x2a; data_array[2] = (x1_LSB); dsi_set_cmdq(data_array, 3, 1); data_array[0] = 0x00043700; /* read id return two byte,version and id */ dsi_set_cmdq(data_array, 1, 1); read_reg_v2(0x2A, read_buf, 4); if ((read_buf[0] == x0_MSB) && (read_buf[1] == x0_LSB) && (read_buf[2] == x1_MSB) && (read_buf[3] == x1_LSB)) ret = 1; else ret = 0; x0 = 0; x1 = FRAME_WIDTH - 1; x0_MSB = ((x0 >> 8) & 0xFF); x0_LSB = (x0 & 0xFF); x1_MSB = ((x1 >> 8) & 0xFF); x1_LSB = (x1 & 0xFF); data_array[0] = 0x0005390A; /* HS packet */ data_array[1] = (x1_MSB << 24) | (x0_LSB << 16) | (x0_MSB << 8) | 0x2a; data_array[2] = (x1_LSB); dsi_set_cmdq(data_array, 3, 1); return ret; #else return 0; #endif } static void lcm_setbacklight_cmdq(void *handle, unsigned int level) { LCM_LOGI("%s,nt35695 backlight: level = %d\n", __func__, level); bl_level[0].para_list[0] = level; push_table(bl_level, sizeof(bl_level) / sizeof(struct LCM_setting_table), 1); } static void lcm_setbacklight(unsigned int level) { LCM_LOGI("%s,nt35695 backlight: level = %d\n", __func__, level); bl_level[0].para_list[0] = level; push_table(bl_level, sizeof(bl_level) / sizeof(struct LCM_setting_table), 1); } static void *lcm_switch_mode(int mode) { #ifndef BUILD_LK /* customization: 1. V2C config 2 values, C2V config 1 value; 2. config mode control register */ if (mode == 0) { /* V2C */ lcm_switch_mode_cmd.mode = CMD_MODE; lcm_switch_mode_cmd.addr = 0xBB; /* mode control addr */ lcm_switch_mode_cmd.val[0] = 0x13; /* enabel GRAM firstly, ensure writing one frame to GRAM */ lcm_switch_mode_cmd.val[1] = 0x10; /* disable video mode secondly */ } else { /* C2V */ lcm_switch_mode_cmd.mode = SYNC_PULSE_VDO_MODE; lcm_switch_mode_cmd.addr = 0xBB; lcm_switch_mode_cmd.val[0] = 0x03; /* disable GRAM and enable video mode */ } return (void *)(&lcm_switch_mode_cmd); #else return NULL; #endif } LCM_DRIVER nt35695_fhd_dsi_vdo_truly_rt5081_hdp_20_9_lcm_drv = { .name = "nt35695_fhd_dsi_vdo_truly_rt5081_hdp_20_9_drv", .set_util_funcs = lcm_set_util_funcs, .get_params = lcm_get_params, .init = lcm_init, .suspend = lcm_suspend, .resume = lcm_resume, .compare_id = lcm_compare_id, .init_power = lcm_init_power, .resume_power = lcm_resume_power, .suspend_power = lcm_suspend_power, .esd_check = lcm_esd_check, .set_backlight = lcm_setbacklight, .ata_check = lcm_ata_check, .update = lcm_update, .switch_mode = lcm_switch_mode, };
997302.c
#include <door.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <time.h> #include <err.h> int main(int argc, char** argv) { time_t t[2]; char* path = "proxy.door"; int proxy = open(path, O_RDONLY); if (proxy == -1) err(1, "Could not open door"); door_arg_t args = {0}; int result = door_call(proxy, &args); if (result == -1) err(1, "Could not call door"); door_desc_t* w_descriptor = args.desc_ptr; int server = w_descriptor->d_data.d_desc.d_descriptor; result = door_call(server, &args); if (result == -1) err(1, "Could not call door"); printf("data: %.*s\n", args.data_size, args.data_ptr); return 0; }
642528.c
#include <sys/stat.h> int main (void) { /* This will fail to compile if S_IRGRP doesn't exist. */ return S_IRGRP ; }
545983.c
/* ==================================================================== * Copyright (c) 2012 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" * * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * [email protected]. * * 5. Products derived from this software may not be called "OpenSSL" * nor may "OpenSSL" appear in their names without prior written * permission of the OpenSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit (http://www.openssl.org/)" * * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This product includes cryptographic software written by Eric Young * ([email protected]). This product includes software written by Tim * Hudson ([email protected]). */ #include <assert.h> #include <string.h> #include <CJWTKitBoringSSL_digest.h> #include <CJWTKitBoringSSL_nid.h> #include <CJWTKitBoringSSL_sha.h> #include "../internal.h" #include "internal.h" #include "../fipsmodule/cipher/internal.h" int EVP_tls_cbc_remove_padding(crypto_word_t *out_padding_ok, size_t *out_len, const uint8_t *in, size_t in_len, size_t block_size, size_t mac_size) { const size_t overhead = 1 /* padding length byte */ + mac_size; // These lengths are all public so we can test them in non-constant time. if (overhead > in_len) { return 0; } size_t padding_length = in[in_len - 1]; crypto_word_t good = constant_time_ge_w(in_len, overhead + padding_length); // The padding consists of a length byte at the end of the record and // then that many bytes of padding, all with the same value as the // length byte. Thus, with the length byte included, there are i+1 // bytes of padding. // // We can't check just |padding_length+1| bytes because that leaks // decrypted information. Therefore we always have to check the maximum // amount of padding possible. (Again, the length of the record is // public information so we can use it.) size_t to_check = 256; // maximum amount of padding, inc length byte. if (to_check > in_len) { to_check = in_len; } for (size_t i = 0; i < to_check; i++) { uint8_t mask = constant_time_ge_8(padding_length, i); uint8_t b = in[in_len - 1 - i]; // The final |padding_length+1| bytes should all have the value // |padding_length|. Therefore the XOR should be zero. good &= ~(mask & (padding_length ^ b)); } // If any of the final |padding_length+1| bytes had the wrong value, // one or more of the lower eight bits of |good| will be cleared. good = constant_time_eq_w(0xff, good & 0xff); // Always treat |padding_length| as zero on error. If, assuming block size of // 16, a padding of [<15 arbitrary bytes> 15] treated |padding_length| as 16 // and returned -1, distinguishing good MAC and bad padding from bad MAC and // bad padding would give POODLE's padding oracle. padding_length = good & (padding_length + 1); *out_len = in_len - padding_length; *out_padding_ok = good; return 1; } void EVP_tls_cbc_copy_mac(uint8_t *out, size_t md_size, const uint8_t *in, size_t in_len, size_t orig_len) { uint8_t rotated_mac1[EVP_MAX_MD_SIZE], rotated_mac2[EVP_MAX_MD_SIZE]; uint8_t *rotated_mac = rotated_mac1; uint8_t *rotated_mac_tmp = rotated_mac2; // mac_end is the index of |in| just after the end of the MAC. size_t mac_end = in_len; size_t mac_start = mac_end - md_size; assert(orig_len >= in_len); assert(in_len >= md_size); assert(md_size <= EVP_MAX_MD_SIZE); assert(md_size > 0); // scan_start contains the number of bytes that we can ignore because // the MAC's position can only vary by 255 bytes. size_t scan_start = 0; // This information is public so it's safe to branch based on it. if (orig_len > md_size + 255 + 1) { scan_start = orig_len - (md_size + 255 + 1); } size_t rotate_offset = 0; uint8_t mac_started = 0; OPENSSL_memset(rotated_mac, 0, md_size); for (size_t i = scan_start, j = 0; i < orig_len; i++, j++) { if (j >= md_size) { j -= md_size; } crypto_word_t is_mac_start = constant_time_eq_w(i, mac_start); mac_started |= is_mac_start; uint8_t mac_ended = constant_time_ge_8(i, mac_end); rotated_mac[j] |= in[i] & mac_started & ~mac_ended; // Save the offset that |mac_start| is mapped to. rotate_offset |= j & is_mac_start; } // Now rotate the MAC. We rotate in log(md_size) steps, one for each bit // position. for (size_t offset = 1; offset < md_size; offset <<= 1, rotate_offset >>= 1) { // Rotate by |offset| iff the corresponding bit is set in // |rotate_offset|, placing the result in |rotated_mac_tmp|. const uint8_t skip_rotate = (rotate_offset & 1) - 1; for (size_t i = 0, j = offset; i < md_size; i++, j++) { if (j >= md_size) { j -= md_size; } rotated_mac_tmp[i] = constant_time_select_8(skip_rotate, rotated_mac[i], rotated_mac[j]); } // Swap pointers so |rotated_mac| contains the (possibly) rotated value. // Note the number of iterations and thus the identity of these pointers is // public information. uint8_t *tmp = rotated_mac; rotated_mac = rotated_mac_tmp; rotated_mac_tmp = tmp; } OPENSSL_memcpy(out, rotated_mac, md_size); } int EVP_sha1_final_with_secret_suffix(SHA_CTX *ctx, uint8_t out[SHA_DIGEST_LENGTH], const uint8_t *in, size_t len, size_t max_len) { // Bound the input length so |total_bits| below fits in four bytes. This is // redundant with TLS record size limits. This also ensures |input_idx| below // does not overflow. size_t max_len_bits = max_len << 3; if (ctx->Nh != 0 || (max_len_bits >> 3) != max_len || // Overflow ctx->Nl + max_len_bits < max_len_bits || ctx->Nl + max_len_bits > UINT32_MAX) { return 0; } // We need to hash the following into |ctx|: // // - ctx->data[:ctx->num] // - in[:len] // - A 0x80 byte // - However many zero bytes are needed to pad up to a block. // - Eight bytes of length. size_t num_blocks = (ctx->num + len + 1 + 8 + SHA_CBLOCK - 1) >> 6; size_t last_block = num_blocks - 1; size_t max_blocks = (ctx->num + max_len + 1 + 8 + SHA_CBLOCK - 1) >> 6; // The bounds above imply |total_bits| fits in four bytes. size_t total_bits = ctx->Nl + (len << 3); uint8_t length_bytes[4]; length_bytes[0] = (uint8_t)(total_bits >> 24); length_bytes[1] = (uint8_t)(total_bits >> 16); length_bytes[2] = (uint8_t)(total_bits >> 8); length_bytes[3] = (uint8_t)total_bits; // We now construct and process each expected block in constant-time. uint8_t block[SHA_CBLOCK] = {0}; uint32_t result[5] = {0}; // input_idx is the index into |in| corresponding to the current block. // However, we allow this index to overflow beyond |max_len|, to simplify the // 0x80 byte. size_t input_idx = 0; for (size_t i = 0; i < max_blocks; i++) { // Fill |block| with data from the partial block in |ctx| and |in|. We copy // as if we were hashing up to |max_len| and then zero the excess later. size_t block_start = 0; if (i == 0) { OPENSSL_memcpy(block, ctx->data, ctx->num); block_start = ctx->num; } if (input_idx < max_len) { size_t to_copy = SHA_CBLOCK - block_start; if (to_copy > max_len - input_idx) { to_copy = max_len - input_idx; } OPENSSL_memcpy(block + block_start, in + input_idx, to_copy); } // Zero any bytes beyond |len| and add the 0x80 byte. for (size_t j = block_start; j < SHA_CBLOCK; j++) { // input[idx] corresponds to block[j]. size_t idx = input_idx + j - block_start; // The barriers on |len| are not strictly necessary. However, without // them, GCC compiles this code by incorporating |len| into the loop // counter and subtracting it out later. This is still constant-time, but // it frustrates attempts to validate this. uint8_t is_in_bounds = constant_time_lt_8(idx, value_barrier_w(len)); uint8_t is_padding_byte = constant_time_eq_8(idx, value_barrier_w(len)); block[j] &= is_in_bounds; block[j] |= 0x80 & is_padding_byte; } input_idx += SHA_CBLOCK - block_start; // Fill in the length if this is the last block. crypto_word_t is_last_block = constant_time_eq_w(i, last_block); for (size_t j = 0; j < 4; j++) { block[SHA_CBLOCK - 4 + j] |= is_last_block & length_bytes[j]; } // Process the block and save the hash state if it is the final value. SHA1_Transform(ctx, block); for (size_t j = 0; j < 5; j++) { result[j] |= is_last_block & ctx->h[j]; } } // Write the output. for (size_t i = 0; i < 5; i++) { CRYPTO_store_u32_be(out + 4 * i, result[i]); } return 1; } int EVP_tls_cbc_record_digest_supported(const EVP_MD *md) { return EVP_MD_type(md) == NID_sha1; } int EVP_tls_cbc_digest_record(const EVP_MD *md, uint8_t *md_out, size_t *md_out_size, const uint8_t header[13], const uint8_t *data, size_t data_size, size_t data_plus_mac_plus_padding_size, const uint8_t *mac_secret, unsigned mac_secret_length) { if (EVP_MD_type(md) != NID_sha1) { // EVP_tls_cbc_record_digest_supported should have been called first to // check that the hash function is supported. assert(0); *md_out_size = 0; return 0; } if (mac_secret_length > SHA_CBLOCK) { // HMAC pads small keys with zeros and hashes large keys down. This function // should never reach the large key case. assert(0); return 0; } // Compute the initial HMAC block. uint8_t hmac_pad[SHA_CBLOCK]; OPENSSL_memset(hmac_pad, 0, sizeof(hmac_pad)); OPENSSL_memcpy(hmac_pad, mac_secret, mac_secret_length); for (size_t i = 0; i < SHA_CBLOCK; i++) { hmac_pad[i] ^= 0x36; } SHA_CTX ctx; SHA1_Init(&ctx); SHA1_Update(&ctx, hmac_pad, SHA_CBLOCK); SHA1_Update(&ctx, header, 13); // There are at most 256 bytes of padding, so we can compute the public // minimum length for |data_size|. size_t min_data_size = 0; if (data_plus_mac_plus_padding_size > SHA_DIGEST_LENGTH + 256) { min_data_size = data_plus_mac_plus_padding_size - SHA_DIGEST_LENGTH - 256; } // Hash the public minimum length directly. This reduces the number of blocks // that must be computed in constant-time. SHA1_Update(&ctx, data, min_data_size); // Hash the remaining data without leaking |data_size|. uint8_t mac_out[SHA_DIGEST_LENGTH]; if (!EVP_sha1_final_with_secret_suffix( &ctx, mac_out, data + min_data_size, data_size - min_data_size, data_plus_mac_plus_padding_size - min_data_size)) { return 0; } // Complete the HMAC in the standard manner. SHA1_Init(&ctx); for (size_t i = 0; i < SHA_CBLOCK; i++) { hmac_pad[i] ^= 0x6a; } SHA1_Update(&ctx, hmac_pad, SHA_CBLOCK); SHA1_Update(&ctx, mac_out, SHA_DIGEST_LENGTH); SHA1_Final(md_out, &ctx); *md_out_size = SHA_DIGEST_LENGTH; return 1; }
3663.c
#include <test.h> #include <sys/types.h> #include <sys/socket.h> #include <string.h> #include <assert.h> #include <unistd.h> #include <signal.h> #include "client.h" #include "daemon.h" static void test_connect(void) { char buf[512]; char *msg[] = { "CONNECT\n", "content-length:0\n", "accept-version:1.2\n", "login:guest\n", "passcode:guest\n", "\n", NULL, }; int sock, len, i; sock = connect_server(); CU_ASSERT(sock > 0); for(i=0; msg[i] != NULL; i++) { len = send(sock, msg[i], strlen(msg[i]), 0); assert(len > 0); } CU_ASSERT(send(sock, "\0", 1, 0) > 0); len = test_recv(sock, buf, sizeof(buf)); CU_ASSERT(len > 0); CU_ASSERT(strncmp(buf, "CONNECTED\n", 10) == 0); CU_ASSERT(close(sock) == 0); } int test_proto_connect(CU_pSuite suite) { suite = CU_add_suite("TestConnectFrame", NULL, NULL); if(suite == NULL) { return CU_ERROR; } CU_add_test(suite, "succeed in sending CONNECT frame", test_connect); return CU_SUCCESS; }
223742.c
/** * \addtogroup packetqueue * @{ */ /* * Copyright (c) 2009, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the Institute nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * This file is part of the Contiki operating system. * * $Id: packetqueue.c,v 1.1 2010/06/14 19:19:16 adamdunkels Exp $ */ /** * \file * Packet queue management * \author * Adam Dunkels <[email protected]> */ #include "sys/ctimer.h" #include "net/packetqueue.h" /*---------------------------------------------------------------------------*/ void packetqueue_init(struct packetqueue *q) { list_init(*q->list); memb_init(q->memb); } /*---------------------------------------------------------------------------*/ static void remove_queued_packet(void *item) { struct packetqueue_item *i = item; struct packetqueue *q = i->queue; list_remove(*q->list, i); queuebuf_free(i->buf); ctimer_stop(&i->lifetimer); memb_free(q->memb, i); /* printf("removing queued packet due to timeout\n");*/ } /*---------------------------------------------------------------------------*/ int packetqueue_enqueue_packetbuf(struct packetqueue *q, clock_time_t lifetime, void *ptr) { struct packetqueue_item *i; /* Allocate a memory block to hold the packet queue item. */ i = memb_alloc(q->memb); if(i == NULL) { return 0; } /* Allocate a queuebuf and copy the contents of the packetbuf into it. */ i->buf = queuebuf_new_from_packetbuf(); if(i->buf == NULL) { memb_free(q->memb, i); return 0; } i->queue = q; i->ptr = ptr; /* Setup a ctimer that removes the packet from the queue when its lifetime expires. If the lifetime is zero, we do not set a lifetimer. */ if(lifetime > 0) { ctimer_set(&i->lifetimer, lifetime, remove_queued_packet, i); } /* Add the item to the queue. */ list_add(*q->list, i); return 1; } /*---------------------------------------------------------------------------*/ struct packetqueue_item * packetqueue_first(struct packetqueue *q) { return list_head(*q->list); } /*---------------------------------------------------------------------------*/ void packetqueue_dequeue(struct packetqueue *q) { struct packetqueue_item *i; i = list_head(*q->list); if(i != NULL) { list_remove(*q->list, i); queuebuf_free(i->buf); ctimer_stop(&i->lifetimer); memb_free(q->memb, i); } } /*---------------------------------------------------------------------------*/ int packetqueue_len(struct packetqueue *q) { return list_length(*q->list); } /*---------------------------------------------------------------------------*/ struct queuebuf * packetqueue_queuebuf(struct packetqueue_item *i) { if(i != NULL) { return i->buf; } else { return NULL; } } /*---------------------------------------------------------------------------*/ void * packetqueue_ptr(struct packetqueue_item *i) { if(i != NULL) { return i->ptr; } else { return NULL; } } /*---------------------------------------------------------------------------*/ /** @} */
204004.c
/* * Copyright (c) 2014-2015 Etnaviv Project * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sub license, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * Authors: * Wladimir J. van der Laan <[email protected]> */ #include "etnaviv_emit.h" #include "etnaviv_blend.h" #include "etnaviv_compiler.h" #include "etnaviv_context.h" #include "etnaviv_rasterizer.h" #include "etnaviv_resource.h" #include "etnaviv_rs.h" #include "etnaviv_screen.h" #include "etnaviv_shader.h" #include "etnaviv_texture.h" #include "etnaviv_translate.h" #include "etnaviv_uniforms.h" #include "etnaviv_util.h" #include "etnaviv_zsa.h" #include "hw/common.xml.h" #include "hw/state.xml.h" #include "hw/state_blt.xml.h" #include "util/u_math.h" /* Queue a STALL command (queues 2 words) */ static inline void CMD_STALL(struct etna_cmd_stream *stream, uint32_t from, uint32_t to) { etna_cmd_stream_emit(stream, VIV_FE_STALL_HEADER_OP_STALL); etna_cmd_stream_emit(stream, VIV_FE_STALL_TOKEN_FROM(from) | VIV_FE_STALL_TOKEN_TO(to)); } void etna_stall(struct etna_cmd_stream *stream, uint32_t from, uint32_t to) { bool blt = (from == SYNC_RECIPIENT_BLT) || (to == SYNC_RECIPIENT_BLT); etna_cmd_stream_reserve(stream, blt ? 8 : 4); if (blt) { etna_emit_load_state(stream, VIVS_BLT_ENABLE >> 2, 1, 0); etna_cmd_stream_emit(stream, 1); } /* TODO: set bit 28/29 of token after BLT COPY_BUFFER */ etna_emit_load_state(stream, VIVS_GL_SEMAPHORE_TOKEN >> 2, 1, 0); etna_cmd_stream_emit(stream, VIVS_GL_SEMAPHORE_TOKEN_FROM(from) | VIVS_GL_SEMAPHORE_TOKEN_TO(to)); if (from == SYNC_RECIPIENT_FE) { /* if the frontend is to be stalled, queue a STALL frontend command */ CMD_STALL(stream, from, to); } else { /* otherwise, load the STALL token state */ etna_emit_load_state(stream, VIVS_GL_STALL_TOKEN >> 2, 1, 0); etna_cmd_stream_emit(stream, VIVS_GL_STALL_TOKEN_FROM(from) | VIVS_GL_STALL_TOKEN_TO(to)); } if (blt) { etna_emit_load_state(stream, VIVS_BLT_ENABLE >> 2, 1, 0); etna_cmd_stream_emit(stream, 0); } } #define EMIT_STATE(state_name, src_value) \ etna_coalsence_emit(stream, &coalesce, VIVS_##state_name, src_value) #define EMIT_STATE_FIXP(state_name, src_value) \ etna_coalsence_emit_fixp(stream, &coalesce, VIVS_##state_name, src_value) #define EMIT_STATE_RELOC(state_name, src_value) \ etna_coalsence_emit_reloc(stream, &coalesce, VIVS_##state_name, src_value) #define ETNA_3D_CONTEXT_SIZE (400) /* keep this number above "Total state updates (fixed)" from gen_weave_state tool */ static unsigned required_stream_size(struct etna_context *ctx) { unsigned size = ETNA_3D_CONTEXT_SIZE; /* stall + flush */ size += 2 + 4; /* vertex elements */ size += ctx->vertex_elements->num_elements + 1; /* uniforms - worst case (2 words per uniform load) */ size += ctx->shader.vs->uniforms.const_count * 2; size += ctx->shader.fs->uniforms.const_count * 2; /* shader */ size += ctx->shader_state.vs_inst_mem_size + 1; size += ctx->shader_state.ps_inst_mem_size + 1; /* DRAW_INDEXED_PRIMITIVES command */ size += 6; /* reserve for alignment etc. */ size += 64; return size; } /* Emit state that only exists on HALTI5+ */ static void emit_halti5_only_state(struct etna_context *ctx, int vs_output_count) { struct etna_cmd_stream *stream = ctx->stream; uint32_t dirty = ctx->dirty; struct etna_coalesce coalesce; etna_coalesce_start(stream, &coalesce); if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { /* Magic states (load balancing, inter-unit sync, buffers) */ /*00870*/ EMIT_STATE(VS_HALTI5_OUTPUT_COUNT, vs_output_count | ((vs_output_count * 0x10) << 8)); /*008A0*/ EMIT_STATE(VS_HALTI5_UNK008A0, 0x0001000e | ((0x110/vs_output_count) << 20)); for (int x = 0; x < 4; ++x) { /*008E0*/ EMIT_STATE(VS_HALTI5_OUTPUT(x), ctx->shader_state.VS_OUTPUT[x]); } } if (unlikely(dirty & (ETNA_DIRTY_VERTEX_ELEMENTS | ETNA_DIRTY_SHADER))) { for (int x = 0; x < 4; ++x) { /*008C0*/ EMIT_STATE(VS_HALTI5_INPUT(x), ctx->shader_state.VS_INPUT[x]); } } if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { /*00A90*/ EMIT_STATE(PA_VARYING_NUM_COMPONENTS(0), ctx->shader_state.GL_VARYING_NUM_COMPONENTS); /*00AA8*/ EMIT_STATE(PA_VS_OUTPUT_COUNT, vs_output_count); /*01080*/ EMIT_STATE(PS_VARYING_NUM_COMPONENTS(0), ctx->shader_state.GL_VARYING_NUM_COMPONENTS); /*03888*/ EMIT_STATE(GL_HALTI5_SH_SPECIALS, ctx->shader_state.GL_HALTI5_SH_SPECIALS); } etna_coalesce_end(stream, &coalesce); } /* Emit state that no longer exists on HALTI5 */ static void emit_pre_halti5_state(struct etna_context *ctx) { struct etna_cmd_stream *stream = ctx->stream; uint32_t dirty = ctx->dirty; struct etna_coalesce coalesce; etna_coalesce_start(stream, &coalesce); if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { /*00800*/ EMIT_STATE(VS_END_PC, ctx->shader_state.VS_END_PC); } if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { for (int x = 0; x < 4; ++x) { /*00810*/ EMIT_STATE(VS_OUTPUT(x), ctx->shader_state.VS_OUTPUT[x]); } } if (unlikely(dirty & (ETNA_DIRTY_VERTEX_ELEMENTS | ETNA_DIRTY_SHADER))) { for (int x = 0; x < 4; ++x) { /*00820*/ EMIT_STATE(VS_INPUT(x), ctx->shader_state.VS_INPUT[x]); } } if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { /*00838*/ EMIT_STATE(VS_START_PC, ctx->shader_state.VS_START_PC); } if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { for (int x = 0; x < 10; ++x) { /*00A40*/ EMIT_STATE(PA_SHADER_ATTRIBUTES(x), ctx->shader_state.PA_SHADER_ATTRIBUTES[x]); } } if (unlikely(dirty & (ETNA_DIRTY_FRAMEBUFFER))) { /*00E04*/ EMIT_STATE(RA_MULTISAMPLE_UNK00E04, ctx->framebuffer.RA_MULTISAMPLE_UNK00E04); for (int x = 0; x < 4; ++x) { /*00E10*/ EMIT_STATE(RA_MULTISAMPLE_UNK00E10(x), ctx->framebuffer.RA_MULTISAMPLE_UNK00E10[x]); } for (int x = 0; x < 16; ++x) { /*00E40*/ EMIT_STATE(RA_CENTROID_TABLE(x), ctx->framebuffer.RA_CENTROID_TABLE[x]); } } if (unlikely(dirty & (ETNA_DIRTY_SHADER | ETNA_DIRTY_FRAMEBUFFER))) { /*01000*/ EMIT_STATE(PS_END_PC, ctx->shader_state.PS_END_PC); } if (unlikely(dirty & (ETNA_DIRTY_SHADER | ETNA_DIRTY_FRAMEBUFFER))) { /*01018*/ EMIT_STATE(PS_START_PC, ctx->shader_state.PS_START_PC); } if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { /*03820*/ EMIT_STATE(GL_VARYING_NUM_COMPONENTS, ctx->shader_state.GL_VARYING_NUM_COMPONENTS); for (int x = 0; x < 2; ++x) { /*03828*/ EMIT_STATE(GL_VARYING_COMPONENT_USE(x), ctx->shader_state.GL_VARYING_COMPONENT_USE[x]); } } etna_coalesce_end(stream, &coalesce); } /* Weave state before draw operation. This function merges all the compiled * state blocks under the context into one device register state. Parts of * this state that are changed since last call (dirty) will be uploaded as * state changes in the command buffer. */ void etna_emit_state(struct etna_context *ctx) { struct etna_cmd_stream *stream = ctx->stream; /* Pre-reserve the command buffer space which we are likely to need. * This must cover all the state emitted below, and the following * draw command. */ etna_cmd_stream_reserve(stream, required_stream_size(ctx)); uint32_t dirty = ctx->dirty; /* Pre-processing: see what caches we need to flush before making state changes. */ uint32_t to_flush = 0; if (unlikely(dirty & (ETNA_DIRTY_BLEND))) { /* Need flush COLOR when changing PE.COLOR_FORMAT.OVERWRITE. */ #if 0 /* TODO*/ if ((ctx->gpu3d.PE_COLOR_FORMAT & VIVS_PE_COLOR_FORMAT_OVERWRITE) != (etna_blend_state(ctx->blend)->PE_COLOR_FORMAT & VIVS_PE_COLOR_FORMAT_OVERWRITE)) #endif to_flush |= VIVS_GL_FLUSH_CACHE_COLOR; } if (unlikely(dirty & (ETNA_DIRTY_TEXTURE_CACHES))) to_flush |= VIVS_GL_FLUSH_CACHE_TEXTURE; if (unlikely(dirty & (ETNA_DIRTY_FRAMEBUFFER))) /* Framebuffer config changed? */ to_flush |= VIVS_GL_FLUSH_CACHE_COLOR | VIVS_GL_FLUSH_CACHE_DEPTH; if (DBG_ENABLED(ETNA_DBG_CFLUSH_ALL)) to_flush |= VIVS_GL_FLUSH_CACHE_TEXTURE | VIVS_GL_FLUSH_CACHE_COLOR | VIVS_GL_FLUSH_CACHE_DEPTH; if (to_flush) { etna_set_state(stream, VIVS_GL_FLUSH_CACHE, to_flush); etna_stall(stream, SYNC_RECIPIENT_RA, SYNC_RECIPIENT_PE); } /* Flush TS cache before changing TS configuration. */ if (unlikely(dirty & ETNA_DIRTY_TS)) { etna_set_state(stream, VIVS_TS_FLUSH_CACHE, VIVS_TS_FLUSH_CACHE_FLUSH); } /* Update vertex elements. This is different from any of the other states, in that * a) the number of vertex elements written matters: so write only active ones * b) the vertex element states must all be written: do not skip entries that stay the same */ if (dirty & (ETNA_DIRTY_VERTEX_ELEMENTS)) { if (ctx->specs.halti >= 5) { /*17800*/ etna_set_state_multi(stream, VIVS_NFE_GENERIC_ATTRIB_CONFIG0(0), ctx->vertex_elements->num_elements, ctx->vertex_elements->NFE_GENERIC_ATTRIB_CONFIG0); /*17A00*/ etna_set_state_multi(stream, VIVS_NFE_GENERIC_ATTRIB_SCALE(0), ctx->vertex_elements->num_elements, ctx->vertex_elements->NFE_GENERIC_ATTRIB_SCALE); /*17A80*/ etna_set_state_multi(stream, VIVS_NFE_GENERIC_ATTRIB_CONFIG1(0), ctx->vertex_elements->num_elements, ctx->vertex_elements->NFE_GENERIC_ATTRIB_CONFIG1); } else { /* Special case: vertex elements must always be sent in full if changed */ /*00600*/ etna_set_state_multi(stream, VIVS_FE_VERTEX_ELEMENT_CONFIG(0), ctx->vertex_elements->num_elements, ctx->vertex_elements->FE_VERTEX_ELEMENT_CONFIG); if (ctx->specs.halti >= 2) { /*00780*/ etna_set_state_multi(stream, VIVS_FE_GENERIC_ATTRIB_SCALE(0), ctx->vertex_elements->num_elements, ctx->vertex_elements->NFE_GENERIC_ATTRIB_SCALE); } } } unsigned vs_output_count = etna_rasterizer_state(ctx->rasterizer)->point_size_per_vertex ? ctx->shader_state.VS_OUTPUT_COUNT_PSIZE : ctx->shader_state.VS_OUTPUT_COUNT; /* The following code is originally generated by gen_merge_state.py, to * emit state in increasing order of address (this makes it possible to merge * consecutive register updates into one SET_STATE command) * * There have been some manual changes, where the weaving operation is not * simply bitwise or: * - scissor fixp * - num vertex elements * - scissor handling * - num samplers * - texture lod * - ETNA_DIRTY_TS * - removed ETNA_DIRTY_BASE_SETUP statements -- these are guaranteed to not * change anyway * - PS / framebuffer interaction for MSAA * - move update of GL_MULTI_SAMPLE_CONFIG first * - add unlikely()/likely() */ struct etna_coalesce coalesce; etna_coalesce_start(stream, &coalesce); /* begin only EMIT_STATE -- make sure no new etna_reserve calls are done here * directly * or indirectly */ /* multi sample config is set first, and outside of the normal sorting * order, as changing the multisample state clobbers PS.INPUT_COUNT (and * possibly PS.TEMP_REGISTER_CONTROL). */ if (unlikely(dirty & (ETNA_DIRTY_FRAMEBUFFER | ETNA_DIRTY_SAMPLE_MASK))) { uint32_t val = VIVS_GL_MULTI_SAMPLE_CONFIG_MSAA_ENABLES(ctx->sample_mask); val |= ctx->framebuffer.GL_MULTI_SAMPLE_CONFIG; /*03818*/ EMIT_STATE(GL_MULTI_SAMPLE_CONFIG, val); } if (likely(dirty & (ETNA_DIRTY_INDEX_BUFFER))) { /*00644*/ EMIT_STATE_RELOC(FE_INDEX_STREAM_BASE_ADDR, &ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR); /*00648*/ EMIT_STATE(FE_INDEX_STREAM_CONTROL, ctx->index_buffer.FE_INDEX_STREAM_CONTROL); } if (likely(dirty & (ETNA_DIRTY_INDEX_BUFFER))) { /*00674*/ EMIT_STATE(FE_PRIMITIVE_RESTART_INDEX, ctx->index_buffer.FE_PRIMITIVE_RESTART_INDEX); } if (likely(dirty & (ETNA_DIRTY_VERTEX_BUFFERS))) { if (ctx->specs.halti >= 2) { /* HALTI2+: NFE_VERTEX_STREAMS */ for (int x = 0; x < ctx->vertex_buffer.count; ++x) { /*14600*/ EMIT_STATE_RELOC(NFE_VERTEX_STREAMS_BASE_ADDR(x), &ctx->vertex_buffer.cvb[x].FE_VERTEX_STREAM_BASE_ADDR); } for (int x = 0; x < ctx->vertex_buffer.count; ++x) { if (ctx->vertex_buffer.cvb[x].FE_VERTEX_STREAM_BASE_ADDR.bo) { /*14640*/ EMIT_STATE(NFE_VERTEX_STREAMS_CONTROL(x), ctx->vertex_buffer.cvb[x].FE_VERTEX_STREAM_CONTROL); } } for (int x = 0; x < ctx->vertex_buffer.count; ++x) { if (ctx->vertex_buffer.cvb[x].FE_VERTEX_STREAM_BASE_ADDR.bo) { /*14680*/ EMIT_STATE(NFE_VERTEX_STREAMS_UNK14680(x), ctx->vertex_buffer.cvb[x].FE_VERTEX_STREAM_UNK14680); } } } else if(ctx->specs.stream_count >= 1) { /* hw w/ multiple vertex streams */ for (int x = 0; x < ctx->vertex_buffer.count; ++x) { /*00680*/ EMIT_STATE_RELOC(FE_VERTEX_STREAMS_BASE_ADDR(x), &ctx->vertex_buffer.cvb[x].FE_VERTEX_STREAM_BASE_ADDR); } for (int x = 0; x < ctx->vertex_buffer.count; ++x) { if (ctx->vertex_buffer.cvb[x].FE_VERTEX_STREAM_BASE_ADDR.bo) { /*006A0*/ EMIT_STATE(FE_VERTEX_STREAMS_CONTROL(x), ctx->vertex_buffer.cvb[x].FE_VERTEX_STREAM_CONTROL); } } } else { /* hw w/ single vertex stream */ /*0064C*/ EMIT_STATE_RELOC(FE_VERTEX_STREAM_BASE_ADDR, &ctx->vertex_buffer.cvb[0].FE_VERTEX_STREAM_BASE_ADDR); /*00650*/ EMIT_STATE(FE_VERTEX_STREAM_CONTROL, ctx->vertex_buffer.cvb[0].FE_VERTEX_STREAM_CONTROL); } } if (unlikely(dirty & (ETNA_DIRTY_SHADER | ETNA_DIRTY_RASTERIZER))) { /*00804*/ EMIT_STATE(VS_OUTPUT_COUNT, vs_output_count); } if (unlikely(dirty & (ETNA_DIRTY_VERTEX_ELEMENTS | ETNA_DIRTY_SHADER))) { /*00808*/ EMIT_STATE(VS_INPUT_COUNT, ctx->shader_state.VS_INPUT_COUNT); /*0080C*/ EMIT_STATE(VS_TEMP_REGISTER_CONTROL, ctx->shader_state.VS_TEMP_REGISTER_CONTROL); } if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { /*00830*/ EMIT_STATE(VS_LOAD_BALANCING, ctx->shader_state.VS_LOAD_BALANCING); } if (unlikely(dirty & (ETNA_DIRTY_VIEWPORT))) { /*00A00*/ EMIT_STATE_FIXP(PA_VIEWPORT_SCALE_X, ctx->viewport.PA_VIEWPORT_SCALE_X); /*00A04*/ EMIT_STATE_FIXP(PA_VIEWPORT_SCALE_Y, ctx->viewport.PA_VIEWPORT_SCALE_Y); /*00A08*/ EMIT_STATE(PA_VIEWPORT_SCALE_Z, ctx->viewport.PA_VIEWPORT_SCALE_Z); /*00A0C*/ EMIT_STATE_FIXP(PA_VIEWPORT_OFFSET_X, ctx->viewport.PA_VIEWPORT_OFFSET_X); /*00A10*/ EMIT_STATE_FIXP(PA_VIEWPORT_OFFSET_Y, ctx->viewport.PA_VIEWPORT_OFFSET_Y); /*00A14*/ EMIT_STATE(PA_VIEWPORT_OFFSET_Z, ctx->viewport.PA_VIEWPORT_OFFSET_Z); } if (unlikely(dirty & (ETNA_DIRTY_RASTERIZER))) { struct etna_rasterizer_state *rasterizer = etna_rasterizer_state(ctx->rasterizer); /*00A18*/ EMIT_STATE(PA_LINE_WIDTH, rasterizer->PA_LINE_WIDTH); /*00A1C*/ EMIT_STATE(PA_POINT_SIZE, rasterizer->PA_POINT_SIZE); /*00A28*/ EMIT_STATE(PA_SYSTEM_MODE, rasterizer->PA_SYSTEM_MODE); } if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { /*00A30*/ EMIT_STATE(PA_ATTRIBUTE_ELEMENT_COUNT, ctx->shader_state.PA_ATTRIBUTE_ELEMENT_COUNT); } if (unlikely(dirty & (ETNA_DIRTY_RASTERIZER | ETNA_DIRTY_SHADER))) { uint32_t val = etna_rasterizer_state(ctx->rasterizer)->PA_CONFIG; /*00A34*/ EMIT_STATE(PA_CONFIG, val & ctx->shader_state.PA_CONFIG); } if (unlikely(dirty & (ETNA_DIRTY_RASTERIZER))) { struct etna_rasterizer_state *rasterizer = etna_rasterizer_state(ctx->rasterizer); /*00A38*/ EMIT_STATE(PA_WIDE_LINE_WIDTH0, rasterizer->PA_LINE_WIDTH); /*00A3C*/ EMIT_STATE(PA_WIDE_LINE_WIDTH1, rasterizer->PA_LINE_WIDTH); } if (unlikely(dirty & (ETNA_DIRTY_SCISSOR | ETNA_DIRTY_FRAMEBUFFER | ETNA_DIRTY_RASTERIZER | ETNA_DIRTY_VIEWPORT))) { /* this is a bit of a mess: rasterizer.scissor determines whether to use * only the framebuffer scissor, or specific scissor state, and the * viewport clips too so the logic spans four CSOs */ struct etna_rasterizer_state *rasterizer = etna_rasterizer_state(ctx->rasterizer); uint32_t scissor_left = MAX2(ctx->framebuffer.SE_SCISSOR_LEFT, ctx->viewport.SE_SCISSOR_LEFT); uint32_t scissor_top = MAX2(ctx->framebuffer.SE_SCISSOR_TOP, ctx->viewport.SE_SCISSOR_TOP); uint32_t scissor_right = MIN2(ctx->framebuffer.SE_SCISSOR_RIGHT, ctx->viewport.SE_SCISSOR_RIGHT); uint32_t scissor_bottom = MIN2(ctx->framebuffer.SE_SCISSOR_BOTTOM, ctx->viewport.SE_SCISSOR_BOTTOM); if (rasterizer->scissor) { scissor_left = MAX2(ctx->scissor.SE_SCISSOR_LEFT, scissor_left); scissor_top = MAX2(ctx->scissor.SE_SCISSOR_TOP, scissor_top); scissor_right = MIN2(ctx->scissor.SE_SCISSOR_RIGHT, scissor_right); scissor_bottom = MIN2(ctx->scissor.SE_SCISSOR_BOTTOM, scissor_bottom); } /*00C00*/ EMIT_STATE_FIXP(SE_SCISSOR_LEFT, scissor_left); /*00C04*/ EMIT_STATE_FIXP(SE_SCISSOR_TOP, scissor_top); /*00C08*/ EMIT_STATE_FIXP(SE_SCISSOR_RIGHT, scissor_right); /*00C0C*/ EMIT_STATE_FIXP(SE_SCISSOR_BOTTOM, scissor_bottom); } if (unlikely(dirty & (ETNA_DIRTY_RASTERIZER))) { struct etna_rasterizer_state *rasterizer = etna_rasterizer_state(ctx->rasterizer); /*00C10*/ EMIT_STATE(SE_DEPTH_SCALE, rasterizer->SE_DEPTH_SCALE); /*00C14*/ EMIT_STATE(SE_DEPTH_BIAS, rasterizer->SE_DEPTH_BIAS); /*00C18*/ EMIT_STATE(SE_CONFIG, rasterizer->SE_CONFIG); } if (unlikely(dirty & (ETNA_DIRTY_SCISSOR | ETNA_DIRTY_FRAMEBUFFER | ETNA_DIRTY_RASTERIZER | ETNA_DIRTY_VIEWPORT))) { struct etna_rasterizer_state *rasterizer = etna_rasterizer_state(ctx->rasterizer); uint32_t clip_right = MIN2(ctx->framebuffer.SE_CLIP_RIGHT, ctx->viewport.SE_CLIP_RIGHT); uint32_t clip_bottom = MIN2(ctx->framebuffer.SE_CLIP_BOTTOM, ctx->viewport.SE_CLIP_BOTTOM); if (rasterizer->scissor) { clip_right = MIN2(ctx->scissor.SE_CLIP_RIGHT, clip_right); clip_bottom = MIN2(ctx->scissor.SE_CLIP_BOTTOM, clip_bottom); } /*00C20*/ EMIT_STATE_FIXP(SE_CLIP_RIGHT, clip_right); /*00C24*/ EMIT_STATE_FIXP(SE_CLIP_BOTTOM, clip_bottom); } if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { /*00E00*/ EMIT_STATE(RA_CONTROL, ctx->shader_state.RA_CONTROL); } if (unlikely(dirty & (ETNA_DIRTY_SHADER | ETNA_DIRTY_FRAMEBUFFER))) { /*01004*/ EMIT_STATE(PS_OUTPUT_REG, ctx->shader_state.PS_OUTPUT_REG); /*01008*/ EMIT_STATE(PS_INPUT_COUNT, ctx->framebuffer.msaa_mode ? ctx->shader_state.PS_INPUT_COUNT_MSAA : ctx->shader_state.PS_INPUT_COUNT); /*0100C*/ EMIT_STATE(PS_TEMP_REGISTER_CONTROL, ctx->framebuffer.msaa_mode ? ctx->shader_state.PS_TEMP_REGISTER_CONTROL_MSAA : ctx->shader_state.PS_TEMP_REGISTER_CONTROL); /*01010*/ EMIT_STATE(PS_CONTROL, ctx->shader_state.PS_CONTROL); } if (unlikely(dirty & (ETNA_DIRTY_ZSA | ETNA_DIRTY_FRAMEBUFFER))) { uint32_t val = etna_zsa_state(ctx->zsa)->PE_DEPTH_CONFIG; /*01400*/ EMIT_STATE(PE_DEPTH_CONFIG, val | ctx->framebuffer.PE_DEPTH_CONFIG); } if (unlikely(dirty & (ETNA_DIRTY_VIEWPORT))) { /*01404*/ EMIT_STATE(PE_DEPTH_NEAR, ctx->viewport.PE_DEPTH_NEAR); /*01408*/ EMIT_STATE(PE_DEPTH_FAR, ctx->viewport.PE_DEPTH_FAR); } if (unlikely(dirty & (ETNA_DIRTY_FRAMEBUFFER))) { /*0140C*/ EMIT_STATE(PE_DEPTH_NORMALIZE, ctx->framebuffer.PE_DEPTH_NORMALIZE); if (ctx->specs.pixel_pipes == 1) { /*01410*/ EMIT_STATE_RELOC(PE_DEPTH_ADDR, &ctx->framebuffer.PE_DEPTH_ADDR); } /*01414*/ EMIT_STATE(PE_DEPTH_STRIDE, ctx->framebuffer.PE_DEPTH_STRIDE); } if (unlikely(dirty & (ETNA_DIRTY_ZSA))) { uint32_t val = etna_zsa_state(ctx->zsa)->PE_STENCIL_OP; /*01418*/ EMIT_STATE(PE_STENCIL_OP, val); } if (unlikely(dirty & (ETNA_DIRTY_ZSA | ETNA_DIRTY_STENCIL_REF))) { uint32_t val = etna_zsa_state(ctx->zsa)->PE_STENCIL_CONFIG; /*0141C*/ EMIT_STATE(PE_STENCIL_CONFIG, val | ctx->stencil_ref.PE_STENCIL_CONFIG); } if (unlikely(dirty & (ETNA_DIRTY_ZSA))) { uint32_t val = etna_zsa_state(ctx->zsa)->PE_ALPHA_OP; /*01420*/ EMIT_STATE(PE_ALPHA_OP, val); } if (unlikely(dirty & (ETNA_DIRTY_BLEND_COLOR))) { /*01424*/ EMIT_STATE(PE_ALPHA_BLEND_COLOR, ctx->blend_color.PE_ALPHA_BLEND_COLOR); } if (unlikely(dirty & (ETNA_DIRTY_BLEND))) { uint32_t val = etna_blend_state(ctx->blend)->PE_ALPHA_CONFIG; /*01428*/ EMIT_STATE(PE_ALPHA_CONFIG, val); } if (unlikely(dirty & (ETNA_DIRTY_BLEND | ETNA_DIRTY_FRAMEBUFFER))) { uint32_t val; /* Use the components and overwrite bits in framebuffer.PE_COLOR_FORMAT * as a mask to enable the bits from blend PE_COLOR_FORMAT */ val = ~(VIVS_PE_COLOR_FORMAT_COMPONENTS__MASK | VIVS_PE_COLOR_FORMAT_OVERWRITE); val |= etna_blend_state(ctx->blend)->PE_COLOR_FORMAT; val &= ctx->framebuffer.PE_COLOR_FORMAT; /*0142C*/ EMIT_STATE(PE_COLOR_FORMAT, val); } if (unlikely(dirty & (ETNA_DIRTY_FRAMEBUFFER))) { if (ctx->specs.pixel_pipes == 1) { /*01430*/ EMIT_STATE_RELOC(PE_COLOR_ADDR, &ctx->framebuffer.PE_COLOR_ADDR); /*01434*/ EMIT_STATE(PE_COLOR_STRIDE, ctx->framebuffer.PE_COLOR_STRIDE); /*01454*/ EMIT_STATE(PE_HDEPTH_CONTROL, ctx->framebuffer.PE_HDEPTH_CONTROL); } else if (ctx->specs.pixel_pipes == 2) { /*01434*/ EMIT_STATE(PE_COLOR_STRIDE, ctx->framebuffer.PE_COLOR_STRIDE); /*01454*/ EMIT_STATE(PE_HDEPTH_CONTROL, ctx->framebuffer.PE_HDEPTH_CONTROL); /*01460*/ EMIT_STATE_RELOC(PE_PIPE_COLOR_ADDR(0), &ctx->framebuffer.PE_PIPE_COLOR_ADDR[0]); /*01464*/ EMIT_STATE_RELOC(PE_PIPE_COLOR_ADDR(1), &ctx->framebuffer.PE_PIPE_COLOR_ADDR[1]); /*01480*/ EMIT_STATE_RELOC(PE_PIPE_DEPTH_ADDR(0), &ctx->framebuffer.PE_PIPE_DEPTH_ADDR[0]); /*01484*/ EMIT_STATE_RELOC(PE_PIPE_DEPTH_ADDR(1), &ctx->framebuffer.PE_PIPE_DEPTH_ADDR[1]); } else { abort(); } } if (unlikely(dirty & (ETNA_DIRTY_STENCIL_REF))) { /*014A0*/ EMIT_STATE(PE_STENCIL_CONFIG_EXT, ctx->stencil_ref.PE_STENCIL_CONFIG_EXT); } if (unlikely(dirty & (ETNA_DIRTY_BLEND | ETNA_DIRTY_FRAMEBUFFER))) { struct etna_blend_state *blend = etna_blend_state(ctx->blend); /*014A4*/ EMIT_STATE(PE_LOGIC_OP, blend->PE_LOGIC_OP | ctx->framebuffer.PE_LOGIC_OP); } if (unlikely(dirty & (ETNA_DIRTY_BLEND))) { struct etna_blend_state *blend = etna_blend_state(ctx->blend); for (int x = 0; x < 2; ++x) { /*014A8*/ EMIT_STATE(PE_DITHER(x), blend->PE_DITHER[x]); } } if (unlikely(dirty & (ETNA_DIRTY_FRAMEBUFFER | ETNA_DIRTY_TS))) { /*01654*/ EMIT_STATE(TS_MEM_CONFIG, ctx->framebuffer.TS_MEM_CONFIG); /*01658*/ EMIT_STATE_RELOC(TS_COLOR_STATUS_BASE, &ctx->framebuffer.TS_COLOR_STATUS_BASE); /*0165C*/ EMIT_STATE_RELOC(TS_COLOR_SURFACE_BASE, &ctx->framebuffer.TS_COLOR_SURFACE_BASE); /*01660*/ EMIT_STATE(TS_COLOR_CLEAR_VALUE, ctx->framebuffer.TS_COLOR_CLEAR_VALUE); /*01664*/ EMIT_STATE_RELOC(TS_DEPTH_STATUS_BASE, &ctx->framebuffer.TS_DEPTH_STATUS_BASE); /*01668*/ EMIT_STATE_RELOC(TS_DEPTH_SURFACE_BASE, &ctx->framebuffer.TS_DEPTH_SURFACE_BASE); /*0166C*/ EMIT_STATE(TS_DEPTH_CLEAR_VALUE, ctx->framebuffer.TS_DEPTH_CLEAR_VALUE); } if (unlikely(dirty & (ETNA_DIRTY_SHADER))) { /*0381C*/ EMIT_STATE(GL_VARYING_TOTAL_COMPONENTS, ctx->shader_state.GL_VARYING_TOTAL_COMPONENTS); } etna_coalesce_end(stream, &coalesce); /* end only EMIT_STATE */ /* Emit strongly architecture-specific state */ if (ctx->specs.halti >= 5) emit_halti5_only_state(ctx, vs_output_count); else emit_pre_halti5_state(ctx); ctx->emit_texture_state(ctx); /* Insert a FE/PE stall as changing the shader instructions (and maybe * the uniforms) can corrupt the previous in-progress draw operation. * Observed with amoeba on GC2000 during the right-to-left rendering * of PI, and can cause GPU hangs immediately after. * I summise that this is because the "new" locations at 0xc000 are not * properly protected against updates as other states seem to be. Hence, * we detect the "new" vertex shader instruction offset to apply this. */ if (ctx->dirty & (ETNA_DIRTY_SHADER | ETNA_DIRTY_CONSTBUF) && ctx->specs.vs_offset > 0x4000) etna_stall(ctx->stream, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE); /* We need to update the uniform cache only if one of the following bits are * set in ctx->dirty: * - ETNA_DIRTY_SHADER * - ETNA_DIRTY_CONSTBUF * - uniforms_dirty_bits * * In case of ETNA_DIRTY_SHADER we need load all uniforms from the cache. In * all * other cases we can load on the changed uniforms. */ static const uint32_t uniform_dirty_bits = ETNA_DIRTY_SHADER | ETNA_DIRTY_CONSTBUF; if (dirty & (uniform_dirty_bits | ctx->shader.vs->uniforms_dirty_bits)) etna_uniforms_write( ctx, ctx->shader.vs, &ctx->constant_buffer[PIPE_SHADER_VERTEX], ctx->shader_state.VS_UNIFORMS, &ctx->shader_state.vs_uniforms_size); if (dirty & (uniform_dirty_bits | ctx->shader.fs->uniforms_dirty_bits)) etna_uniforms_write( ctx, ctx->shader.fs, &ctx->constant_buffer[PIPE_SHADER_FRAGMENT], ctx->shader_state.PS_UNIFORMS, &ctx->shader_state.ps_uniforms_size); /**** Large dynamically-sized state ****/ bool do_uniform_flush = ctx->specs.halti < 5; if (dirty & (ETNA_DIRTY_SHADER)) { /* Special case: a new shader was loaded; simply re-load all uniforms and * shader code at once */ /* This sequence is special, do not change ordering unless necessary. According to comment snippets in the Vivante kernel driver a process called "steering" goes on while programming shader state. This (as I understand it) means certain unified states are "steered" toward a specific shader unit (VS/PS/...) based on either explicit flags in register 00860, or what other state is written before "auto-steering". So this means some state can legitimately be programmed multiple times. */ if (ctx->specs.halti >= 5) { /* ICACHE (HALTI5) */ assert(ctx->shader_state.VS_INST_ADDR.bo && ctx->shader_state.PS_INST_ADDR.bo); /* Set icache (VS) */ etna_set_state(stream, VIVS_VS_NEWRANGE_LOW, 0); etna_set_state(stream, VIVS_VS_NEWRANGE_HIGH, ctx->shader_state.vs_inst_mem_size / 4); assert(ctx->shader_state.VS_INST_ADDR.bo); etna_set_state_reloc(stream, VIVS_VS_INST_ADDR, &ctx->shader_state.VS_INST_ADDR); etna_set_state(stream, VIVS_SH_CONFIG, 0x00000002); etna_set_state(stream, VIVS_VS_ICACHE_CONTROL, VIVS_VS_ICACHE_CONTROL_ENABLE); etna_set_state(stream, VIVS_VS_ICACHE_COUNT, ctx->shader_state.vs_inst_mem_size / 4 - 1); /* Set icache (PS) */ etna_set_state(stream, VIVS_PS_NEWRANGE_LOW, 0); etna_set_state(stream, VIVS_PS_NEWRANGE_HIGH, ctx->shader_state.ps_inst_mem_size / 4); assert(ctx->shader_state.PS_INST_ADDR.bo); etna_set_state_reloc(stream, VIVS_PS_INST_ADDR, &ctx->shader_state.PS_INST_ADDR); etna_set_state(stream, VIVS_SH_CONFIG, 0x00000002); etna_set_state(stream, VIVS_VS_ICACHE_CONTROL, VIVS_VS_ICACHE_CONTROL_ENABLE); etna_set_state(stream, VIVS_PS_ICACHE_COUNT, ctx->shader_state.ps_inst_mem_size / 4 - 1); } else if (ctx->shader_state.VS_INST_ADDR.bo || ctx->shader_state.PS_INST_ADDR.bo) { /* ICACHE (pre-HALTI5) */ assert(ctx->specs.has_icache && ctx->specs.has_shader_range_registers); /* Set icache (VS) */ etna_set_state(stream, VIVS_VS_RANGE, (ctx->shader_state.vs_inst_mem_size / 4 - 1) << 16); etna_set_state(stream, VIVS_VS_ICACHE_CONTROL, VIVS_VS_ICACHE_CONTROL_ENABLE | VIVS_VS_ICACHE_CONTROL_FLUSH_VS); assert(ctx->shader_state.VS_INST_ADDR.bo); etna_set_state_reloc(stream, VIVS_VS_INST_ADDR, &ctx->shader_state.VS_INST_ADDR); /* Set icache (PS) */ etna_set_state(stream, VIVS_PS_RANGE, (ctx->shader_state.ps_inst_mem_size / 4 - 1) << 16); etna_set_state(stream, VIVS_VS_ICACHE_CONTROL, VIVS_VS_ICACHE_CONTROL_ENABLE | VIVS_VS_ICACHE_CONTROL_FLUSH_PS); assert(ctx->shader_state.PS_INST_ADDR.bo); etna_set_state_reloc(stream, VIVS_PS_INST_ADDR, &ctx->shader_state.PS_INST_ADDR); } else { /* Upload shader directly, first flushing and disabling icache if * supported on this hw */ if (ctx->specs.has_icache) { etna_set_state(stream, VIVS_VS_ICACHE_CONTROL, VIVS_VS_ICACHE_CONTROL_FLUSH_PS | VIVS_VS_ICACHE_CONTROL_FLUSH_VS); } if (ctx->specs.has_shader_range_registers) { etna_set_state(stream, VIVS_VS_RANGE, (ctx->shader_state.vs_inst_mem_size / 4 - 1) << 16); etna_set_state(stream, VIVS_PS_RANGE, ((ctx->shader_state.ps_inst_mem_size / 4 - 1 + 0x100) << 16) | 0x100); } etna_set_state_multi(stream, ctx->specs.vs_offset, ctx->shader_state.vs_inst_mem_size, ctx->shader_state.VS_INST_MEM); etna_set_state_multi(stream, ctx->specs.ps_offset, ctx->shader_state.ps_inst_mem_size, ctx->shader_state.PS_INST_MEM); } if (ctx->specs.has_unified_uniforms) { etna_set_state(stream, VIVS_VS_UNIFORM_BASE, 0); etna_set_state(stream, VIVS_PS_UNIFORM_BASE, ctx->specs.max_vs_uniforms); } if (do_uniform_flush) etna_set_state(stream, VIVS_VS_UNIFORM_CACHE, VIVS_VS_UNIFORM_CACHE_FLUSH); etna_set_state_multi(stream, ctx->specs.vs_uniforms_offset, ctx->shader_state.vs_uniforms_size, ctx->shader_state.VS_UNIFORMS); if (do_uniform_flush) etna_set_state(stream, VIVS_VS_UNIFORM_CACHE, VIVS_VS_UNIFORM_CACHE_FLUSH | VIVS_VS_UNIFORM_CACHE_PS); etna_set_state_multi(stream, ctx->specs.ps_uniforms_offset, ctx->shader_state.ps_uniforms_size, ctx->shader_state.PS_UNIFORMS); /* Copy uniforms to gpu3d, so that incremental updates to uniforms are * possible as long as the * same shader remains bound */ memcpy(ctx->gpu3d.VS_UNIFORMS, ctx->shader_state.VS_UNIFORMS, ctx->shader_state.vs_uniforms_size * 4); memcpy(ctx->gpu3d.PS_UNIFORMS, ctx->shader_state.PS_UNIFORMS, ctx->shader_state.ps_uniforms_size * 4); if (ctx->specs.halti >= 5) { /* HALTI5 needs to be prompted to pre-fetch shaders */ etna_set_state(stream, VIVS_VS_ICACHE_PREFETCH, 0x00000000); etna_set_state(stream, VIVS_PS_ICACHE_PREFETCH, 0x00000000); etna_stall(stream, SYNC_RECIPIENT_RA, SYNC_RECIPIENT_PE); } } else { /* ideally this cache would only be flushed if there are VS uniform changes */ if (do_uniform_flush) etna_set_state(stream, VIVS_VS_UNIFORM_CACHE, VIVS_VS_UNIFORM_CACHE_FLUSH); etna_coalesce_start(stream, &coalesce); for (int x = 0; x < ctx->shader.vs->uniforms.const_count; ++x) { if (ctx->gpu3d.VS_UNIFORMS[x] != ctx->shader_state.VS_UNIFORMS[x]) { etna_coalsence_emit(stream, &coalesce, ctx->specs.vs_uniforms_offset + x*4, ctx->shader_state.VS_UNIFORMS[x]); ctx->gpu3d.VS_UNIFORMS[x] = ctx->shader_state.VS_UNIFORMS[x]; } } etna_coalesce_end(stream, &coalesce); /* ideally this cache would only be flushed if there are PS uniform changes */ if (do_uniform_flush) etna_set_state(stream, VIVS_VS_UNIFORM_CACHE, VIVS_VS_UNIFORM_CACHE_FLUSH | VIVS_VS_UNIFORM_CACHE_PS); etna_coalesce_start(stream, &coalesce); for (int x = 0; x < ctx->shader.fs->uniforms.const_count; ++x) { if (ctx->gpu3d.PS_UNIFORMS[x] != ctx->shader_state.PS_UNIFORMS[x]) { etna_coalsence_emit(stream, &coalesce, ctx->specs.ps_uniforms_offset + x*4, ctx->shader_state.PS_UNIFORMS[x]); ctx->gpu3d.PS_UNIFORMS[x] = ctx->shader_state.PS_UNIFORMS[x]; } } etna_coalesce_end(stream, &coalesce); } /**** End of state update ****/ #undef EMIT_STATE #undef EMIT_STATE_FIXP #undef EMIT_STATE_RELOC ctx->dirty = 0; ctx->dirty_sampler_views = 0; }
950102.c
/* TEMPLATE GENERATED TESTCASE FILE Filename: CWE122_Heap_Based_Buffer_Overflow__c_dest_char_cat_61b.c Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_dest.label.xml Template File: sources-sink-61b.tmpl.c */ /* * @description * CWE: 122 Heap Based Buffer Overflow * BadSource: Allocate using malloc() and set data pointer to a small buffer * GoodSource: Allocate using malloc() and set data pointer to a large buffer * Sinks: cat * BadSink : Copy string to data using strcat * Flow Variant: 61 Data flow: data returned from one function to another in different source files * * */ #include "std_testcase.h" #include <wchar.h> #ifndef OMITBAD char * CWE122_Heap_Based_Buffer_Overflow__c_dest_char_cat_61b_badSource(char * data) { /* FLAW: Allocate and point data to a small buffer that is smaller than the large buffer used in the sinks */ data = (char *)malloc(50*sizeof(char)); if (data == NULL) {exit(-1);} data[0] = '\0'; /* null terminate */ return data; } #endif /* OMITBAD */ #ifndef OMITGOOD /* goodG2B() uses the GoodSource with the BadSink */ char * CWE122_Heap_Based_Buffer_Overflow__c_dest_char_cat_61b_goodG2BSource(char * data) { /* FIX: Allocate and point data to a large buffer that is at least as large as the large buffer used in the sink */ data = (char *)malloc(100*sizeof(char)); if (data == NULL) {exit(-1);} data[0] = '\0'; /* null terminate */ return data; } #endif /* OMITGOOD */
977644.c
/* TEMPLATE GENERATED TESTCASE FILE Filename: CWE197_Numeric_Truncation_Error__int_fscanf_to_char_61a.c Label Definition File: CWE197_Numeric_Truncation_Error__int.label.xml Template File: sources-sink-61a.tmpl.c */ /* * @description * CWE: 197 Numeric Truncation Error * BadSource: fscanf Read data from the console using fscanf() * GoodSource: Less than CHAR_MAX * Sinks: to_char * BadSink : Convert data to a char * Flow Variant: 61 Data flow: data returned from one function to another in different source files * * */ #include "std_testcase.h" #ifndef OMITBAD /* bad function declaration */ int CWE197_Numeric_Truncation_Error__int_fscanf_to_char_61b_badSource(int data); void CWE197_Numeric_Truncation_Error__int_fscanf_to_char_61_bad() { int data; /* Initialize data */ data = -1; data = CWE197_Numeric_Truncation_Error__int_fscanf_to_char_61b_badSource(data); { /* POTENTIAL FLAW: Convert data to a char, possibly causing a truncation error */ char charData = (char)data; printHexCharLine(charData); } } #endif /* OMITBAD */ #ifndef OMITGOOD /* goodG2B uses the GoodSource with the BadSink */ int CWE197_Numeric_Truncation_Error__int_fscanf_to_char_61b_goodG2BSource(int data); static void goodG2B() { int data; /* Initialize data */ data = -1; data = CWE197_Numeric_Truncation_Error__int_fscanf_to_char_61b_goodG2BSource(data); { /* POTENTIAL FLAW: Convert data to a char, possibly causing a truncation error */ char charData = (char)data; printHexCharLine(charData); } } void CWE197_Numeric_Truncation_Error__int_fscanf_to_char_61_good() { goodG2B(); } #endif /* OMITGOOD */ /* Below is the main(). It is only used when building this testcase on * its own for testing or for building a binary to use in testing binary * analysis tools. It is not used when compiling all the testcases as one * application, which is how source code analysis tools are tested. */ #ifdef INCLUDEMAIN int main(int argc, char * argv[]) { /* seed randomness */ srand( (unsigned)time(NULL) ); #ifndef OMITGOOD printLine("Calling good()..."); CWE197_Numeric_Truncation_Error__int_fscanf_to_char_61_good(); printLine("Finished good()"); #endif /* OMITGOOD */ #ifndef OMITBAD printLine("Calling bad()..."); CWE197_Numeric_Truncation_Error__int_fscanf_to_char_61_bad(); printLine("Finished bad()"); #endif /* OMITBAD */ return 0; } #endif
125861.c
#include "test_subject.h" #include "test_iface.h" /* Private structure definition. */ typedef struct { gchar *string; int int32; TestRegularEnum _enum; TestIface* iface; char** str_list; } TestSubjectPrivate; static void test_subject_iface_interface_init(TestIfaceInterface *iface) { iface->return_myself_as_interface = test_subject_return_myself_as_interface; } G_DEFINE_TYPE_WITH_CODE(TestSubject, test_subject, G_TYPE_OBJECT, G_ADD_PRIVATE(TestSubject) G_IMPLEMENT_INTERFACE(TEST_TYPE_IFACE, test_subject_iface_interface_init)) typedef enum { PROP_STRING = 1, PROP_INT32, PROP_IFACE, PROP_ENUM, PROP_STR_LIST, N_PROPERTIES } TestSubjectProperty; static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, }; static void test_subject_dispose(GObject *gobject) { // TestSubjectPrivate *priv = test_subject_get_instance_private(TEST_SUBJECT(gobject)); G_OBJECT_CLASS(test_subject_parent_class)->dispose(gobject); } static void test_subject_finalize(GObject *gobject) { TestSubjectPrivate *priv = test_subject_get_instance_private(TEST_SUBJECT(gobject)); g_free(priv->string); g_strfreev(priv->str_list); G_OBJECT_CLASS(test_subject_parent_class)->finalize(gobject); } static void test_subject_set_property(GObject *gobject, guint property_id, const GValue *value, GParamSpec *pspec) { TestSubject* self = TEST_SUBJECT(gobject); TestSubjectPrivate *priv = test_subject_get_instance_private(self); switch ((TestSubjectProperty) property_id) { case PROP_STRING: g_free(priv->string); priv->string = g_value_dup_string(value); break; case PROP_INT32: priv->int32 = g_value_get_int(value); break; case PROP_IFACE: if (priv->iface) g_object_unref(G_OBJECT(priv->iface)); GObject* gobj = g_value_get_object(value); g_object_ref(gobj); priv->iface = TEST_IFACE(gobj); break; case PROP_ENUM: priv->_enum = g_value_get_enum(value); break; case PROP_STR_LIST: test_subject_set_str_list(self, (const char**) g_value_get_boxed(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec); break; } } static void test_subject_get_property(GObject *gobject, guint property_id, GValue *value, GParamSpec *pspec) { TestSubjectPrivate *priv = test_subject_get_instance_private(TEST_SUBJECT(gobject)); switch ((TestSubjectProperty) property_id) { case PROP_STRING: g_value_set_string(value, priv->string); break; case PROP_INT32: g_value_set_int(value, priv->int32); break; case PROP_IFACE: g_value_set_object(value, G_OBJECT(priv->iface)); break; case PROP_ENUM: g_value_set_enum(value, priv->_enum); break; case PROP_STR_LIST: g_value_set_boxed(value, priv->str_list); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec); break; } } static void test_subject_class_init(TestSubjectClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); object_class->set_property = test_subject_set_property; object_class->get_property = test_subject_get_property; object_class->dispose = test_subject_dispose; object_class->finalize = test_subject_finalize; obj_properties[PROP_STRING] = g_param_spec_string("string", "String", "A string property.", "", G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT | G_PARAM_READWRITE); obj_properties[PROP_INT32] = g_param_spec_int("int32", "Int32", "A int32 property.", INT_MIN, INT_MAX, 0, G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT | G_PARAM_READWRITE); obj_properties[PROP_IFACE] = g_param_spec_object("iface", "IFace", "An IFace object.", TEST_TYPE_IFACE, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE); obj_properties[PROP_ENUM] = g_param_spec_enum("enum", "Enum", "An enum.", TEST_TYPE_REGULAR_ENUM, TEST_VALUE1, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE); obj_properties[PROP_STR_LIST] = g_param_spec_boxed("str_list", "StrList", "A null terminated list of strings", G_TYPE_STRV, G_PARAM_READWRITE); g_object_class_install_properties(object_class, N_PROPERTIES, obj_properties); } static void test_subject_init(TestSubject *self) { // TestSubjectPrivate *priv = test_subject_instance_private(self); /* initialize all public and private members to reasonable default values. * They are all automatically initialized to 0 to begin with. */ } TestSubject *test_subject_new(void) { return g_object_new(TEST_TYPE_SUBJECT, "string", "", "int32", 0, NULL); } TestSubject *test_subject_new_from_string(const gchar *string) { return g_object_new(TEST_TYPE_SUBJECT, "string", string, "int32", 0, NULL); } void test_subject_set_str_list(TestSubject* self, const char** list) { TestSubjectPrivate *priv = test_subject_get_instance_private(self); g_strfreev(priv->str_list); priv->str_list = g_strdupv((char **)list); } void test_subject_transfer_full_param(GObject* subject) { } gchar* test_subject_concat_strings(TestSubject *self, int n, const gchar **strings) { if (n == 0 || strings == NULL) return g_strdup(""); int size = 0; for (int i = 0; i < n; ++i) size += strlen(strings[i]); gchar* ret = g_malloc(size + 1); gchar* ptr = ret; for (int i = 0; i < n; ++i) { strcpy(ptr, strings[i]); ptr += strlen(strings[i]); } return ret; } gchar* test_subject_concat_filenames(TestSubject *self, int n, const gchar **filenames) { return test_subject_concat_strings(self, n, filenames); } int test_subject_sum(TestSubject *self, int n, int* numbers) { int sum = 0; for(int i = 0; i < n; ++i) sum += numbers[i]; return sum; } int test_subject_sum_nullable(TestSubject *self, int n, int* numbers) { return numbers == NULL ? 0 : test_subject_sum(self, n, numbers); } int test_subject_receive_nullable_object(TestSubject *self, TestSubject* nullable) { return nullable == NULL; } int test_subject_no_optional_param(int* int32, const gchar** str, TestRegularEnum* en, GObject** gobj) { return (int32 || str || en || gobj) ? -1 : 0; } int test_subject_receive_arguments_named_as_crystal_keywords(TestSubject *self_, int def, int alias, int module, int out, int begin, int self, int end, int abstract, int in) { return def + alias + module + out + begin + self + end + abstract + in; } const gchar* test_subject_get_getter_without_args(TestSubject *self) { return "some string"; } void test_subject_set_setter(TestSubject *self, const gchar* data) { g_object_set(G_OBJECT(self), "string", data, NULL); } TestFlagFlags test_subject_return_or_on_flags(TestSubject* self, TestFlagFlags flag1, TestFlagFlags flag2) { return flag1 | flag2; } void test_subject_put_42_on_out_argument(TestSubject *self, int *out) { *out = 42; } const gchar** test_subject_return_null_terminated_array_transfer_none(TestSubject* self) { static const gchar* ret[] = { "Hello", "World", NULL }; return ret; } gchar** test_subject_return_null_terminated_array_transfer_full(TestSubject* self) { gchar** ret = g_malloc_n(3, sizeof(gchar*)); ret[0] = g_strdup("Hello"); ret[1] = g_strdup("World"); ret[2] = NULL; return ret; } TestIface *test_subject_return_myself_as_interface(TestIface *self) { TestSubject* subject = TEST_SUBJECT(self); g_object_set(subject, "string", __FUNCTION__, NULL); return self; } GList* test_subject_return_list_of_strings_transfer_full(TestSubject* self) { GList* list = NULL; list = g_list_append(list, g_strdup("one")); list = g_list_append(list, g_strdup("two")); return list; } GList* test_subject_return_list_of_strings_transfer_container(TestSubject* self) { GList* list = NULL; list = g_list_append(list, "one"); list = g_list_append(list, "two"); return list; } GSList* test_subject_return_slist_of_strings_transfer_full(TestSubject* self) { GSList* list = NULL; list = g_slist_append(list, g_strdup("one")); list = g_slist_append(list, g_strdup("two")); return list; } GSList* test_subject_return_slist_of_strings_transfer_container(TestSubject* self) { GSList* list = NULL; list = g_slist_append(list, "one"); list = g_slist_append(list, "two"); return list; } void test_subject_get_out_param(TestSubject* self, TestStruct *out) { out->in = 1; out->begin = 2; } static gchar* g_value_to_string(gchar* buffer, GValue* value) { const gchar* type_name = g_type_name(value->g_type); int type_name_size = strlen(type_name); strncpy(buffer, type_name, type_name_size); buffer += type_name_size; *buffer = ':'; buffer++; switch (value->g_type) { case G_TYPE_INT: buffer += sprintf(buffer, "%d", g_value_get_int(value)); break; case G_TYPE_UINT: buffer += sprintf(buffer, "%u", g_value_get_uint(value)); break; case G_TYPE_INT64: buffer += sprintf(buffer, "%ld", g_value_get_int64(value)); break; case G_TYPE_UINT64: buffer += sprintf(buffer, "%lu", g_value_get_uint64(value)); break; case G_TYPE_FLOAT: buffer += sprintf(buffer, "%0.2f", g_value_get_float(value)); break; case G_TYPE_DOUBLE: buffer += sprintf(buffer, "%0.2f", g_value_get_double(value)); break; case G_TYPE_STRING: buffer += sprintf(buffer, "%s", g_value_get_string(value)); break; case G_TYPE_CHAR: *buffer++ = g_value_get_schar(value); break; case G_TYPE_UCHAR: buffer += sprintf(buffer, "%d", g_value_get_uchar(value)); break; case G_TYPE_ENUM: buffer += sprintf(buffer, "%d", g_value_get_enum(value)); break; default: *buffer++ = '?'; } *buffer++ = ';'; return buffer; } const gchar* test_subject_array_of_g_values(TestSubject* self, int n, GValue *values) { static gchar buffer[1024]; gchar* ptr = buffer; for (int i = 0; i < n; ++i) { ptr = g_value_to_string(ptr, &values[i]); } *ptr = 0; return buffer; } const gchar* test_subject_g_value_parameter(GValue* value) { static gchar buffer[128]; gchar* ptr = g_value_to_string(buffer, value); *ptr = 0; return buffer; } void test_subject_g_value_by_out_parameter(GValue* value) { g_value_init(value, G_TYPE_INT); g_value_set_int(value, 42); } gchar* test_subject_g_variant_parameter(GVariant* variant) { return g_variant_print(variant, TRUE); }
685728.c
/* +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ | Copyright (c) 1998-2016 Zend Technologies Ltd. (http://www.zend.com) | +----------------------------------------------------------------------+ | This source file is subject to version 2.00 of the Zend license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.zend.com/license/2_00.txt. | | If you did not receive a copy of the Zend license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Andi Gutmans <[email protected]> | | Zeev Suraski <[email protected]> | | Dmitry Stogov <[email protected]> | +----------------------------------------------------------------------+ */ /* $Id$ */ #include <stdio.h> #include <signal.h> #include "zend.h" #include "zend_compile.h" #include "zend_execute.h" #include "zend_API.h" #include "zend_stack.h" #include "zend_constants.h" #include "zend_extensions.h" #include "zend_exceptions.h" #include "zend_closures.h" #include "zend_generators.h" #include "zend_vm.h" #include "zend_float.h" #ifdef HAVE_SYS_TIME_H #include <sys/time.h> #endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif ZEND_API void (*zend_execute_ex)(zend_execute_data *execute_data); ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data, zval *return_value); /* true globals */ ZEND_API const zend_fcall_info empty_fcall_info = { 0, {{0}, {{0}}, {0}}, NULL, NULL, NULL, 0, 0 }; ZEND_API const zend_fcall_info_cache empty_fcall_info_cache = { 0, NULL, NULL, NULL, NULL }; #ifdef ZEND_WIN32 ZEND_TLS HANDLE tq_timer = NULL; #endif #if 0&&ZEND_DEBUG static void (*original_sigsegv_handler)(int); static void zend_handle_sigsegv(int dummy) /* {{{ */ { fflush(stdout); fflush(stderr); if (original_sigsegv_handler == zend_handle_sigsegv) { signal(SIGSEGV, original_sigsegv_handler); } else { signal(SIGSEGV, SIG_DFL); } { fprintf(stderr, "SIGSEGV caught on opcode %d on opline %d of %s() at %s:%d\n\n", active_opline->opcode, active_opline-EG(active_op_array)->opcodes, get_active_function_name(), zend_get_executed_filename(), zend_get_executed_lineno()); /* See http://support.microsoft.com/kb/190351 */ #ifdef ZEND_WIN32 fflush(stderr); #endif } if (original_sigsegv_handler!=zend_handle_sigsegv) { original_sigsegv_handler(dummy); } } /* }}} */ #endif static void zend_extension_activator(zend_extension *extension) /* {{{ */ { if (extension->activate) { extension->activate(); } } /* }}} */ static void zend_extension_deactivator(zend_extension *extension) /* {{{ */ { if (extension->deactivate) { extension->deactivate(); } } /* }}} */ static int clean_non_persistent_function(zval *zv) /* {{{ */ { zend_function *function = Z_PTR_P(zv); return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE; } /* }}} */ ZEND_API int clean_non_persistent_function_full(zval *zv) /* {{{ */ { zend_function *function = Z_PTR_P(zv); return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE; } /* }}} */ static int clean_non_persistent_class(zval *zv) /* {{{ */ { zend_class_entry *ce = Z_PTR_P(zv); return (ce->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE; } /* }}} */ ZEND_API int clean_non_persistent_class_full(zval *zv) /* {{{ */ { zend_class_entry *ce = Z_PTR_P(zv); return (ce->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE; } /* }}} */ void init_executor(void) /* {{{ */ { zend_init_fpu(); ZVAL_NULL(&EG(uninitialized_zval)); ZVAL_ERROR(&EG(error_zval)); /* destroys stack frame, therefore makes core dumps worthless */ #if 0&&ZEND_DEBUG original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv); #endif EG(symtable_cache_ptr) = EG(symtable_cache) - 1; EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE - 1; EG(no_extensions) = 0; EG(function_table) = CG(function_table); EG(class_table) = CG(class_table); EG(in_autoload) = NULL; EG(autoload_func) = NULL; EG(error_handling) = EH_NORMAL; zend_vm_stack_init(); zend_hash_init(&EG(symbol_table), 64, NULL, ZVAL_PTR_DTOR, 0); EG(valid_symbol_table) = 1; zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_activator); zend_hash_init(&EG(included_files), 8, NULL, NULL, 0); EG(ticks_count) = 0; ZVAL_UNDEF(&EG(user_error_handler)); EG(current_execute_data) = NULL; zend_stack_init(&EG(user_error_handlers_error_reporting), sizeof(int)); zend_stack_init(&EG(user_error_handlers), sizeof(zval)); zend_stack_init(&EG(user_exception_handlers), sizeof(zval)); zend_objects_store_init(&EG(objects_store), 1024); EG(full_tables_cleanup) = 0; EG(vm_interrupt) = 0; EG(timed_out) = 0; EG(exception) = NULL; EG(prev_exception) = NULL; EG(fake_scope) = NULL; EG(ht_iterators_count) = sizeof(EG(ht_iterators_slots)) / sizeof(HashTableIterator); EG(ht_iterators_used) = 0; EG(ht_iterators) = EG(ht_iterators_slots); memset(EG(ht_iterators), 0, sizeof(EG(ht_iterators_slots))); EG(active) = 1; } /* }}} */ static int zval_call_destructor(zval *zv) /* {{{ */ { if (Z_TYPE_P(zv) == IS_INDIRECT) { zv = Z_INDIRECT_P(zv); } if (Z_TYPE_P(zv) == IS_OBJECT && Z_REFCOUNT_P(zv) == 1) { return ZEND_HASH_APPLY_REMOVE; } else { return ZEND_HASH_APPLY_KEEP; } } /* }}} */ static void zend_unclean_zval_ptr_dtor(zval *zv) /* {{{ */ { if (Z_TYPE_P(zv) == IS_INDIRECT) { zv = Z_INDIRECT_P(zv); } i_zval_ptr_dtor(zv ZEND_FILE_LINE_CC); } /* }}} */ static void zend_throw_or_error(int fetch_type, zend_class_entry *exception_ce, const char *format, ...) /* {{{ */ { va_list va; char *message = NULL; va_start(va, format); zend_vspprintf(&message, 0, format, va); if (fetch_type & ZEND_FETCH_CLASS_EXCEPTION) { zend_throw_error(exception_ce, "%s", message); } else { zend_error(E_ERROR, "%s", message); } efree(message); va_end(va); } /* }}} */ void shutdown_destructors(void) /* {{{ */ { if (CG(unclean_shutdown)) { EG(symbol_table).pDestructor = zend_unclean_zval_ptr_dtor; } zend_try { uint32_t symbols; do { symbols = zend_hash_num_elements(&EG(symbol_table)); zend_hash_reverse_apply(&EG(symbol_table), (apply_func_t) zval_call_destructor); } while (symbols != zend_hash_num_elements(&EG(symbol_table))); zend_objects_store_call_destructors(&EG(objects_store)); } zend_catch { /* if we couldn't destruct cleanly, mark all objects as destructed anyway */ zend_objects_store_mark_destructed(&EG(objects_store)); } zend_end_try(); } /* }}} */ void shutdown_executor(void) /* {{{ */ { zend_function *func; zend_class_entry *ce; zend_try { /* Removed because this can not be safely done, e.g. in this situation: Object 1 creates object 2 Object 3 holds reference to object 2. Now when 1 and 2 are destroyed, 3 can still access 2 in its destructor, with very problematic results */ /* zend_objects_store_call_destructors(&EG(objects_store)); */ /* Moved after symbol table cleaners, because some of the cleaners can call destructors, which would use EG(symtable_cache_ptr) and thus leave leaks */ /* while (EG(symtable_cache_ptr)>=EG(symtable_cache)) { zend_hash_destroy(*EG(symtable_cache_ptr)); efree(*EG(symtable_cache_ptr)); EG(symtable_cache_ptr)--; } */ zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator); if (CG(unclean_shutdown)) { EG(symbol_table).pDestructor = zend_unclean_zval_ptr_dtor; } zend_hash_graceful_reverse_destroy(&EG(symbol_table)); } zend_end_try(); EG(valid_symbol_table) = 0; zend_try { zval *zeh; /* remove error handlers before destroying classes and functions, * so that if handler used some class, crash would not happen */ if (Z_TYPE(EG(user_error_handler)) != IS_UNDEF) { zeh = &EG(user_error_handler); zval_ptr_dtor(zeh); ZVAL_UNDEF(&EG(user_error_handler)); } if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { zeh = &EG(user_exception_handler); zval_ptr_dtor(zeh); ZVAL_UNDEF(&EG(user_exception_handler)); } zend_stack_clean(&EG(user_error_handlers_error_reporting), NULL, 1); zend_stack_clean(&EG(user_error_handlers), (void (*)(void *))ZVAL_PTR_DTOR, 1); zend_stack_clean(&EG(user_exception_handlers), (void (*)(void *))ZVAL_PTR_DTOR, 1); } zend_end_try(); zend_try { /* Cleanup static data for functions and arrays. * We need a separate cleanup stage because of the following problem: * Suppose we destroy class X, which destroys the class's function table, * and in the function table we have function foo() that has static $bar. * Now if an object of class X is assigned to $bar, its destructor will be * called and will fail since X's function table is in mid-destruction. * So we want first of all to clean up all data and then move to tables destruction. * Note that only run-time accessed data need to be cleaned up, pre-defined data can * not contain objects and thus are not probelmatic */ if (EG(full_tables_cleanup)) { ZEND_HASH_FOREACH_PTR(EG(function_table), func) { if (func->type == ZEND_USER_FUNCTION) { zend_cleanup_op_array_data((zend_op_array *) func); } } ZEND_HASH_FOREACH_END(); ZEND_HASH_REVERSE_FOREACH_PTR(EG(class_table), ce) { if (ce->type == ZEND_USER_CLASS) { zend_cleanup_user_class_data(ce); } else { zend_cleanup_internal_class_data(ce); } } ZEND_HASH_FOREACH_END(); } else { ZEND_HASH_REVERSE_FOREACH_PTR(EG(function_table), func) { if (func->type != ZEND_USER_FUNCTION) { break; } zend_cleanup_op_array_data((zend_op_array *) func); } ZEND_HASH_FOREACH_END(); ZEND_HASH_REVERSE_FOREACH_PTR(EG(class_table), ce) { if (ce->type != ZEND_USER_CLASS) { break; } zend_cleanup_user_class_data(ce); } ZEND_HASH_FOREACH_END(); zend_cleanup_internal_classes(); } } zend_end_try(); zend_try { zend_llist_destroy(&CG(open_files)); } zend_end_try(); zend_try { zend_close_rsrc_list(&EG(regular_list)); } zend_end_try(); #if ZEND_DEBUG if (GC_G(gc_enabled) && !CG(unclean_shutdown)) { gc_collect_cycles(); } #endif zend_try { zend_objects_store_free_object_storage(&EG(objects_store)); zend_vm_stack_destroy(); /* Destroy all op arrays */ if (EG(full_tables_cleanup)) { zend_hash_reverse_apply(EG(function_table), clean_non_persistent_function_full); zend_hash_reverse_apply(EG(class_table), clean_non_persistent_class_full); } else { zend_hash_reverse_apply(EG(function_table), clean_non_persistent_function); zend_hash_reverse_apply(EG(class_table), clean_non_persistent_class); } while (EG(symtable_cache_ptr)>=EG(symtable_cache)) { zend_hash_destroy(*EG(symtable_cache_ptr)); FREE_HASHTABLE(*EG(symtable_cache_ptr)); EG(symtable_cache_ptr)--; } } zend_end_try(); zend_try { clean_non_persistent_constants(); } zend_end_try(); zend_try { #if 0&&ZEND_DEBUG signal(SIGSEGV, original_sigsegv_handler); #endif zend_hash_destroy(&EG(included_files)); zend_stack_destroy(&EG(user_error_handlers_error_reporting)); zend_stack_destroy(&EG(user_error_handlers)); zend_stack_destroy(&EG(user_exception_handlers)); zend_objects_store_destroy(&EG(objects_store)); if (EG(in_autoload)) { zend_hash_destroy(EG(in_autoload)); FREE_HASHTABLE(EG(in_autoload)); } } zend_end_try(); zend_shutdown_fpu(); #if ZEND_DEBUG if (EG(ht_iterators_used) && !CG(unclean_shutdown)) { zend_error(E_WARNING, "Leaked %" PRIu32 " hashtable iterators", EG(ht_iterators_used)); } #endif EG(ht_iterators_used) = 0; if (EG(ht_iterators) != EG(ht_iterators_slots)) { efree(EG(ht_iterators)); } EG(active) = 0; } /* }}} */ /* return class name and "::" or "". */ ZEND_API const char *get_active_class_name(const char **space) /* {{{ */ { zend_function *func; if (!zend_is_executing()) { if (space) { *space = ""; } return ""; } func = EG(current_execute_data)->func; switch (func->type) { case ZEND_USER_FUNCTION: case ZEND_INTERNAL_FUNCTION: { zend_class_entry *ce = func->common.scope; if (space) { *space = ce ? "::" : ""; } return ce ? ZSTR_VAL(ce->name) : ""; } default: if (space) { *space = ""; } return ""; } } /* }}} */ ZEND_API const char *get_active_function_name(void) /* {{{ */ { zend_function *func; if (!zend_is_executing()) { return NULL; } func = EG(current_execute_data)->func; switch (func->type) { case ZEND_USER_FUNCTION: { zend_string *function_name = func->common.function_name; if (function_name) { return ZSTR_VAL(function_name); } else { return "main"; } } break; case ZEND_INTERNAL_FUNCTION: return ZSTR_VAL(func->common.function_name); break; default: return NULL; } } /* }}} */ ZEND_API const char *zend_get_executed_filename(void) /* {{{ */ { zend_execute_data *ex = EG(current_execute_data); while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) { ex = ex->prev_execute_data; } if (ex) { return ZSTR_VAL(ex->func->op_array.filename); } else { return "[no active file]"; } } /* }}} */ ZEND_API zend_string *zend_get_executed_filename_ex(void) /* {{{ */ { zend_execute_data *ex = EG(current_execute_data); while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) { ex = ex->prev_execute_data; } if (ex) { return ex->func->op_array.filename; } else { return NULL; } } /* }}} */ ZEND_API uint zend_get_executed_lineno(void) /* {{{ */ { zend_execute_data *ex = EG(current_execute_data); while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) { ex = ex->prev_execute_data; } if (ex) { if (EG(exception) && ex->opline->opcode == ZEND_HANDLE_EXCEPTION && ex->opline->lineno == 0 && EG(opline_before_exception)) { return EG(opline_before_exception)->lineno; } return ex->opline->lineno; } else { return 0; } } /* }}} */ ZEND_API zend_class_entry *zend_get_executed_scope(void) /* {{{ */ { zend_execute_data *ex = EG(current_execute_data); while (1) { if (!ex) { return NULL; } else if (ex->func && (ZEND_USER_CODE(ex->func->type) || ex->func->common.scope)) { return ex->func->common.scope; } ex = ex->prev_execute_data; } } /* }}} */ ZEND_API zend_bool zend_is_executing(void) /* {{{ */ { return EG(current_execute_data) != 0; } /* }}} */ ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */ { i_zval_ptr_dtor(zval_ptr ZEND_FILE_LINE_RELAY_CC); } /* }}} */ ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */ { if (Z_REFCOUNTED_P(zval_ptr)) { Z_DELREF_P(zval_ptr); if (Z_REFCOUNT_P(zval_ptr) == 0) { _zval_internal_dtor_for_ptr(zval_ptr ZEND_FILE_LINE_CC); } } } /* }}} */ ZEND_API int zval_update_constant_ex(zval *p, zend_class_entry *scope) /* {{{ */ { zval *const_value; char *colon; zend_bool inline_change; if (Z_TYPE_P(p) == IS_CONSTANT) { if (IS_CONSTANT_VISITED(p)) { zend_throw_error(NULL, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p)); return FAILURE; } inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_IMMUTABLE) == 0; SEPARATE_ZVAL_NOREF(p); MARK_CONSTANT_VISITED(p); if (Z_CONST_FLAGS_P(p) & IS_CONSTANT_CLASS) { ZEND_ASSERT(EG(current_execute_data)); if (inline_change) { zend_string_release(Z_STR_P(p)); } if (scope && scope->name) { ZVAL_STR_COPY(p, scope->name); } else { ZVAL_EMPTY_STRING(p); } } else if (UNEXPECTED((const_value = zend_get_constant_ex(Z_STR_P(p), scope, Z_CONST_FLAGS_P(p))) == NULL)) { if (UNEXPECTED(EG(exception))) { RESET_CONSTANT_VISITED(p); return FAILURE; } else if ((colon = (char*)zend_memrchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p)))) { zend_throw_error(NULL, "Undefined class constant '%s'", Z_STRVAL_P(p)); RESET_CONSTANT_VISITED(p); return FAILURE; } else { if ((Z_CONST_FLAGS_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) { zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(p)); RESET_CONSTANT_VISITED(p); return FAILURE; } else { zend_string *save = Z_STR_P(p); char *actual = Z_STRVAL_P(p); size_t actual_len = Z_STRLEN_P(p); char *slash = (char *) zend_memrchr(actual, '\\', actual_len); if (slash) { actual = slash + 1; actual_len -= (actual - Z_STRVAL_P(p)); } zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", actual, actual); if (EG(exception)) { RESET_CONSTANT_VISITED(p); return FAILURE; } if (!inline_change) { ZVAL_STRINGL(p, actual, actual_len); } else { if (slash) { ZVAL_STRINGL(p, actual, actual_len); zend_string_release(save); } else { Z_TYPE_INFO_P(p) = Z_REFCOUNTED_P(p) ? IS_STRING_EX : IS_INTERNED_STRING_EX; } } } } } else { if (inline_change) { zend_string_release(Z_STR_P(p)); } ZVAL_COPY_VALUE(p, const_value); zval_opt_copy_ctor(p); } } else if (Z_TYPE_P(p) == IS_CONSTANT_AST) { zval tmp; inline_change = (Z_TYPE_FLAGS_P(p) & IS_TYPE_IMMUTABLE) == 0; if (UNEXPECTED(zend_ast_evaluate(&tmp, Z_ASTVAL_P(p), scope) != SUCCESS)) { return FAILURE; } if (inline_change) { zval_ptr_dtor(p); } ZVAL_COPY_VALUE(p, &tmp); } return SUCCESS; } /* }}} */ ZEND_API int zval_update_constant(zval *pp) /* {{{ */ { return zval_update_constant_ex(pp, EG(current_execute_data) ? zend_get_executed_scope() : CG(active_class_entry)); } /* }}} */ int _call_user_function_ex(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], int no_separation) /* {{{ */ { zend_fcall_info fci; fci.size = sizeof(fci); fci.object = object ? Z_OBJ_P(object) : NULL; ZVAL_COPY_VALUE(&fci.function_name, function_name); fci.retval = retval_ptr; fci.param_count = param_count; fci.params = params; fci.no_separation = (zend_bool) no_separation; return zend_call_function(&fci, NULL); } /* }}} */ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /* {{{ */ { uint32_t i; zend_execute_data *call, dummy_execute_data; zend_fcall_info_cache fci_cache_local; zend_function *func; ZVAL_UNDEF(fci->retval); if (!EG(active)) { return FAILURE; /* executor is already inactive */ } if (EG(exception)) { return FAILURE; /* we would result in an instable executor otherwise */ } switch (fci->size) { case sizeof(zend_fcall_info): break; /* nothing to do currently */ default: zend_error_noreturn(E_CORE_ERROR, "Corrupted fcall_info provided to zend_call_function()"); break; } /* Initialize execute_data */ if (!EG(current_execute_data)) { /* This only happens when we're called outside any execute()'s * It shouldn't be strictly necessary to NULL execute_data out, * but it may make bugs easier to spot */ memset(&dummy_execute_data, 0, sizeof(zend_execute_data)); EG(current_execute_data) = &dummy_execute_data; } else if (EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type) && EG(current_execute_data)->opline->opcode != ZEND_DO_FCALL && EG(current_execute_data)->opline->opcode != ZEND_DO_ICALL && EG(current_execute_data)->opline->opcode != ZEND_DO_UCALL && EG(current_execute_data)->opline->opcode != ZEND_DO_FCALL_BY_NAME) { /* Insert fake frame in case of include or magic calls */ dummy_execute_data = *EG(current_execute_data); dummy_execute_data.prev_execute_data = EG(current_execute_data); dummy_execute_data.call = NULL; dummy_execute_data.opline = NULL; dummy_execute_data.func = NULL; EG(current_execute_data) = &dummy_execute_data; } if (!fci_cache || !fci_cache->initialized) { zend_string *callable_name; char *error = NULL; if (!fci_cache) { fci_cache = &fci_cache_local; } if (!zend_is_callable_ex(&fci->function_name, fci->object, IS_CALLABLE_CHECK_SILENT, &callable_name, fci_cache, &error)) { if (error) { zend_error(E_WARNING, "Invalid callback %s, %s", ZSTR_VAL(callable_name), error); efree(error); } if (callable_name) { zend_string_release(callable_name); } if (EG(current_execute_data) == &dummy_execute_data) { EG(current_execute_data) = dummy_execute_data.prev_execute_data; } return FAILURE; } else if (error) { /* Capitalize the first latter of the error message */ if (error[0] >= 'a' && error[0] <= 'z') { error[0] += ('A' - 'a'); } zend_error(E_DEPRECATED, "%s", error); efree(error); } zend_string_release(callable_name); } func = fci_cache->function_handler; fci->object = (func->common.fn_flags & ZEND_ACC_STATIC) ? NULL : fci_cache->object; call = zend_vm_stack_push_call_frame(ZEND_CALL_TOP_FUNCTION | ZEND_CALL_DYNAMIC, func, fci->param_count, fci_cache->called_scope, fci->object); if (fci->object && (!EG(objects_store).object_buckets || !IS_OBJ_VALID(EG(objects_store).object_buckets[fci->object->handle]))) { if (EG(current_execute_data) == &dummy_execute_data) { EG(current_execute_data) = dummy_execute_data.prev_execute_data; } return FAILURE; } if (func->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) { if (func->common.fn_flags & ZEND_ACC_ABSTRACT) { zend_throw_error(NULL, "Cannot call abstract method %s::%s()", ZSTR_VAL(func->common.scope->name), ZSTR_VAL(func->common.function_name)); if (EG(current_execute_data) == &dummy_execute_data) { EG(current_execute_data) = dummy_execute_data.prev_execute_data; } return FAILURE; } if (func->common.fn_flags & ZEND_ACC_DEPRECATED) { zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated", func->common.scope ? ZSTR_VAL(func->common.scope->name) : "", func->common.scope ? "::" : "", ZSTR_VAL(func->common.function_name)); } } for (i=0; i<fci->param_count; i++) { zval *param; zval *arg = &fci->params[i]; if (ARG_SHOULD_BE_SENT_BY_REF(func, i + 1)) { if (UNEXPECTED(!Z_ISREF_P(arg))) { if (!fci->no_separation) { /* Separation is enabled -- create a ref */ ZVAL_NEW_REF(arg, arg); } else if (!ARG_MAY_BE_SENT_BY_REF(func, i + 1)) { /* By-value send is not allowed -- emit a warning, * but still perform the call with a by-value send. */ zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given", i+1, func->common.scope ? ZSTR_VAL(func->common.scope->name) : "", func->common.scope ? "::" : "", ZSTR_VAL(func->common.function_name)); } } } else { if (Z_ISREF_P(arg) && !(func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) { /* don't separate references for __call */ arg = Z_REFVAL_P(arg); } } param = ZEND_CALL_ARG(call, i+1); ZVAL_COPY(param, arg); } if (UNEXPECTED(func->op_array.fn_flags & ZEND_ACC_CLOSURE)) { uint32_t call_info; ZEND_ASSERT(GC_TYPE((zend_object*)func->op_array.prototype) == IS_OBJECT); GC_REFCOUNT((zend_object*)func->op_array.prototype)++; call_info = ZEND_CALL_CLOSURE; if (func->common.fn_flags & ZEND_ACC_FAKE_CLOSURE) { call_info |= ZEND_CALL_FAKE_CLOSURE; } ZEND_ADD_CALL_FLAG(call, call_info); } if (func->type == ZEND_USER_FUNCTION) { int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0; const zend_op *current_opline_before_exception = EG(opline_before_exception); zend_init_execute_data(call, &func->op_array, fci->retval); zend_execute_ex(call); EG(opline_before_exception) = current_opline_before_exception; if (call_via_handler) { /* We must re-initialize function again */ fci_cache->initialized = 0; } } else if (func->type == ZEND_INTERNAL_FUNCTION) { int call_via_handler = (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) != 0; ZVAL_NULL(fci->retval); call->prev_execute_data = EG(current_execute_data); call->return_value = NULL; /* this is not a constructor call */ EG(current_execute_data) = call; if (EXPECTED(zend_execute_internal == NULL)) { /* saves one function call if zend_execute_internal is not used */ func->internal_function.handler(call, fci->retval); } else { zend_execute_internal(call, fci->retval); } EG(current_execute_data) = call->prev_execute_data; zend_vm_stack_free_args(call); /* We shouldn't fix bad extensions here, because it can break proper ones (Bug #34045) if (!EX(function_state).function->common.return_reference) { INIT_PZVAL(f->retval); }*/ if (EG(exception)) { zval_ptr_dtor(fci->retval); ZVAL_UNDEF(fci->retval); } if (call_via_handler) { /* We must re-initialize function again */ fci_cache->initialized = 0; } } else { /* ZEND_OVERLOADED_FUNCTION */ ZVAL_NULL(fci->retval); /* Not sure what should be done here if it's a static method */ if (fci->object) { call->prev_execute_data = EG(current_execute_data); EG(current_execute_data) = call; fci->object->handlers->call_method(func->common.function_name, fci->object, call, fci->retval); EG(current_execute_data) = call->prev_execute_data; } else { zend_throw_error(NULL, "Cannot call overloaded function for non-object"); } zend_vm_stack_free_args(call); if (func->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) { zend_string_release(func->common.function_name); } efree(func); if (EG(exception)) { zval_ptr_dtor(fci->retval); ZVAL_UNDEF(fci->retval); } } zend_vm_stack_free_call_frame(call); if (EG(current_execute_data) == &dummy_execute_data) { EG(current_execute_data) = dummy_execute_data.prev_execute_data; } if (EG(exception)) { zend_throw_exception_internal(NULL); } return SUCCESS; } /* }}} */ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload) /* {{{ */ { zend_class_entry *ce = NULL; zval args[1]; zval local_retval; zend_string *lc_name; zend_fcall_info fcall_info; zend_fcall_info_cache fcall_cache; if (key) { lc_name = Z_STR_P(key); } else { if (name == NULL || !ZSTR_LEN(name)) { return NULL; } if (ZSTR_VAL(name)[0] == '\\') { lc_name = zend_string_alloc(ZSTR_LEN(name) - 1, 0); zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1); } else { lc_name = zend_string_tolower(name); } } ce = zend_hash_find_ptr(EG(class_table), lc_name); if (ce) { if (!key) { zend_string_release(lc_name); } return ce; } /* The compiler is not-reentrant. Make sure we __autoload() only during run-time * (doesn't impact functionality of __autoload() */ if (!use_autoload || zend_is_compiling()) { if (!key) { zend_string_release(lc_name); } return NULL; } if (!EG(autoload_func)) { zend_function *func = zend_hash_find_ptr(EG(function_table), CG(known_strings)[ZEND_STR_MAGIC_AUTOLOAD]); if (func) { EG(autoload_func) = func; } else { if (!key) { zend_string_release(lc_name); } return NULL; } } /* Verify class name before passing it to __autoload() */ if (strspn(ZSTR_VAL(name), "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\") != ZSTR_LEN(name)) { if (!key) { zend_string_release(lc_name); } return NULL; } if (EG(in_autoload) == NULL) { ALLOC_HASHTABLE(EG(in_autoload)); zend_hash_init(EG(in_autoload), 8, NULL, NULL, 0); } if (zend_hash_add_empty_element(EG(in_autoload), lc_name) == NULL) { if (!key) { zend_string_release(lc_name); } return NULL; } ZVAL_UNDEF(&local_retval); if (ZSTR_VAL(name)[0] == '\\') { ZVAL_STRINGL(&args[0], ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1); } else { ZVAL_STR_COPY(&args[0], name); } fcall_info.size = sizeof(fcall_info); ZVAL_STR_COPY(&fcall_info.function_name, EG(autoload_func)->common.function_name); fcall_info.retval = &local_retval; fcall_info.param_count = 1; fcall_info.params = args; fcall_info.object = NULL; fcall_info.no_separation = 1; fcall_cache.initialized = 1; fcall_cache.function_handler = EG(autoload_func); fcall_cache.calling_scope = NULL; fcall_cache.called_scope = NULL; fcall_cache.object = NULL; zend_exception_save(); if ((zend_call_function(&fcall_info, &fcall_cache) == SUCCESS) && !EG(exception)) { ce = zend_hash_find_ptr(EG(class_table), lc_name); } zend_exception_restore(); zval_ptr_dtor(&args[0]); zval_dtor(&fcall_info.function_name); zend_hash_del(EG(in_autoload), lc_name); zval_ptr_dtor(&local_retval); if (!key) { zend_string_release(lc_name); } return ce; } /* }}} */ ZEND_API zend_class_entry *zend_lookup_class(zend_string *name) /* {{{ */ { return zend_lookup_class_ex(name, NULL, 1); } /* }}} */ ZEND_API zend_class_entry *zend_get_called_scope(zend_execute_data *ex) /* {{{ */ { while (ex) { if (Z_TYPE(ex->This) == IS_OBJECT) { return Z_OBJCE(ex->This); } else if (Z_CE(ex->This)) { return Z_CE(ex->This); } else if (ex->func) { if (ex->func->type != ZEND_INTERNAL_FUNCTION || ex->func->common.scope) { return NULL; } } ex = ex->prev_execute_data; } return NULL; } /* }}} */ ZEND_API zend_object *zend_get_this_object(zend_execute_data *ex) /* {{{ */ { while (ex) { if (Z_TYPE(ex->This) == IS_OBJECT) { return Z_OBJ(ex->This); } else if (ex->func) { if (ex->func->type != ZEND_INTERNAL_FUNCTION || ex->func->common.scope) { return NULL; } } ex = ex->prev_execute_data; } return NULL; } /* }}} */ ZEND_API int zend_eval_stringl(char *str, size_t str_len, zval *retval_ptr, char *string_name) /* {{{ */ { zval pv; zend_op_array *new_op_array; uint32_t original_compiler_options; int retval; if (retval_ptr) { ZVAL_NEW_STR(&pv, zend_string_alloc(str_len + sizeof("return ;")-1, 1)); memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1); memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, str, str_len); Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';'; Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0'; } else { ZVAL_STRINGL(&pv, str, str_len); } /*printf("Evaluating '%s'\n", pv.value.str.val);*/ original_compiler_options = CG(compiler_options); CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL; new_op_array = zend_compile_string(&pv, string_name); CG(compiler_options) = original_compiler_options; if (new_op_array) { zval local_retval; EG(no_extensions)=1; zend_try { ZVAL_UNDEF(&local_retval); zend_execute(new_op_array, &local_retval); } zend_catch { destroy_op_array(new_op_array); efree_size(new_op_array, sizeof(zend_op_array)); zend_bailout(); } zend_end_try(); if (Z_TYPE(local_retval) != IS_UNDEF) { if (retval_ptr) { ZVAL_COPY_VALUE(retval_ptr, &local_retval); } else { zval_ptr_dtor(&local_retval); } } else { if (retval_ptr) { ZVAL_NULL(retval_ptr); } } EG(no_extensions)=0; destroy_op_array(new_op_array); efree_size(new_op_array, sizeof(zend_op_array)); retval = SUCCESS; } else { retval = FAILURE; } zval_dtor(&pv); return retval; } /* }}} */ ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name) /* {{{ */ { return zend_eval_stringl(str, strlen(str), retval_ptr, string_name); } /* }}} */ ZEND_API int zend_eval_stringl_ex(char *str, size_t str_len, zval *retval_ptr, char *string_name, int handle_exceptions) /* {{{ */ { int result; result = zend_eval_stringl(str, str_len, retval_ptr, string_name); if (handle_exceptions && EG(exception)) { zend_exception_error(EG(exception), E_ERROR); result = FAILURE; } return result; } /* }}} */ ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions) /* {{{ */ { return zend_eval_stringl_ex(str, strlen(str), retval_ptr, string_name, handle_exceptions); } /* }}} */ static void zend_set_timeout_ex(zend_long seconds, int reset_signals); ZEND_API ZEND_NORETURN void zend_timeout(int dummy) /* {{{ */ { #if defined(PHP_WIN32) # ifndef ZTS /* No action is needed if we're timed out because zero seconds are just ignored. Also, the hard timeout needs to be respected. If the timer is not restarted properly, it could hang in the shutdown function. */ if (EG(hard_timeout) > 0) { EG(timed_out) = 0; zend_set_timeout_ex(EG(hard_timeout), 1); /* XXX Abused, introduce an additional flag if the value needs to be kept. */ EG(hard_timeout) = 0; } # endif #else EG(timed_out) = 0; zend_set_timeout_ex(0, 1); #endif zend_error_noreturn(E_ERROR, "Maximum execution time of " ZEND_LONG_FMT " second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s"); } /* }}} */ #ifndef ZEND_WIN32 static void zend_timeout_handler(int dummy) /* {{{ */ { #ifndef ZTS if (EG(timed_out)) { /* Die on hard timeout */ const char *error_filename = NULL; uint error_lineno = 0; char log_buffer[2048]; int output_len = 0; if (zend_is_compiling()) { error_filename = ZSTR_VAL(zend_get_compiled_filename()); error_lineno = zend_get_compiled_lineno(); } else if (zend_is_executing()) { error_filename = zend_get_executed_filename(); if (error_filename[0] == '[') { /* [no active file] */ error_filename = NULL; error_lineno = 0; } else { error_lineno = zend_get_executed_lineno(); } } if (!error_filename) { error_filename = "Unknown"; } output_len = snprintf(log_buffer, sizeof(log_buffer), "\nFatal error: Maximum execution time of " ZEND_LONG_FMT "+" ZEND_LONG_FMT " seconds exceeded (terminated) in %s on line %d\n", EG(timeout_seconds), EG(hard_timeout), error_filename, error_lineno); if (output_len > 0) { write(2, log_buffer, MIN(output_len, sizeof(log_buffer))); } _exit(1); } #endif if (zend_on_timeout) { #ifdef ZEND_SIGNALS /* We got here because we got a timeout signal, so we are in a signal handler at this point. However, we want to be able to timeout any user-supplied shutdown functions, so pretend we are not in a signal handler while we are calling these */ SIGG(running) = 0; #endif zend_on_timeout(EG(timeout_seconds)); } EG(timed_out) = 1; EG(vm_interrupt) = 1; #ifndef ZTS if (EG(hard_timeout) > 0) { /* Set hard timeout */ zend_set_timeout_ex(EG(hard_timeout), 1); } #endif } /* }}} */ #endif #ifdef ZEND_WIN32 VOID CALLBACK tq_timer_cb(PVOID arg, BOOLEAN timed_out) { zend_executor_globals *eg; /* The doc states it'll be always true, however it theoretically could be FALSE when the thread was signaled. */ if (!timed_out) { return; } eg = (zend_executor_globals *)arg; eg->timed_out = 1; eg->vm_interrupt = 1; } #endif /* This one doesn't exists on QNX */ #ifndef SIGPROF #define SIGPROF 27 #endif static void zend_set_timeout_ex(zend_long seconds, int reset_signals) /* {{{ */ { #ifdef ZEND_WIN32 zend_executor_globals *eg; if(!seconds) { return; } /* Don't use ChangeTimerQueueTimer() as it will not restart an expired timer, so we could end up with just an ignored timeout. Instead delete and recreate. */ if (NULL != tq_timer) { if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL)) { tq_timer = NULL; zend_error_noreturn(E_ERROR, "Could not delete queued timer"); return; } tq_timer = NULL; } /* XXX passing NULL means the default timer queue provided by the system is used */ eg = ZEND_MODULE_GLOBALS_BULK(executor); if (!CreateTimerQueueTimer(&tq_timer, NULL, (WAITORTIMERCALLBACK)tq_timer_cb, (VOID*)eg, seconds*1000, 0, WT_EXECUTEONLYONCE)) { tq_timer = NULL; zend_error_noreturn(E_ERROR, "Could not queue new timer"); return; } #else # ifdef HAVE_SETITIMER { struct itimerval t_r; /* timeout requested */ int signo; if(seconds) { t_r.it_value.tv_sec = seconds; t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0; # ifdef __CYGWIN__ setitimer(ITIMER_REAL, &t_r, NULL); } signo = SIGALRM; # else setitimer(ITIMER_PROF, &t_r, NULL); } signo = SIGPROF; # endif if (reset_signals) { # ifdef ZEND_SIGNALS zend_signal(signo, zend_timeout_handler); # else sigset_t sigset; # ifdef HAVE_SIGACTION struct sigaction act; act.sa_handler = zend_timeout_handler; sigemptyset(&act.sa_mask); act.sa_flags = SA_RESETHAND | SA_NODEFER; sigaction(signo, &act, NULL); # else signal(signo, zend_timeout_handler); # endif /* HAVE_SIGACTION */ sigemptyset(&sigset); sigaddset(&sigset, signo); sigprocmask(SIG_UNBLOCK, &sigset, NULL); # endif /* ZEND_SIGNALS */ } } # endif /* HAVE_SETITIMER */ #endif } /* }}} */ void zend_set_timeout(zend_long seconds, int reset_signals) /* {{{ */ { EG(timeout_seconds) = seconds; zend_set_timeout_ex(seconds, reset_signals); EG(timed_out) = 0; } /* }}} */ void zend_unset_timeout(void) /* {{{ */ { #ifdef ZEND_WIN32 if (NULL != tq_timer) { if (!DeleteTimerQueueTimer(NULL, tq_timer, NULL)) { EG(timed_out) = 0; tq_timer = NULL; zend_error_noreturn(E_ERROR, "Could not delete queued timer"); return; } tq_timer = NULL; } EG(timed_out) = 0; #else # ifdef HAVE_SETITIMER if (EG(timeout_seconds)) { struct itimerval no_timeout; no_timeout.it_value.tv_sec = no_timeout.it_value.tv_usec = no_timeout.it_interval.tv_sec = no_timeout.it_interval.tv_usec = 0; #ifdef __CYGWIN__ setitimer(ITIMER_REAL, &no_timeout, NULL); #else setitimer(ITIMER_PROF, &no_timeout, NULL); #endif } # endif EG(timed_out) = 0; #endif } /* }}} */ zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type) /* {{{ */ { zend_class_entry *ce, *scope; int fetch_sub_type = fetch_type & ZEND_FETCH_CLASS_MASK; check_fetch_type: switch (fetch_sub_type) { case ZEND_FETCH_CLASS_SELF: scope = zend_get_executed_scope(); if (UNEXPECTED(!scope)) { zend_throw_or_error(fetch_type, NULL, "Cannot access self:: when no class scope is active"); } return scope; case ZEND_FETCH_CLASS_PARENT: scope = zend_get_executed_scope(); if (UNEXPECTED(!scope)) { zend_throw_or_error(fetch_type, NULL, "Cannot access parent:: when no class scope is active"); return NULL; } if (UNEXPECTED(!scope->parent)) { zend_throw_or_error(fetch_type, NULL, "Cannot access parent:: when current class scope has no parent"); } return scope->parent; case ZEND_FETCH_CLASS_STATIC: ce = zend_get_called_scope(EG(current_execute_data)); if (UNEXPECTED(!ce)) { zend_throw_or_error(fetch_type, NULL, "Cannot access static:: when no class scope is active"); return NULL; } return ce; case ZEND_FETCH_CLASS_AUTO: { fetch_sub_type = zend_get_class_fetch_type(class_name); if (UNEXPECTED(fetch_sub_type != ZEND_FETCH_CLASS_DEFAULT)) { goto check_fetch_type; } } break; } if (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) { return zend_lookup_class_ex(class_name, NULL, 0); } else if ((ce = zend_lookup_class_ex(class_name, NULL, 1)) == NULL) { if (!(fetch_type & ZEND_FETCH_CLASS_SILENT) && !EG(exception)) { if (fetch_sub_type == ZEND_FETCH_CLASS_INTERFACE) { zend_throw_or_error(fetch_type, NULL, "Interface '%s' not found", ZSTR_VAL(class_name)); } else if (fetch_sub_type == ZEND_FETCH_CLASS_TRAIT) { zend_throw_or_error(fetch_type, NULL, "Trait '%s' not found", ZSTR_VAL(class_name)); } else { zend_throw_or_error(fetch_type, NULL, "Class '%s' not found", ZSTR_VAL(class_name)); } } return NULL; } return ce; } /* }}} */ zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval *key, int fetch_type) /* {{{ */ { zend_class_entry *ce; if (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) { return zend_lookup_class_ex(class_name, key, 0); } else if ((ce = zend_lookup_class_ex(class_name, key, 1)) == NULL) { if ((fetch_type & ZEND_FETCH_CLASS_SILENT) == 0 && !EG(exception)) { if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) { zend_throw_or_error(fetch_type, NULL, "Interface '%s' not found", ZSTR_VAL(class_name)); } else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) { zend_throw_or_error(fetch_type, NULL, "Trait '%s' not found", ZSTR_VAL(class_name)); } else { zend_throw_or_error(fetch_type, NULL, "Class '%s' not found", ZSTR_VAL(class_name)); } } return NULL; } return ce; } /* }}} */ #define MAX_ABSTRACT_INFO_CNT 3 #define MAX_ABSTRACT_INFO_FMT "%s%s%s%s" #define DISPLAY_ABSTRACT_FN(idx) \ ai.afn[idx] ? ZEND_FN_SCOPE_NAME(ai.afn[idx]) : "", \ ai.afn[idx] ? "::" : "", \ ai.afn[idx] ? ZSTR_VAL(ai.afn[idx]->common.function_name) : "", \ ai.afn[idx] && ai.afn[idx + 1] ? ", " : (ai.afn[idx] && ai.cnt > MAX_ABSTRACT_INFO_CNT ? ", ..." : "") typedef struct _zend_abstract_info { zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1]; int cnt; int ctor; } zend_abstract_info; static void zend_verify_abstract_class_function(zend_function *fn, zend_abstract_info *ai) /* {{{ */ { if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) { if (ai->cnt < MAX_ABSTRACT_INFO_CNT) { ai->afn[ai->cnt] = fn; } if (fn->common.fn_flags & ZEND_ACC_CTOR) { if (!ai->ctor) { ai->cnt++; ai->ctor = 1; } else { ai->afn[ai->cnt] = NULL; } } else { ai->cnt++; } } } /* }}} */ void zend_verify_abstract_class(zend_class_entry *ce) /* {{{ */ { zend_function *func; zend_abstract_info ai; if ((ce->ce_flags & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) && !(ce->ce_flags & (ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) { memset(&ai, 0, sizeof(ai)); ZEND_HASH_FOREACH_PTR(&ce->function_table, func) { zend_verify_abstract_class_function(func, &ai); } ZEND_HASH_FOREACH_END(); if (ai.cnt) { zend_error_noreturn(E_ERROR, "Class %s contains %d abstract method%s and must therefore be declared abstract or implement the remaining methods (" MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT ")", ZSTR_VAL(ce->name), ai.cnt, ai.cnt > 1 ? "s" : "", DISPLAY_ABSTRACT_FN(0), DISPLAY_ABSTRACT_FN(1), DISPLAY_ABSTRACT_FN(2) ); } } } /* }}} */ ZEND_API int zend_delete_global_variable(zend_string *name) /* {{{ */ { return zend_hash_del_ind(&EG(symbol_table), name); } /* }}} */ ZEND_API zend_array *zend_rebuild_symbol_table(void) /* {{{ */ { zend_execute_data *ex; zend_array *symbol_table; /* Search for last called user function */ ex = EG(current_execute_data); while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->common.type))) { ex = ex->prev_execute_data; } if (!ex) { return NULL; } if (ZEND_CALL_INFO(ex) & ZEND_CALL_HAS_SYMBOL_TABLE) { return ex->symbol_table; } ZEND_ADD_CALL_FLAG(ex, ZEND_CALL_HAS_SYMBOL_TABLE); if (EG(symtable_cache_ptr) >= EG(symtable_cache)) { /*printf("Cache hit! Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/ symbol_table = ex->symbol_table = *(EG(symtable_cache_ptr)--); if (!ex->func->op_array.last_var) { return symbol_table; } zend_hash_extend(symbol_table, ex->func->op_array.last_var, 0); } else { symbol_table = ex->symbol_table = emalloc(sizeof(zend_array)); zend_hash_init(symbol_table, ex->func->op_array.last_var, NULL, ZVAL_PTR_DTOR, 0); if (!ex->func->op_array.last_var) { return symbol_table; } zend_hash_real_init(symbol_table, 0); /*printf("Cache miss! Initialized %x\n", EG(active_symbol_table));*/ } if (EXPECTED(ex->func->op_array.last_var)) { zend_string **str = ex->func->op_array.vars; zend_string **end = str + ex->func->op_array.last_var; zval *var = ZEND_CALL_VAR_NUM(ex, 0); do { _zend_hash_append_ind(symbol_table, *str, var); str++; var++; } while (str != end); } return symbol_table; } /* }}} */ ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data) /* {{{ */ { zend_op_array *op_array = &execute_data->func->op_array; HashTable *ht = execute_data->symbol_table; /* copy real values from symbol table into CV slots and create INDIRECT references to CV in symbol table */ if (EXPECTED(op_array->last_var)) { zend_string **str = op_array->vars; zend_string **end = str + op_array->last_var; zval *var = EX_VAR_NUM(0); do { zval *zv = zend_hash_find(ht, *str); if (zv) { if (Z_TYPE_P(zv) == IS_INDIRECT) { zval *val = Z_INDIRECT_P(zv); ZVAL_COPY_VALUE(var, val); } else { ZVAL_COPY_VALUE(var, zv); } } else { ZVAL_UNDEF(var); zv = zend_hash_add_new(ht, *str, var); } ZVAL_INDIRECT(zv, var); str++; var++; } while (str != end); } } /* }}} */ ZEND_API void zend_detach_symbol_table(zend_execute_data *execute_data) /* {{{ */ { zend_op_array *op_array = &execute_data->func->op_array; HashTable *ht = execute_data->symbol_table; /* copy real values from CV slots into symbol table */ if (EXPECTED(op_array->last_var)) { zend_string **str = op_array->vars; zend_string **end = str + op_array->last_var; zval *var = EX_VAR_NUM(0); do { if (Z_TYPE_P(var) == IS_UNDEF) { zend_hash_del(ht, *str); } else { zend_hash_update(ht, *str, var); ZVAL_UNDEF(var); } str++; var++; } while (str != end); } } /* }}} */ ZEND_API int zend_set_local_var(zend_string *name, zval *value, int force) /* {{{ */ { zend_execute_data *execute_data = EG(current_execute_data); while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) { execute_data = execute_data->prev_execute_data; } if (execute_data) { if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) { zend_ulong h = zend_string_hash_val(name); zend_op_array *op_array = &execute_data->func->op_array; if (EXPECTED(op_array->last_var)) { zend_string **str = op_array->vars; zend_string **end = str + op_array->last_var; do { if (ZSTR_H(*str) == h && ZSTR_LEN(*str) == ZSTR_LEN(name) && memcmp(ZSTR_VAL(*str), ZSTR_VAL(name), ZSTR_LEN(name)) == 0) { zval *var = EX_VAR_NUM(str - op_array->vars); ZVAL_COPY_VALUE(var, value); return SUCCESS; } str++; } while (str != end); } if (force) { zend_array *symbol_table = zend_rebuild_symbol_table(); if (symbol_table) { return zend_hash_update(symbol_table, name, value) ? SUCCESS : FAILURE;; } } } else { return (zend_hash_update_ind(execute_data->symbol_table, name, value) != NULL) ? SUCCESS : FAILURE; } } return FAILURE; } /* }}} */ ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, int force) /* {{{ */ { zend_execute_data *execute_data = EG(current_execute_data); while (execute_data && (!execute_data->func || !ZEND_USER_CODE(execute_data->func->common.type))) { execute_data = execute_data->prev_execute_data; } if (execute_data) { if (!(EX_CALL_INFO() & ZEND_CALL_HAS_SYMBOL_TABLE)) { zend_ulong h = zend_hash_func(name, len); zend_op_array *op_array = &execute_data->func->op_array; if (EXPECTED(op_array->last_var)) { zend_string **str = op_array->vars; zend_string **end = str + op_array->last_var; do { if (ZSTR_H(*str) == h && ZSTR_LEN(*str) == len && memcmp(ZSTR_VAL(*str), name, len) == 0) { zval *var = EX_VAR_NUM(str - op_array->vars); zval_ptr_dtor(var); ZVAL_COPY_VALUE(var, value); return SUCCESS; } str++; } while (str != end); } if (force) { zend_array *symbol_table = zend_rebuild_symbol_table(); if (symbol_table) { return zend_hash_str_update(symbol_table, name, len, value) ? SUCCESS : FAILURE;; } } } else { return (zend_hash_str_update_ind(execute_data->symbol_table, name, len, value) != NULL) ? SUCCESS : FAILURE; } } return FAILURE; } /* }}} */ ZEND_API int zend_forbid_dynamic_call(const char *func_name) /* {{{ */ { zend_execute_data *ex = EG(current_execute_data); ZEND_ASSERT(ex != NULL && ex->func != NULL); if (ZEND_CALL_INFO(ex) & ZEND_CALL_DYNAMIC) { zend_error(E_WARNING, "Cannot call %s dynamically", func_name); return FAILURE; } return SUCCESS; } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * indent-tabs-mode: t * End: */
704859.c
/***************************************************************************** * update_crypto.c: OpenPGP related functions used for updating ***************************************************************************** * Copyright © 2008-2009 VLC authors and VideoLAN * $Id: 09479468c00337ddadd44f27e6cbee6428a28ed5 $ * * Authors: Rafaël Carré <funman@videolanorg> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either release 2 of the License, or * (at your option) any later release. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /** * \file * This file contains functions related to OpenPGP in VLC update management */ /***************************************************************************** * Preamble *****************************************************************************/ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include <gcrypt.h> #include <assert.h> #include <limits.h> #include "vlc_common.h" #include <vlc_stream.h> #include <vlc_strings.h> #include <vlc_fs.h> #include "update.h" /***************************************************************************** * OpenPGP functions *****************************************************************************/ #define packet_type( c ) ( ( c & 0x3c ) >> 2 ) /* 0x3C = 00111100 */ #define packet_header_len( c ) ( ( c & 0x03 ) + 1 ) /* number of bytes in a packet header */ static inline uint32_t scalar_number( const uint8_t *p, int header_len ) { assert( header_len == 1 || header_len == 2 || header_len == 4 ); if( header_len == 1 ) return( p[0] ); else if( header_len == 2 ) return( (p[0] << 8) + p[1] ); else if( header_len == 4 ) return( ((uint32_t)p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3] ); else abort(); } /* number of data bytes in a MPI */ static uint32_t mpi_len(const uint8_t *mpi) { return (scalar_number(mpi, 2) + 7) / 8; } static size_t read_mpi(uint8_t *dst, const uint8_t *buf, size_t buflen, size_t bits) { if (buflen < 2) return 0; size_t n = mpi_len(buf); if (n * 8 > bits) return 0; n += 2; if (buflen < n) return 0; memcpy(dst, buf, n); return n; } #define READ_MPI(d, bits) do { \ size_t n = read_mpi(d, p_buf, i_packet_len - i_read, bits); \ if (!n) goto error; \ p_buf += n; \ i_read += n; \ } while(0) /* * fill a public_key_packet_t structure from public key packet data * verify that it is a version 4 public key packet, using DSA or RSA */ static int parse_public_key_packet( public_key_packet_t *p_key, const uint8_t *p_buf, size_t i_packet_len ) { if( i_packet_len < 6 ) return VLC_EGENERIC; size_t i_read = 0; p_key->version = *p_buf++; i_read++; if( p_key->version != 4 ) return VLC_EGENERIC; /* XXX: warn when timestamp is > date ? */ memcpy( p_key->timestamp, p_buf, 4 ); p_buf += 4; i_read += 4; p_key->algo = *p_buf++; i_read++; if( p_key->algo == GCRY_PK_DSA ) { READ_MPI(p_key->sig.dsa.p, 3072); READ_MPI(p_key->sig.dsa.q, 256); READ_MPI(p_key->sig.dsa.g, 3072); READ_MPI(p_key->sig.dsa.y, 3072); } else if ( p_key->algo == GCRY_PK_RSA ) { READ_MPI(p_key->sig.rsa.n, 4096); READ_MPI(p_key->sig.rsa.e, 4096); } else return VLC_EGENERIC; if( i_read == i_packet_len ) return VLC_SUCCESS; /* some extra data eh ? */ error: return VLC_EGENERIC; } static size_t parse_signature_v3_packet( signature_packet_t *p_sig, const uint8_t *p_buf, size_t i_sig_len ) { size_t i_read = 1; /* we already read the version byte */ if( i_sig_len < 19 ) /* signature is at least 19 bytes + the 2 MPIs */ return 0; p_sig->specific.v3.hashed_data_len = *p_buf++; i_read++; if( p_sig->specific.v3.hashed_data_len != 5 ) return 0; p_sig->type = *p_buf++; i_read++; memcpy( p_sig->specific.v3.timestamp, p_buf, 4 ); p_buf += 4; i_read += 4; memcpy( p_sig->issuer_longid, p_buf, 8 ); p_buf += 8; i_read += 8; p_sig->public_key_algo = *p_buf++; i_read++; p_sig->digest_algo = *p_buf++; i_read++; p_sig->hash_verification[0] = *p_buf++; i_read++; p_sig->hash_verification[1] = *p_buf++; i_read++; assert( i_read == 19 ); return i_read; } /* * fill a signature_packet_v4_t from signature packet data * verify that it was used with a DSA or RSA public key */ static size_t parse_signature_v4_packet( signature_packet_t *p_sig, const uint8_t *p_buf, size_t i_sig_len ) { size_t i_read = 1; /* we already read the version byte */ if( i_sig_len < 10 ) /* signature is at least 10 bytes + the 2 MPIs */ return 0; p_sig->type = *p_buf++; i_read++; p_sig->public_key_algo = *p_buf++; i_read++; if (p_sig->public_key_algo != GCRY_PK_DSA && p_sig->public_key_algo != GCRY_PK_RSA ) return 0; p_sig->digest_algo = *p_buf++; i_read++; memcpy( p_sig->specific.v4.hashed_data_len, p_buf, 2 ); p_buf += 2; i_read += 2; size_t i_hashed_data_len = scalar_number( p_sig->specific.v4.hashed_data_len, 2 ); i_read += i_hashed_data_len; if( i_read + 4 > i_sig_len ) return 0; p_sig->specific.v4.hashed_data = (uint8_t*) malloc( i_hashed_data_len ); if( !p_sig->specific.v4.hashed_data ) return 0; memcpy( p_sig->specific.v4.hashed_data, p_buf, i_hashed_data_len ); p_buf += i_hashed_data_len; memcpy( p_sig->specific.v4.unhashed_data_len, p_buf, 2 ); p_buf += 2; i_read += 2; size_t i_unhashed_data_len = scalar_number( p_sig->specific.v4.unhashed_data_len, 2 ); i_read += i_unhashed_data_len; if( i_read + 2 > i_sig_len ) return 0; p_sig->specific.v4.unhashed_data = (uint8_t*) malloc( i_unhashed_data_len ); if( !p_sig->specific.v4.unhashed_data ) return 0; memcpy( p_sig->specific.v4.unhashed_data, p_buf, i_unhashed_data_len ); p_buf += i_unhashed_data_len; memcpy( p_sig->hash_verification, p_buf, 2 ); p_buf += 2; i_read += 2; uint8_t *p, *max_pos; p = p_sig->specific.v4.unhashed_data; max_pos = p + scalar_number( p_sig->specific.v4.unhashed_data_len, 2 ); for( ;; ) { if( p > max_pos ) return 0; size_t i_subpacket_len; if( *p < 192 ) { if( p + 1 > max_pos ) return 0; i_subpacket_len = *p++; } else if( *p < 255 ) { if( p + 2 > max_pos ) return 0; i_subpacket_len = (*p++ - 192) << 8; i_subpacket_len += *p++ + 192; } else { if( ++p + 4 > max_pos ) return 0; i_subpacket_len = U32_AT(p); p += 4; } if( *p == ISSUER_SUBPACKET ) { if( p + 9 > max_pos ) return 0; memcpy( &p_sig->issuer_longid, p+1, 8 ); return i_read; } p += i_subpacket_len; } } static int parse_signature_packet( signature_packet_t *p_sig, const uint8_t *p_buf, size_t i_packet_len ) { if( !i_packet_len ) /* 1st sanity check, we need at least the version */ return VLC_EGENERIC; p_sig->version = *p_buf++; size_t i_read; switch( p_sig->version ) { case 3: i_read = parse_signature_v3_packet( p_sig, p_buf, i_packet_len ); break; case 4: p_sig->specific.v4.hashed_data = NULL; p_sig->specific.v4.unhashed_data = NULL; i_read = parse_signature_v4_packet( p_sig, p_buf, i_packet_len ); break; default: return VLC_EGENERIC; } if( i_read == 0 ) /* signature packet parsing has failed */ goto error; if( p_sig->public_key_algo != GCRY_PK_DSA && p_sig->public_key_algo != GCRY_PK_RSA ) goto error; switch( p_sig->type ) { case BINARY_SIGNATURE: case TEXT_SIGNATURE: case GENERIC_KEY_SIGNATURE: case PERSONA_KEY_SIGNATURE: case CASUAL_KEY_SIGNATURE: case POSITIVE_KEY_SIGNATURE: break; default: goto error; } p_buf--; /* rewind to the version byte */ p_buf += i_read; if( p_sig->public_key_algo == GCRY_PK_DSA ) { READ_MPI(p_sig->algo_specific.dsa.r, 256); READ_MPI(p_sig->algo_specific.dsa.s, 256); } else if ( p_sig->public_key_algo == GCRY_PK_RSA ) { READ_MPI(p_sig->algo_specific.rsa.s, 4096); } else goto error; assert( i_read == i_packet_len ); if( i_read < i_packet_len ) /* some extra data, hm ? */ goto error; return VLC_SUCCESS; error: if( p_sig->version == 4 ) { free( p_sig->specific.v4.hashed_data ); free( p_sig->specific.v4.unhashed_data ); } return VLC_EGENERIC; } /* * crc_octets() was lamely copied from rfc 2440 * Copyright (C) The Internet Society (1998). All Rights Reserved. */ #define CRC24_INIT 0xB704CEL #define CRC24_POLY 0x1864CFBL static long crc_octets( uint8_t *octets, size_t len ) { long crc = CRC24_INIT; int i; while (len--) { crc ^= (*octets++) << 16; for (i = 0; i < 8; i++) { crc <<= 1; if (crc & 0x1000000) crc ^= CRC24_POLY; } } return crc & 0xFFFFFFL; } /* * Transform an armored document in binary format * Used on public keys and signatures */ static int pgp_unarmor( const char *p_ibuf, size_t i_ibuf_len, uint8_t *p_obuf, size_t i_obuf_len ) { const char *p_ipos = p_ibuf; uint8_t *p_opos = p_obuf; int i_end = 0; int i_header_skipped = 0; while( !i_end && p_ipos < p_ibuf + i_ibuf_len && *p_ipos != '=' ) { if( *p_ipos == '\r' || *p_ipos == '\n' ) { p_ipos++; continue; } size_t i_line_len = strcspn( p_ipos, "\r\n" ); if( i_line_len == 0 ) continue; if( !i_header_skipped ) { if( !strncmp( p_ipos, "-----BEGIN PGP", 14 ) ) i_header_skipped = 1; p_ipos += i_line_len + 1; continue; } if( !strncmp( p_ipos, "Version:", 8 ) ) { p_ipos += i_line_len + 1; continue; } if( p_ipos[i_line_len - 1] == '=' ) { i_end = 1; } p_opos += vlc_b64_decode_binary_to_buffer( p_opos, p_obuf - p_opos + i_obuf_len, p_ipos ); p_ipos += i_line_len + 1; } /* XXX: the CRC is OPTIONAL, really require it ? */ if( p_ipos + 5 > p_ibuf + i_ibuf_len || *p_ipos++ != '=' ) return 0; uint8_t p_crc[3]; if( vlc_b64_decode_binary_to_buffer( p_crc, 3, p_ipos ) != 3 ) return 0; long l_crc = crc_octets( p_obuf, p_opos - p_obuf ); long l_crc2 = ( 0 << 24 ) + ( p_crc[0] << 16 ) + ( p_crc[1] << 8 ) + p_crc[2]; return l_crc2 == l_crc ? p_opos - p_obuf : 0; } static int rsa_pkcs1_encode_sig(gcry_mpi_t *r_result, size_t size, const uint8_t *hash, int algo) { uint8_t asn[100]; uint8_t frame[4096/8]; size_t asnlen = sizeof(asn); size_t hashlen = gcry_md_get_algo_dlen(algo); if (gcry_md_algo_info(algo, GCRYCTL_GET_ASNOID, asn, &asnlen)) return VLC_EGENERIC; if (!hashlen || hashlen + asnlen + 4 > size) return VLC_EGENERIC; frame[0] = 0; frame[1] = 1; /* block type */ int pad = size - hashlen - asnlen - 3 ; memset (&frame[2], 0xff, pad ); frame[2+pad] = 0; memcpy(&frame[3+pad], asn, asnlen); memcpy(&frame[3+pad+asnlen], hash, hashlen); if (gcry_mpi_scan(r_result, GCRYMPI_FMT_USG, frame, size, &size)) return VLC_EGENERIC; return VLC_SUCCESS; } /* * Verify an OpenPGP signature made with some RSA public key */ static int verify_signature_rsa( signature_packet_t *sign, public_key_packet_t *p_key, uint8_t *p_hash ) { int ret = VLC_EGENERIC; /* the data to be verified (a hash) */ const char *hash_sexp_s = "(data(flags raw)(value %m))"; /* the public key */ const char *key_sexp_s = "(public-key(rsa(n %m)(e %m)))"; /* the signature */ const char *sig_sexp_s = "(sig-val(rsa(s%m)))"; size_t erroff; gcry_mpi_t n, e, s, hash; n = e = s = hash = NULL; gcry_sexp_t key_sexp, hash_sexp, sig_sexp; key_sexp = hash_sexp = sig_sexp = NULL; size_t i_e_len = mpi_len( p_key->sig.rsa.e ); size_t i_n_len = mpi_len( p_key->sig.rsa.n ); if( gcry_mpi_scan( &n, GCRYMPI_FMT_USG, p_key->sig.rsa.n + 2, i_n_len, NULL ) || gcry_mpi_scan( &e, GCRYMPI_FMT_USG, p_key->sig.rsa.e + 2, i_e_len, NULL ) || gcry_sexp_build( &key_sexp, &erroff, key_sexp_s, n, e ) ) goto out; uint8_t *p_s = sign->algo_specific.rsa.s; size_t i_s_len = mpi_len( p_s ); if( gcry_mpi_scan( &s, GCRYMPI_FMT_USG, p_s + 2, i_s_len, NULL ) || gcry_sexp_build( &sig_sexp, &erroff, sig_sexp_s, s ) ) goto out; if( rsa_pkcs1_encode_sig (&hash, i_n_len, p_hash, sign->digest_algo) || gcry_sexp_build( &hash_sexp, &erroff, hash_sexp_s, hash ) ) goto out; if( gcry_pk_verify( sig_sexp, hash_sexp, key_sexp ) ) goto out; ret = VLC_SUCCESS; out: if( n ) gcry_mpi_release( n ); if( e ) gcry_mpi_release( e ); if( s ) gcry_mpi_release( s ); if( hash ) gcry_mpi_release( hash ); if( key_sexp ) gcry_sexp_release( key_sexp ); if( sig_sexp ) gcry_sexp_release( sig_sexp ); if( hash_sexp ) gcry_sexp_release( hash_sexp ); return ret; } /* * Verify an OpenPGP signature made with some DSA public key */ static int verify_signature_dsa( signature_packet_t *sign, public_key_packet_t *p_key, uint8_t *p_hash ) { int ret = VLC_EGENERIC; /* the data to be verified (a hash) */ const char *hash_sexp_s = "(data(flags raw)(value %m))"; /* the public key */ const char *key_sexp_s = "(public-key(dsa(p %m)(q %m)(g %m)(y %m)))"; /* the signature */ const char *sig_sexp_s = "(sig-val(dsa(r %m )(s %m )))"; size_t erroff; gcry_mpi_t p, q, g, y, r, s, hash; p = q = g = y = r = s = hash = NULL; gcry_sexp_t key_sexp, hash_sexp, sig_sexp; key_sexp = hash_sexp = sig_sexp = NULL; size_t i_p_len = mpi_len( p_key->sig.dsa.p ); size_t i_q_len = mpi_len( p_key->sig.dsa.q ); size_t i_g_len = mpi_len( p_key->sig.dsa.g ); size_t i_y_len = mpi_len( p_key->sig.dsa.y ); if( gcry_mpi_scan( &p, GCRYMPI_FMT_USG, p_key->sig.dsa.p + 2, i_p_len, NULL ) || gcry_mpi_scan( &q, GCRYMPI_FMT_USG, p_key->sig.dsa.q + 2, i_q_len, NULL ) || gcry_mpi_scan( &g, GCRYMPI_FMT_USG, p_key->sig.dsa.g + 2, i_g_len, NULL ) || gcry_mpi_scan( &y, GCRYMPI_FMT_USG, p_key->sig.dsa.y + 2, i_y_len, NULL ) || gcry_sexp_build( &key_sexp, &erroff, key_sexp_s, p, q, g, y ) ) goto out; uint8_t *p_r = sign->algo_specific.dsa.r; uint8_t *p_s = sign->algo_specific.dsa.s; size_t i_r_len = mpi_len( p_r ); size_t i_s_len = mpi_len( p_s ); if( gcry_mpi_scan( &r, GCRYMPI_FMT_USG, p_r + 2, i_r_len, NULL ) || gcry_mpi_scan( &s, GCRYMPI_FMT_USG, p_s + 2, i_s_len, NULL ) || gcry_sexp_build( &sig_sexp, &erroff, sig_sexp_s, r, s ) ) goto out; unsigned int i_hash_len = gcry_md_get_algo_dlen (sign->digest_algo); if (i_hash_len > i_q_len) i_hash_len = i_q_len; if( gcry_mpi_scan( &hash, GCRYMPI_FMT_USG, p_hash, i_hash_len, NULL ) || gcry_sexp_build( &hash_sexp, &erroff, hash_sexp_s, hash ) ) goto out; if( gcry_pk_verify( sig_sexp, hash_sexp, key_sexp ) ) goto out; ret = VLC_SUCCESS; out: if( p ) gcry_mpi_release( p ); if( q ) gcry_mpi_release( q ); if( g ) gcry_mpi_release( g ); if( y ) gcry_mpi_release( y ); if( r ) gcry_mpi_release( r ); if( s ) gcry_mpi_release( s ); if( hash ) gcry_mpi_release( hash ); if( key_sexp ) gcry_sexp_release( key_sexp ); if( sig_sexp ) gcry_sexp_release( sig_sexp ); if( hash_sexp ) gcry_sexp_release( hash_sexp ); return ret; } /* * Verify an OpenPGP signature made with some public key */ int verify_signature( signature_packet_t *sign, public_key_packet_t *p_key, uint8_t *p_hash ) { if (sign->public_key_algo == GCRY_PK_DSA) return verify_signature_dsa(sign, p_key, p_hash); else if (sign->public_key_algo == GCRY_PK_RSA) return verify_signature_rsa(sign, p_key, p_hash); else return VLC_EGENERIC; } /* * fill a public_key_t with public key data, including: * * public key packet * * signature packet issued by key which long id is p_sig_issuer * * user id packet */ int parse_public_key( const uint8_t *p_key_data, size_t i_key_len, public_key_t *p_key, const uint8_t *p_sig_issuer ) { const uint8_t *pos = p_key_data; const uint8_t *max_pos = pos + i_key_len; int i_status = 0; #define PUBLIC_KEY_FOUND 0x01 #define USER_ID_FOUND 0x02 #define SIGNATURE_FOUND 0X04 uint8_t *p_key_unarmored = NULL; p_key->psz_username = NULL; p_key->sig.specific.v4.hashed_data = NULL; p_key->sig.specific.v4.unhashed_data = NULL; if( !( *pos & 0x80 ) ) { /* first byte is ASCII, unarmoring */ p_key_unarmored = (uint8_t*)malloc( i_key_len ); if( !p_key_unarmored ) return VLC_ENOMEM; int i_len = pgp_unarmor( (char*)p_key_data, i_key_len, p_key_unarmored, i_key_len ); if( i_len == 0 ) goto error; pos = p_key_unarmored; max_pos = pos + i_len; } while( pos < max_pos ) { if( !(*pos & 0x80) || *pos & 0x40 ) goto error; int i_type = packet_type( *pos ); int i_header_len = packet_header_len( *pos++ ); if( pos + i_header_len > max_pos || ( i_header_len != 1 && i_header_len != 2 && i_header_len != 4 ) ) goto error; size_t i_packet_len = scalar_number( pos, i_header_len ); pos += i_header_len; if( pos + i_packet_len > max_pos ) goto error; switch( i_type ) { case PUBLIC_KEY_PACKET: i_status |= PUBLIC_KEY_FOUND; if( parse_public_key_packet( &p_key->key, pos, i_packet_len ) != VLC_SUCCESS ) goto error; break; case SIGNATURE_PACKET: /* we accept only v4 signatures here */ if( i_status & SIGNATURE_FOUND || !p_sig_issuer ) break; int i_ret = parse_signature_packet( &p_key->sig, pos, i_packet_len ); if( i_ret == VLC_SUCCESS ) { if( p_key->sig.version != 4 ) break; if( memcmp( p_key->sig.issuer_longid, p_sig_issuer, 8 ) ) { free( p_key->sig.specific.v4.hashed_data ); free( p_key->sig.specific.v4.unhashed_data ); p_key->sig.specific.v4.hashed_data = NULL; p_key->sig.specific.v4.unhashed_data = NULL; break; } i_status |= SIGNATURE_FOUND; } break; case USER_ID_PACKET: if( p_key->psz_username ) /* save only the first User ID */ break; i_status |= USER_ID_FOUND; p_key->psz_username = (uint8_t*)malloc( i_packet_len + 1); if( !p_key->psz_username ) goto error; memcpy( p_key->psz_username, pos, i_packet_len ); p_key->psz_username[i_packet_len] = '\0'; break; default: break; } pos += i_packet_len; } free( p_key_unarmored ); if( !( i_status & ( PUBLIC_KEY_FOUND | USER_ID_FOUND ) ) ) return VLC_EGENERIC; if( p_sig_issuer && !( i_status & SIGNATURE_FOUND ) ) return VLC_EGENERIC; return VLC_SUCCESS; error: if( p_key->sig.version == 4 ) { free( p_key->sig.specific.v4.hashed_data ); free( p_key->sig.specific.v4.unhashed_data ); } free( p_key->psz_username ); free( p_key_unarmored ); return VLC_EGENERIC; } /* hash a binary file */ static int hash_from_binary_file( const char *psz_file, gcry_md_hd_t hd ) { uint8_t buffer[4096]; size_t i_read; FILE *f = vlc_fopen( psz_file, "r" ); if( !f ) return -1; while( ( i_read = fread( buffer, 1, sizeof(buffer), f ) ) > 0 ) gcry_md_write( hd, buffer, i_read ); fclose( f ); return 0; } /* final part of the hash */ static uint8_t *hash_finish( gcry_md_hd_t hd, signature_packet_t *p_sig ) { if( p_sig->version == 3 ) { gcry_md_putc( hd, p_sig->type ); gcry_md_write( hd, &p_sig->specific.v3.timestamp, 4 ); } else if( p_sig->version == 4 ) { gcry_md_putc( hd, p_sig->version ); gcry_md_putc( hd, p_sig->type ); gcry_md_putc( hd, p_sig->public_key_algo ); gcry_md_putc( hd, p_sig->digest_algo ); gcry_md_write( hd, p_sig->specific.v4.hashed_data_len, 2 ); size_t i_len = scalar_number( p_sig->specific.v4.hashed_data_len, 2 ); gcry_md_write( hd, p_sig->specific.v4.hashed_data, i_len ); gcry_md_putc( hd, 0x04 ); gcry_md_putc( hd, 0xFF ); i_len += 6; /* hashed data + 6 bytes header */ gcry_md_putc( hd, (i_len >> 24) & 0xff ); gcry_md_putc( hd, (i_len >> 16) & 0xff ); gcry_md_putc( hd, (i_len >> 8) & 0xff ); gcry_md_putc( hd, (i_len) & 0xff ); } else { /* RFC 4880 only tells about versions 3 and 4 */ return NULL; } gcry_md_final( hd ); uint8_t *p_tmp = (uint8_t*) gcry_md_read( hd, p_sig->digest_algo) ; unsigned int hash_len = gcry_md_get_algo_dlen (p_sig->digest_algo); uint8_t *p_hash = malloc(hash_len); if( p_hash ) memcpy(p_hash, p_tmp, hash_len); gcry_md_close( hd ); return p_hash; } /* * return a hash of a text */ uint8_t *hash_from_text( const char *psz_string, signature_packet_t *p_sig ) { gcry_md_hd_t hd; if( gcry_md_open( &hd, p_sig->digest_algo, 0 ) ) return NULL; if( p_sig->type == TEXT_SIGNATURE ) while( *psz_string ) { size_t i_len = strcspn( psz_string, "\r\n" ); if( i_len ) { gcry_md_write( hd, psz_string, i_len ); psz_string += i_len; } gcry_md_putc( hd, '\r' ); gcry_md_putc( hd, '\n' ); if( *psz_string == '\r' ) psz_string++; if( *psz_string == '\n' ) psz_string++; } else gcry_md_write( hd, psz_string, strlen( psz_string ) ); return hash_finish( hd, p_sig ); } /* * return a hash of a file */ uint8_t *hash_from_file( const char *psz_file, signature_packet_t *p_sig ) { gcry_md_hd_t hd; if( gcry_md_open( &hd, p_sig->digest_algo, 0 ) ) return NULL; if( hash_from_binary_file( psz_file, hd ) < 0 ) { gcry_md_close( hd ); return NULL; } return hash_finish( hd, p_sig ); } /* * Generate a hash on a public key, to verify a signature made on that hash * Note that we need the signature (v4) to compute the hash */ uint8_t *hash_from_public_key( public_key_t *p_pkey ) { const uint8_t pk_algo = p_pkey->key.algo; size_t i_size; size_t i_p_len, i_g_len, i_q_len, i_y_len; size_t i_n_len, i_e_len; if( p_pkey->sig.version != 4 ) return NULL; if( p_pkey->sig.type < GENERIC_KEY_SIGNATURE || p_pkey->sig.type > POSITIVE_KEY_SIGNATURE ) return NULL; if( p_pkey->psz_username == NULL ) return NULL; gcry_error_t error = 0; gcry_md_hd_t hd; if (pk_algo == GCRY_PK_DSA) { i_p_len = mpi_len( p_pkey->key.sig.dsa.p ); i_g_len = mpi_len( p_pkey->key.sig.dsa.g ); i_q_len = mpi_len( p_pkey->key.sig.dsa.q ); i_y_len = mpi_len( p_pkey->key.sig.dsa.y ); i_size = 6 + 2*4 + i_p_len + i_g_len + i_q_len + i_y_len; } else if (pk_algo == GCRY_PK_RSA) { i_n_len = mpi_len( p_pkey->key.sig.rsa.n ); i_e_len = mpi_len( p_pkey->key.sig.rsa.e ); i_size = 6 + 2*2 + i_n_len + i_e_len; } else return NULL; error = gcry_md_open( &hd, p_pkey->sig.digest_algo, 0 ); if( error ) return NULL; gcry_md_putc( hd, 0x99 ); gcry_md_putc( hd, (i_size >> 8) & 0xff ); gcry_md_putc( hd, i_size & 0xff ); gcry_md_putc( hd, p_pkey->key.version ); gcry_md_write( hd, p_pkey->key.timestamp, 4 ); gcry_md_putc( hd, p_pkey->key.algo ); if (pk_algo == GCRY_PK_DSA) { gcry_md_write( hd, (uint8_t*)&p_pkey->key.sig.dsa.p, 2 + i_p_len ); gcry_md_write( hd, (uint8_t*)&p_pkey->key.sig.dsa.q, 2 + i_q_len ); gcry_md_write( hd, (uint8_t*)&p_pkey->key.sig.dsa.g, 2 + i_g_len ); gcry_md_write( hd, (uint8_t*)&p_pkey->key.sig.dsa.y, 2 + i_y_len ); } else if (pk_algo == GCRY_PK_RSA) { gcry_md_write( hd, (uint8_t*)&p_pkey->key.sig.rsa.n, 2 + i_n_len ); gcry_md_write( hd, (uint8_t*)&p_pkey->key.sig.rsa.e, 2 + i_e_len ); } gcry_md_putc( hd, 0xb4 ); size_t i_len = strlen((char*)p_pkey->psz_username); gcry_md_putc( hd, (i_len >> 24) & 0xff ); gcry_md_putc( hd, (i_len >> 16) & 0xff ); gcry_md_putc( hd, (i_len >> 8) & 0xff ); gcry_md_putc( hd, (i_len) & 0xff ); gcry_md_write( hd, p_pkey->psz_username, i_len ); uint8_t *p_hash = hash_finish( hd, &p_pkey->sig ); if( !p_hash || p_hash[0] != p_pkey->sig.hash_verification[0] || p_hash[1] != p_pkey->sig.hash_verification[1] ) { free(p_hash); return NULL; } return p_hash; } /* * download a public key (the last one) from videolan server, and parse it */ public_key_t *download_key( vlc_object_t *p_this, const uint8_t *p_longid, const uint8_t *p_signature_issuer ) { char *psz_url; if( asprintf( &psz_url, "http://download.videolan.org/pub/keys/%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X.asc", p_longid[0], p_longid[1], p_longid[2], p_longid[3], p_longid[4], p_longid[5], p_longid[6], p_longid[7] ) == -1 ) return NULL; stream_t *p_stream = vlc_stream_NewURL( p_this, psz_url ); free( psz_url ); if( !p_stream ) return NULL; uint64_t i_size; if( vlc_stream_GetSize( p_stream, &i_size ) || i_size > INT_MAX ) { vlc_stream_Delete( p_stream ); return NULL; } uint8_t *p_buf = (uint8_t*)malloc( i_size ); if( !p_buf ) { vlc_stream_Delete( p_stream ); return NULL; } int i_read = vlc_stream_Read( p_stream, p_buf, (int)i_size ); vlc_stream_Delete( p_stream ); if( i_read != (int)i_size ) { msg_Dbg( p_this, "Couldn't read full GPG key" ); free( p_buf ); return NULL; } public_key_t *p_pkey = (public_key_t*) malloc( sizeof( public_key_t ) ); if( !p_pkey ) { free( p_buf ); return NULL; } memcpy( p_pkey->longid, p_longid, 8 ); int i_error = parse_public_key( p_buf, i_read, p_pkey, p_signature_issuer ); free( p_buf ); if( i_error != VLC_SUCCESS ) { msg_Dbg( p_this, "Couldn't parse GPG key" ); free( p_pkey ); return NULL; } return p_pkey; } /* * Download the signature associated to a document or a binary file. * We're given the file's url, we just append ".asc" to it and download */ int download_signature( vlc_object_t *p_this, signature_packet_t *p_sig, const char *psz_url ) { char *psz_sig = (char*) malloc( strlen( psz_url ) + 4 + 1 ); /* ".asc" + \0 */ if( !psz_sig ) return VLC_ENOMEM; strcpy( psz_sig, psz_url ); strcat( psz_sig, ".asc" ); stream_t *p_stream = vlc_stream_NewURL( p_this, psz_sig ); free( psz_sig ); if( !p_stream ) return VLC_ENOMEM; uint64_t i_size; if( vlc_stream_GetSize( p_stream, &i_size ) || i_size > INT_MAX ) { vlc_stream_Delete( p_stream ); return VLC_EGENERIC; } msg_Dbg( p_this, "Downloading signature (%"PRIu64" bytes)", i_size ); uint8_t *p_buf = (uint8_t*)malloc( i_size ); if( !p_buf ) { vlc_stream_Delete( p_stream ); return VLC_ENOMEM; } int i_read = vlc_stream_Read( p_stream, p_buf, (int)i_size ); vlc_stream_Delete( p_stream ); if( i_read != (int)i_size ) { msg_Dbg( p_this, "Couldn't download full signature (only %d bytes)", i_read ); free( p_buf ); return VLC_EGENERIC; } if( (uint8_t)*p_buf < 0x80 ) /* ASCII */ { msg_Dbg( p_this, "Unarmoring signature" ); uint8_t* p_unarmored = (uint8_t*) malloc( ( i_size * 3 ) / 4 + 1 ); if( !p_unarmored ) { free( p_buf ); return VLC_EGENERIC; } int i_bytes = pgp_unarmor( (char*)p_buf, i_size, p_unarmored, i_size ); free( p_buf ); p_buf = p_unarmored; i_size = i_bytes; if( i_bytes < 2 ) { free( p_buf ); msg_Dbg( p_this, "Unarmoring failed : corrupted signature ?" ); return VLC_EGENERIC; } } if( packet_type( *p_buf ) != SIGNATURE_PACKET ) { msg_Dbg( p_this, "Not a signature: %d", *p_buf ); free( p_buf ); return VLC_EGENERIC; } size_t i_header_len = packet_header_len( *p_buf ); if( ( i_header_len != 1 && i_header_len != 2 && i_header_len != 4 ) || i_header_len + 1 > (size_t)i_size ) { free( p_buf ); msg_Dbg( p_this, "Invalid signature packet header" ); return VLC_EGENERIC; } size_t i_len = scalar_number( p_buf+1, i_header_len ); if( i_len + i_header_len + 1 != (size_t)i_size ) { free( p_buf ); msg_Dbg( p_this, "Invalid signature packet" ); return VLC_EGENERIC; } int i_ret = parse_signature_packet( p_sig, p_buf+1+i_header_len, i_len ); free( p_buf ); if( i_ret != VLC_SUCCESS ) { msg_Dbg( p_this, "Couldn't parse signature" ); return i_ret; } if( p_sig->type != BINARY_SIGNATURE && p_sig->type != TEXT_SIGNATURE ) { msg_Dbg( p_this, "Invalid signature type: %d", p_sig->type ); if( p_sig->version == 4 ) { free( p_sig->specific.v4.hashed_data ); free( p_sig->specific.v4.unhashed_data ); } return VLC_EGENERIC; } return VLC_SUCCESS; }
859177.c
/**************************************************************************** * Included Files ****************************************************************************/ #include <ecr/config.h> #include <sys/types.h> #include <stdint.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <debug.h> #include <ecr/arch.h> #include <ecr/kmalloc.h> #include <ecr/usb/usb.h> #include <ecr/usb/usbdev.h> #include <ecr/usb/usbdev_trace.h> #include <ecr/irq.h> #include <arch/board/board.h> #include "chip.h" #include "up_arch.h" #include "up_internal.h" #include "stm32_otghs.h" #if defined(CONFIG_USBDEV) && (defined(CONFIG_STM32_OTGHS)) /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ /* Configuration ***************************************************************/ #ifndef CONFIG_USBDEV_EP0_MAXSIZE # define CONFIG_USBDEV_EP0_MAXSIZE 64 #endif #ifndef CONFIG_USBDEV_SETUP_MAXDATASIZE # define CONFIG_USBDEV_SETUP_MAXDATASIZE CONFIG_USBDEV_EP0_MAXSIZE #endif #ifndef CONFIG_USBDEV_MAXPOWER # define CONFIG_USBDEV_MAXPOWER 100 /* mA */ #endif #ifndef CONFIG_DEBUG_USB_INFO # undef CONFIG_STM32_USBDEV_REGDEBUG #endif /* There is 1.25Kb of FIFO memory. The default partitions this memory * so that there is a TxFIFO allocated for each endpoint and with more * memory provided for the common RxFIFO. A more knowledge-able * configuration would not allocate any TxFIFO space to OUT endpoints. */ #ifndef CONFIG_USBDEV_RXFIFO_SIZE # define CONFIG_USBDEV_RXFIFO_SIZE 512 #endif #ifndef CONFIG_USBDEV_EP0_TXFIFO_SIZE # define CONFIG_USBDEV_EP0_TXFIFO_SIZE 192 #endif #ifndef CONFIG_USBDEV_EP1_TXFIFO_SIZE # define CONFIG_USBDEV_EP1_TXFIFO_SIZE 192 #endif #ifndef CONFIG_USBDEV_EP2_TXFIFO_SIZE # define CONFIG_USBDEV_EP2_TXFIFO_SIZE 192 #endif #ifndef CONFIG_USBDEV_EP3_TXFIFO_SIZE # define CONFIG_USBDEV_EP3_TXFIFO_SIZE 192 #endif #if (CONFIG_USBDEV_RXFIFO_SIZE + CONFIG_USBDEV_EP0_TXFIFO_SIZE + \ CONFIG_USBDEV_EP2_TXFIFO_SIZE + CONFIG_USBDEV_EP3_TXFIFO_SIZE) > 1280 # error "FIFO allocations exceed FIFO memory size" #endif /* The actual FIFO addresses that we use must be aligned to 4-byte boundaries; * FIFO sizes must be provided in units of 32-bit words. */ #define STM32_RXFIFO_BYTES ((CONFIG_USBDEV_RXFIFO_SIZE + 3) & ~3) #define STM32_RXFIFO_WORDS ((CONFIG_USBDEV_RXFIFO_SIZE + 3) >> 2) #define STM32_EP0_TXFIFO_BYTES ((CONFIG_USBDEV_EP0_TXFIFO_SIZE + 3) & ~3) #define STM32_EP0_TXFIFO_WORDS ((CONFIG_USBDEV_EP0_TXFIFO_SIZE + 3) >> 2) #if STM32_EP0_TXFIFO_WORDS < 16 || STM32_EP0_TXFIFO_WORDS > 256 # error "CONFIG_USBDEV_EP0_TXFIFO_SIZE is out of range" #endif #define STM32_EP1_TXFIFO_BYTES ((CONFIG_USBDEV_EP1_TXFIFO_SIZE + 3) & ~3) #define STM32_EP1_TXFIFO_WORDS ((CONFIG_USBDEV_EP1_TXFIFO_SIZE + 3) >> 2) #if STM32_EP1_TXFIFO_WORDS < 16 # error "CONFIG_USBDEV_EP1_TXFIFO_SIZE is out of range" #endif #define STM32_EP2_TXFIFO_BYTES ((CONFIG_USBDEV_EP2_TXFIFO_SIZE + 3) & ~3) #define STM32_EP2_TXFIFO_WORDS ((CONFIG_USBDEV_EP2_TXFIFO_SIZE + 3) >> 2) #if STM32_EP2_TXFIFO_WORDS < 16 # error "CONFIG_USBDEV_EP2_TXFIFO_SIZE is out of range" #endif #define STM32_EP3_TXFIFO_BYTES ((CONFIG_USBDEV_EP3_TXFIFO_SIZE + 3) & ~3) #define STM32_EP3_TXFIFO_WORDS ((CONFIG_USBDEV_EP3_TXFIFO_SIZE + 3) >> 2) #if STM32_EP3_TXFIFO_WORDS < 16 # error "CONFIG_USBDEV_EP3_TXFIFO_SIZE is out of range" #endif /* Debug ***********************************************************************/ /* Trace error codes */ #define STM32_TRACEERR_ALLOCFAIL 0x01 #define STM32_TRACEERR_BADCLEARFEATURE 0x02 #define STM32_TRACEERR_BADDEVGETSTATUS 0x03 #define STM32_TRACEERR_BADEPNO 0x04 #define STM32_TRACEERR_BADEPGETSTATUS 0x05 #define STM32_TRACEERR_BADGETCONFIG 0x06 #define STM32_TRACEERR_BADGETSETDESC 0x07 #define STM32_TRACEERR_BADGETSTATUS 0x08 #define STM32_TRACEERR_BADSETADDRESS 0x09 #define STM32_TRACEERR_BADSETCONFIG 0x0a #define STM32_TRACEERR_BADSETFEATURE 0x0b #define STM32_TRACEERR_BADTESTMODE 0x0c #define STM32_TRACEERR_BINDFAILED 0x0d #define STM32_TRACEERR_DISPATCHSTALL 0x0e #define STM32_TRACEERR_DRIVER 0x0f #define STM32_TRACEERR_DRIVERREGISTERED 0x10 #define STM32_TRACEERR_EP0NOSETUP 0x11 #define STM32_TRACEERR_EP0SETUPSTALLED 0x12 #define STM32_TRACEERR_EPINNULLPACKET 0x13 #define STM32_TRACEERR_EPINUNEXPECTED 0x14 #define STM32_TRACEERR_EPOUTNULLPACKET 0x15 #define STM32_TRACEERR_EPOUTUNEXPECTED 0x16 #define STM32_TRACEERR_INVALIDCTRLREQ 0x17 #define STM32_TRACEERR_INVALIDPARMS 0x18 #define STM32_TRACEERR_IRQREGISTRATION 0x19 #define STM32_TRACEERR_NOEP 0x1a #define STM32_TRACEERR_NOTCONFIGURED 0x1b #define STM32_TRACEERR_EPOUTQEMPTY 0x1c #define STM32_TRACEERR_EPINREQEMPTY 0x1d #define STM32_TRACEERR_NOOUTSETUP 0x1e #define STM32_TRACEERR_POLLTIMEOUT 0x1f /* Trace interrupt codes */ #define STM32_TRACEINTID_USB 1 /* USB Interrupt entry/exit */ #define STM32_TRACEINTID_INTPENDING 2 /* On each pass through the loop */ #define STM32_TRACEINTID_EPOUT (10 + 0) /* First level interrupt decode */ #define STM32_TRACEINTID_EPIN (10 + 1) #define STM32_TRACEINTID_MISMATCH (10 + 2) #define STM32_TRACEINTID_WAKEUP (10 + 3) #define STM32_TRACEINTID_SUSPEND (10 + 4) #define STM32_TRACEINTID_SOF (10 + 5) #define STM32_TRACEINTID_RXFIFO (10 + 6) #define STM32_TRACEINTID_DEVRESET (10 + 7) #define STM32_TRACEINTID_ENUMDNE (10 + 8) #define STM32_TRACEINTID_IISOIXFR (10 + 9) #define STM32_TRACEINTID_IISOOXFR (10 + 10) #define STM32_TRACEINTID_SRQ (10 + 11) #define STM32_TRACEINTID_OTG (10 + 12) #define STM32_TRACEINTID_EPOUT_XFRC (40 + 0) /* EPOUT second level decode */ #define STM32_TRACEINTID_EPOUT_EPDISD (40 + 1) #define STM32_TRACEINTID_EPOUT_SETUP (40 + 2) #define STM32_TRACEINTID_DISPATCH (40 + 3) #define STM32_TRACEINTID_GETSTATUS (50 + 0) /* EPOUT third level decode */ #define STM32_TRACEINTID_EPGETSTATUS (50 + 1) #define STM32_TRACEINTID_DEVGETSTATUS (50 + 2) #define STM32_TRACEINTID_IFGETSTATUS (50 + 3) #define STM32_TRACEINTID_CLEARFEATURE (50 + 4) #define STM32_TRACEINTID_SETFEATURE (50 + 5) #define STM32_TRACEINTID_SETADDRESS (50 + 6) #define STM32_TRACEINTID_GETSETDESC (50 + 7) #define STM32_TRACEINTID_GETCONFIG (50 + 8) #define STM32_TRACEINTID_SETCONFIG (50 + 9) #define STM32_TRACEINTID_GETSETIF (50 + 10) #define STM32_TRACEINTID_SYNCHFRAME (50 + 11) #define STM32_TRACEINTID_EPIN_XFRC (70 + 0) /* EPIN second level decode */ #define STM32_TRACEINTID_EPIN_TOC (70 + 1) #define STM32_TRACEINTID_EPIN_ITTXFE (70 + 2) #define STM32_TRACEINTID_EPIN_EPDISD (70 + 3) #define STM32_TRACEINTID_EPIN_TXFE (70 + 4) #define STM32_TRACEINTID_EPIN_EMPWAIT (80 + 0) /* EPIN second level decode */ #define STM32_TRACEINTID_OUTNAK (90 + 0) /* RXFLVL second level decode */ #define STM32_TRACEINTID_OUTRECVD (90 + 1) #define STM32_TRACEINTID_OUTDONE (90 + 2) #define STM32_TRACEINTID_SETUPDONE (90 + 3) #define STM32_TRACEINTID_SETUPRECVD (90 + 4) /* Endpoints ******************************************************************/ /* Number of endpoints */ #define STM32_NENDPOINTS (4) /* ep0-3 x 2 for IN and OUT */ /* Odd physical endpoint numbers are IN; even are OUT */ #define STM32_EPPHYIN2LOG(epphy) ((uint8_t)(epphy)|USB_DIR_IN) #define STM32_EPPHYOUT2LOG(epphy) ((uint8_t)(epphy)|USB_DIR_OUT) /* Endpoint 0 */ #define EP0 (0) /* The set of all enpoints available to the class implementation (1-3) */ #define STM32_EP_AVAILABLE (0x0e) /* All available endpoints */ /* Maximum packet sizes for full speed endpoints */ #define STM32_MAXPACKET (64) /* Max packet size (1-64) */ /* Delays **********************************************************************/ #define STM32_READY_DELAY 200000 #define STM32_FLUSH_DELAY 200000 /* Request queue operations ****************************************************/ #define stm32_rqempty(ep) ((ep)->head == NULL) #define stm32_rqpeek(ep) ((ep)->head) /* Standard stuff **************************************************************/ #ifndef MIN # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif #ifndef MAX # define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif /**************************************************************************** * Private Types ****************************************************************************/ /* Overall device state */ enum stm32_devstate_e { DEVSTATE_DEFAULT = 0, /* Power-up, unconfigured state. This state simply * means that the device is not yet been given an * address. * SET: At initialization, uninitialization, * reset, and whenever the device address * is set to zero * TESTED: Never */ DEVSTATE_ADDRESSED, /* Device address has been assigned, not no * configuration has yet been selected. * SET: When either a non-zero device address * is first assigned or when the device * is unconfigured (with configuration == 0) * TESTED: never */ DEVSTATE_CONFIGURED, /* Address assigned and configured: * SET: When the device has been addressed and * an non-zero configuration has been selected. * TESTED: In many places to assure that the USB device * has been properly configured by the host. */ }; /* Endpoint 0 states */ enum stm32_ep0state_e { EP0STATE_IDLE = 0, /* Idle State, leave on receiving a SETUP packet or * epsubmit: * SET: In stm32_epin() and stm32_epout() when * we revert from request processing to * SETUP processing. * TESTED: Never */ EP0STATE_SETUP_OUT, /* OUT SETUP packet received. Waiting for the DATA * OUT phase of SETUP Packet to complete before * processing a SETUP command (without a USB request): * SET: Set in stm32_rxinterrupt() when SETUP OUT * packet is received. * TESTED: In stm32_ep0out_receive() */ EP0STATE_SETUP_READY, /* IN SETUP packet received -OR- OUT SETUP packet and * accompanying data have been received. Processing * of SETUP command will happen soon. * SET: (1) stm32_ep0out_receive() when the OUT * SETUP data phase completes, or (2) * stm32_rxinterrupt() when an IN SETUP is * packet received. * TESTED: Tested in stm32_epout_interrupt() when * SETUP phase is done to see if the SETUP * command is ready to be processed. Also * tested in stm32_ep0out_setup() just to * double-check that we have a SETUP request * and any accompanying data. */ EP0STATE_SETUP_PROCESS, /* SETUP Packet is being processed by stm32_ep0out_setup(): * SET: When SETUP packet received in EP0 OUT * TESTED: Never */ EP0STATE_SETUPRESPONSE, /* Short SETUP response write (without a USB request): * SET: When SETUP response is sent by * stm32_ep0in_setupresponse() * TESTED: Never */ EP0STATE_DATA_IN, /* Waiting for data out stage (with a USB request): * SET: In stm32_epin_request() when a write * request is processed on EP0. * TESTED: In stm32_epin() to see if we should * revert to SETUP processing. */ EP0STATE_DATA_OUT /* Waiting for data in phase to complete ( with a * USB request) * SET: In stm32_epout_request() when a read * request is processed on EP0. * TESTED: In stm32_epout() to see if we should * revert to SETUP processing */ }; /* Parsed control request */ struct stm32_ctrlreq_s { uint8_t type; uint8_t req; uint16_t value; uint16_t index; uint16_t len; }; /* A container for a request so that the request may be retained in a list */ struct stm32_req_s { struct usbdev_req_s req; /* Standard USB request */ struct stm32_req_s *flink; /* Supports a singly linked list */ }; /* This is the internal representation of an endpoint */ struct stm32_ep_s { /* Common endpoint fields. This must be the first thing defined in the * structure so that it is possible to simply cast from struct usbdev_ep_s * to struct stm32_ep_s. */ struct usbdev_ep_s ep; /* Standard endpoint structure */ /* STM32-specific fields */ struct stm32_usbdev_s *dev; /* Reference to private driver data */ struct stm32_req_s *head; /* Request list for this endpoint */ struct stm32_req_s *tail; uint8_t epphy; /* Physical EP address */ uint8_t eptype:2; /* Endpoint type */ uint8_t active:1; /* 1: A request is being processed */ uint8_t stalled:1; /* 1: Endpoint is stalled */ uint8_t isin:1; /* 1: IN Endpoint */ uint8_t odd:1; /* 1: Odd frame */ uint8_t zlp:1; /* 1: Transmit a zero-length-packet (IN EPs only) */ }; /* This structure retains the state of the USB device controller */ struct stm32_usbdev_s { /* Common device fields. This must be the first thing defined in the * structure so that it is possible to simply cast from struct usbdev_s * to struct stm32_usbdev_s. */ struct usbdev_s usbdev; /* The bound device class driver */ struct usbdevclass_driver_s *driver; /* STM32-specific fields */ uint8_t stalled:1; /* 1: Protocol stalled */ uint8_t selfpowered:1; /* 1: Device is self powered */ uint8_t addressed:1; /* 1: Peripheral address has been set */ uint8_t configured:1; /* 1: Class driver has been configured */ uint8_t wakeup:1; /* 1: Device remote wake-up */ uint8_t dotest:1; /* 1: Test mode selected */ uint8_t devstate:4; /* See enum stm32_devstate_e */ uint8_t ep0state:4; /* See enum stm32_ep0state_e */ uint8_t testmode:4; /* Selected test mode */ uint8_t epavail[2]; /* Bitset of available OUT/IN endpoints */ /* E0 SETUP data buffering. * * ctrlreq: * The 8-byte SETUP request is received on the EP0 OUT endpoint and is * saved. * * ep0data * For OUT SETUP requests, the SETUP data phase must also complete before * the SETUP command can be processed. The pack receipt logic will save * the accompanying EP0 IN data in ep0data[] before the SETUP command is * processed. * * For IN SETUP requests, the DATA phase will occur AFTER the SETUP * control request is processed. In that case, ep0data[] may be used as * the response buffer. * * ep0datlen * Length of OUT DATA received in ep0data[] (Not used with OUT data) */ struct usb_ctrlreq_s ctrlreq; uint8_t ep0data[CONFIG_USBDEV_SETUP_MAXDATASIZE]; uint16_t ep0datlen; /* The endpoint lists */ struct stm32_ep_s epin[STM32_NENDPOINTS]; struct stm32_ep_s epout[STM32_NENDPOINTS]; }; /**************************************************************************** * Private Function Prototypes ****************************************************************************/ /* Register operations ********************************************************/ #ifdef CONFIG_STM32_USBDEV_REGDEBUG static uint32_t stm32_getreg(uint32_t addr); static void stm32_putreg(uint32_t val, uint32_t addr); #else # define stm32_getreg(addr) getreg32(addr) # define stm32_putreg(val,addr) putreg32(val,addr) #endif /* Request queue operations ****************************************************/ static FAR struct stm32_req_s *stm32_req_remfirst(FAR struct stm32_ep_s *privep); static bool stm32_req_addlast(FAR struct stm32_ep_s *privep, FAR struct stm32_req_s *req); /* Low level data transfers and request operations *****************************/ /* Special endpoint 0 data transfer logic */ static void stm32_ep0in_setupresponse(FAR struct stm32_usbdev_s *priv, FAR uint8_t *data, uint32_t nbytes); static inline void stm32_ep0in_transmitzlp(FAR struct stm32_usbdev_s *priv); static void stm32_ep0in_activate(void); static void stm32_ep0out_ctrlsetup(FAR struct stm32_usbdev_s *priv); /* IN request and TxFIFO handling */ static void stm32_txfifo_write(FAR struct stm32_ep_s *privep, FAR uint8_t *buf, int nbytes); static void stm32_epin_transfer(FAR struct stm32_ep_s *privep, FAR uint8_t *buf, int nbytes); static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, FAR struct stm32_ep_s *privep); /* OUT request and RxFIFO handling */ static void stm32_rxfifo_read(FAR struct stm32_ep_s *privep, FAR uint8_t *dest, uint16_t len); static void stm32_rxfifo_discard(FAR struct stm32_ep_s *privep, int len); static void stm32_epout_complete(FAR struct stm32_usbdev_s *priv, FAR struct stm32_ep_s *privep); static inline void stm32_ep0out_receive(FAR struct stm32_ep_s *privep, int bcnt); static inline void stm32_epout_receive(FAR struct stm32_ep_s *privep, int bcnt); static void stm32_epout_request(FAR struct stm32_usbdev_s *priv, FAR struct stm32_ep_s *privep); /* General request handling */ static void stm32_ep_flush(FAR struct stm32_ep_s *privep); static void stm32_req_complete(FAR struct stm32_ep_s *privep, int16_t result); static void stm32_req_cancel(FAR struct stm32_ep_s *privep, int16_t status); /* Interrupt handling **********************************************************/ static struct stm32_ep_s *stm32_ep_findbyaddr(struct stm32_usbdev_s *priv, uint16_t eplog); static int stm32_req_dispatch(FAR struct stm32_usbdev_s *priv, FAR const struct usb_ctrlreq_s *ctrl); static void stm32_usbreset(FAR struct stm32_usbdev_s *priv); /* Second level OUT endpoint interrupt processing */ static inline void stm32_ep0out_testmode(FAR struct stm32_usbdev_s *priv, uint16_t index); static inline void stm32_ep0out_stdrequest(struct stm32_usbdev_s *priv, FAR struct stm32_ctrlreq_s *ctrlreq); static inline void stm32_ep0out_setup(struct stm32_usbdev_s *priv); static inline void stm32_epout(FAR struct stm32_usbdev_s *priv, uint8_t epno); static inline void stm32_epout_interrupt(FAR struct stm32_usbdev_s *priv); /* Second level IN endpoint interrupt processing */ static inline void stm32_epin_runtestmode(FAR struct stm32_usbdev_s *priv); static inline void stm32_epin(FAR struct stm32_usbdev_s *priv, uint8_t epno); static inline void stm32_epin_txfifoempty(FAR struct stm32_usbdev_s *priv, int epno); static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv); /* Other second level interrupt processing */ static inline void stm32_resumeinterrupt(FAR struct stm32_usbdev_s *priv); static inline void stm32_suspendinterrupt(FAR struct stm32_usbdev_s *priv); static inline void stm32_rxinterrupt(FAR struct stm32_usbdev_s *priv); static inline void stm32_enuminterrupt(FAR struct stm32_usbdev_s *priv); #ifdef CONFIG_USBDEV_ISOCHRONOUS static inline void stm32_isocininterrupt(FAR struct stm32_usbdev_s *priv); static inline void stm32_isocoutinterrupt(FAR struct stm32_usbdev_s *priv); #endif #ifdef CONFIG_USBDEV_VBUSSENSING static inline void stm32_sessioninterrupt(FAR struct stm32_usbdev_s *priv); static inline void stm32_otginterrupt(FAR struct stm32_usbdev_s *priv); #endif /* First level interrupt processing */ static int stm32_usbinterrupt(int irq, FAR void *context, FAR void *arg); /* Endpoint operations *********************************************************/ /* Global OUT NAK controls */ static void stm32_enablegonak(FAR struct stm32_ep_s *privep); static void stm32_disablegonak(FAR struct stm32_ep_s *privep); /* Endpoint configuration */ static int stm32_epout_configure(FAR struct stm32_ep_s *privep, uint8_t eptype, uint16_t maxpacket); static int stm32_epin_configure(FAR struct stm32_ep_s *privep, uint8_t eptype, uint16_t maxpacket); static int stm32_ep_configure(FAR struct usbdev_ep_s *ep, FAR const struct usb_epdesc_s *desc, bool last); static void stm32_ep0_configure(FAR struct stm32_usbdev_s *priv); /* Endpoint disable */ static void stm32_epout_disable(FAR struct stm32_ep_s *privep); static void stm32_epin_disable(FAR struct stm32_ep_s *privep); static int stm32_ep_disable(FAR struct usbdev_ep_s *ep); /* Endpoint request management */ static FAR struct usbdev_req_s *stm32_ep_allocreq(FAR struct usbdev_ep_s *ep); static void stm32_ep_freereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *); /* Endpoint buffer management */ #ifdef CONFIG_USBDEV_DMA static void *stm32_ep_allocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes); static void stm32_ep_freebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf); #endif /* Endpoint request submission */ static int stm32_ep_submit(FAR struct usbdev_ep_s *ep, struct usbdev_req_s *req); /* Endpoint request cancellation */ static int stm32_ep_cancel(FAR struct usbdev_ep_s *ep, struct usbdev_req_s *req); /* Stall handling */ static int stm32_epout_setstall(FAR struct stm32_ep_s *privep); static int stm32_epin_setstall(FAR struct stm32_ep_s *privep); static int stm32_ep_setstall(FAR struct stm32_ep_s *privep); static int stm32_ep_clrstall(FAR struct stm32_ep_s *privep); static int stm32_ep_stall(FAR struct usbdev_ep_s *ep, bool resume); static void stm32_ep0_stall(FAR struct stm32_usbdev_s *priv); /* Endpoint allocation */ static FAR struct usbdev_ep_s *stm32_ep_alloc(FAR struct usbdev_s *dev, uint8_t epno, bool in, uint8_t eptype); static void stm32_ep_free(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep); /* USB device controller operations ********************************************/ static int stm32_getframe(struct usbdev_s *dev); static int stm32_wakeup(struct usbdev_s *dev); static int stm32_selfpowered(struct usbdev_s *dev, bool selfpowered); static int stm32_pullup(struct usbdev_s *dev, bool enable); static void stm32_setaddress(struct stm32_usbdev_s *priv, uint16_t address); static int stm32_txfifo_flush(uint32_t txfnum); static int stm32_rxfifo_flush(void); /* Initialization **************************************************************/ static void stm32_swinitialize(FAR struct stm32_usbdev_s *priv); static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv); /**************************************************************************** * Private Data ****************************************************************************/ /* Since there is only a single USB interface, all status information can be * be simply retained in a single global instance. */ static struct stm32_usbdev_s g_otghsdev; static const struct usbdev_epops_s g_epops = { .configure = stm32_ep_configure, .disable = stm32_ep_disable, .allocreq = stm32_ep_allocreq, .freereq = stm32_ep_freereq, #ifdef CONFIG_USBDEV_DMA .allocbuffer = stm32_ep_allocbuffer, .freebuffer = stm32_ep_freebuffer, #endif .submit = stm32_ep_submit, .cancel = stm32_ep_cancel, .stall = stm32_ep_stall, }; static const struct usbdev_ops_s g_devops = { .allocep = stm32_ep_alloc, .freeep = stm32_ep_free, .getframe = stm32_getframe, .wakeup = stm32_wakeup, .selfpowered = stm32_selfpowered, .pullup = stm32_pullup, }; /* Device error strings that may be enabled for more descriptive USB trace * output. */ #ifdef CONFIG_USBDEV_TRACE_STRINGS const struct trace_msg_t g_usb_trace_strings_deverror[] = { TRACE_STR(STM32_TRACEERR_ALLOCFAIL ), TRACE_STR(STM32_TRACEERR_BADCLEARFEATURE ), TRACE_STR(STM32_TRACEERR_BADDEVGETSTATUS ), TRACE_STR(STM32_TRACEERR_BADEPNO ), TRACE_STR(STM32_TRACEERR_BADEPGETSTATUS ), TRACE_STR(STM32_TRACEERR_BADGETCONFIG ), TRACE_STR(STM32_TRACEERR_BADGETSETDESC ), TRACE_STR(STM32_TRACEERR_BADGETSTATUS ), TRACE_STR(STM32_TRACEERR_BADSETADDRESS ), TRACE_STR(STM32_TRACEERR_BADSETCONFIG ), TRACE_STR(STM32_TRACEERR_BADSETFEATURE ), TRACE_STR(STM32_TRACEERR_BADTESTMODE ), TRACE_STR(STM32_TRACEERR_BINDFAILED ), TRACE_STR(STM32_TRACEERR_DISPATCHSTALL ), TRACE_STR(STM32_TRACEERR_DRIVER ), TRACE_STR(STM32_TRACEERR_DRIVERREGISTERED), TRACE_STR(STM32_TRACEERR_EP0NOSETUP ), TRACE_STR(STM32_TRACEERR_EP0SETUPSTALLED ), TRACE_STR(STM32_TRACEERR_EPINNULLPACKET ), TRACE_STR(STM32_TRACEERR_EPINUNEXPECTED ), TRACE_STR(STM32_TRACEERR_EPOUTNULLPACKET ), TRACE_STR(STM32_TRACEERR_EPOUTUNEXPECTED ), TRACE_STR(STM32_TRACEERR_INVALIDCTRLREQ ), TRACE_STR(STM32_TRACEERR_INVALIDPARMS ), TRACE_STR(STM32_TRACEERR_IRQREGISTRATION ), TRACE_STR(STM32_TRACEERR_NOEP ), TRACE_STR(STM32_TRACEERR_NOTCONFIGURED ), TRACE_STR(STM32_TRACEERR_EPOUTQEMPTY ), TRACE_STR(STM32_TRACEERR_EPINREQEMPTY ), TRACE_STR(STM32_TRACEERR_NOOUTSETUP ), TRACE_STR(STM32_TRACEERR_POLLTIMEOUT ), TRACE_STR_END }; #endif /* Interrupt event strings that may be enabled for more descriptive USB trace * output. */ #ifdef CONFIG_USBDEV_TRACE_STRINGS const struct trace_msg_t g_usb_trace_strings_intdecode[] = { TRACE_STR(STM32_TRACEINTID_USB ), TRACE_STR(STM32_TRACEINTID_INTPENDING ), TRACE_STR(STM32_TRACEINTID_EPOUT ), TRACE_STR(STM32_TRACEINTID_EPIN ), TRACE_STR(STM32_TRACEINTID_MISMATCH ), TRACE_STR(STM32_TRACEINTID_WAKEUP ), TRACE_STR(STM32_TRACEINTID_SUSPEND ), TRACE_STR(STM32_TRACEINTID_SOF ), TRACE_STR(STM32_TRACEINTID_RXFIFO ), TRACE_STR(STM32_TRACEINTID_DEVRESET ), TRACE_STR(STM32_TRACEINTID_ENUMDNE ), TRACE_STR(STM32_TRACEINTID_IISOIXFR ), TRACE_STR(STM32_TRACEINTID_IISOOXFR ), TRACE_STR(STM32_TRACEINTID_SRQ ), TRACE_STR(STM32_TRACEINTID_OTG ), TRACE_STR(STM32_TRACEINTID_EPOUT_XFRC ), TRACE_STR(STM32_TRACEINTID_EPOUT_EPDISD), TRACE_STR(STM32_TRACEINTID_EPOUT_SETUP ), TRACE_STR(STM32_TRACEINTID_DISPATCH ), TRACE_STR(STM32_TRACEINTID_GETSTATUS ), TRACE_STR(STM32_TRACEINTID_EPGETSTATUS ), TRACE_STR(STM32_TRACEINTID_DEVGETSTATUS), TRACE_STR(STM32_TRACEINTID_IFGETSTATUS ), TRACE_STR(STM32_TRACEINTID_CLEARFEATURE), TRACE_STR(STM32_TRACEINTID_SETFEATURE ), TRACE_STR(STM32_TRACEINTID_SETADDRESS ), TRACE_STR(STM32_TRACEINTID_GETSETDESC ), TRACE_STR(STM32_TRACEINTID_GETCONFIG ), TRACE_STR(STM32_TRACEINTID_SETCONFIG ), TRACE_STR(STM32_TRACEINTID_GETSETIF ), TRACE_STR(STM32_TRACEINTID_SYNCHFRAME ), TRACE_STR(STM32_TRACEINTID_EPIN_XFRC ), TRACE_STR(STM32_TRACEINTID_EPIN_TOC ), TRACE_STR(STM32_TRACEINTID_EPIN_ITTXFE ), TRACE_STR(STM32_TRACEINTID_EPIN_EPDISD ), TRACE_STR(STM32_TRACEINTID_EPIN_TXFE ), TRACE_STR(STM32_TRACEINTID_EPIN_EMPWAIT), TRACE_STR(STM32_TRACEINTID_OUTNAK ), TRACE_STR(STM32_TRACEINTID_OUTRECVD ), TRACE_STR(STM32_TRACEINTID_OUTDONE ), TRACE_STR(STM32_TRACEINTID_SETUPDONE ), TRACE_STR(STM32_TRACEINTID_SETUPRECVD ), TRACE_STR_END }; #endif /**************************************************************************** * Public Data ****************************************************************************/ /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** * Name: stm32_getreg * * Description: * Get the contents of an STM32 register * ****************************************************************************/ #ifdef CONFIG_STM32_USBDEV_REGDEBUG static uint32_t stm32_getreg(uint32_t addr) { static uint32_t prevaddr = 0; static uint32_t preval = 0; static uint32_t count = 0; /* Read the value from the register */ uint32_t val = getreg32(addr); /* Is this the same value that we read from the same register last time? Are * we polling the register? If so, suppress some of the output. */ if (addr == prevaddr && val == preval) { if (count == 0xffffffff || ++count > 3) { if (count == 4) { uinfo("...\n"); } return val; } } /* No this is a new address or value */ else { /* Did we print "..." for the previous value? */ if (count > 3) { /* Yes.. then show how many times the value repeated */ uinfo("[repeats %d more times]\n", count-3); } /* Save the new address, value, and count */ prevaddr = addr; preval = val; count = 1; } /* Show the register value read */ uinfo("%08x->%08x\n", addr, val); return val; } #endif /**************************************************************************** * Name: stm32_putreg * * Description: * Set the contents of an STM32 register to a value * ****************************************************************************/ #ifdef CONFIG_STM32_USBDEV_REGDEBUG static void stm32_putreg(uint32_t val, uint32_t addr) { /* Show the register value being written */ uinfo("%08x<-%08x\n", addr, val); /* Write the value */ putreg32(val, addr); } #endif /**************************************************************************** * Name: stm32_req_remfirst * * Description: * Remove a request from the head of an endpoint request queue * ****************************************************************************/ static FAR struct stm32_req_s *stm32_req_remfirst(FAR struct stm32_ep_s *privep) { FAR struct stm32_req_s *ret = privep->head; if (ret) { privep->head = ret->flink; if (!privep->head) { privep->tail = NULL; } ret->flink = NULL; } return ret; } /**************************************************************************** * Name: stm32_req_addlast * * Description: * Add a request to the end of an endpoint request queue * ****************************************************************************/ static bool stm32_req_addlast(FAR struct stm32_ep_s *privep, FAR struct stm32_req_s *req) { bool is_empty = !privep->head; req->flink = NULL; if (is_empty) { privep->head = req; privep->tail = req; } else { privep->tail->flink = req; privep->tail = req; } return is_empty; } /**************************************************************************** * Name: stm32_ep0in_setupresponse * * Description: * Schedule a short transfer on Endpoint 0 (IN or OUT) * ****************************************************************************/ static void stm32_ep0in_setupresponse(FAR struct stm32_usbdev_s *priv, FAR uint8_t *buf, uint32_t nbytes) { stm32_epin_transfer(&priv->epin[EP0], buf, nbytes); priv->ep0state = EP0STATE_SETUPRESPONSE; stm32_ep0out_ctrlsetup(priv); } /**************************************************************************** * Name: stm32_ep0in_transmitzlp * * Description: * Send a zero length packet (ZLP) on endpoint 0 IN * ****************************************************************************/ static inline void stm32_ep0in_transmitzlp(FAR struct stm32_usbdev_s *priv) { stm32_ep0in_setupresponse(priv, NULL, 0); } /**************************************************************************** * Name: stm32_ep0in_activate * * Description: * Activate the endpoint 0 IN endpoint. * ****************************************************************************/ static void stm32_ep0in_activate(void) { uint32_t regval; /* Set the max packet size of the IN EP. */ regval = stm32_getreg(STM32_OTGHS_DIEPCTL0); regval &= ~OTGHS_DIEPCTL0_MPSIZ_MASK; #if CONFIG_USBDEV_EP0_MAXSIZE == 8 regval |= OTGHS_DIEPCTL0_MPSIZ_8; #elif CONFIG_USBDEV_EP0_MAXSIZE == 16 regval |= OTGHS_DIEPCTL0_MPSIZ_16; #elif CONFIG_USBDEV_EP0_MAXSIZE == 32 regval |= OTGHS_DIEPCTL0_MPSIZ_32; #elif CONFIG_USBDEV_EP0_MAXSIZE == 64 regval |= OTGHS_DIEPCTL0_MPSIZ_64; #else # error "Unsupported value of CONFIG_USBDEV_EP0_MAXSIZE" #endif stm32_putreg(regval, STM32_OTGHS_DIEPCTL0); /* Clear global IN NAK */ regval = stm32_getreg(STM32_OTGHS_DCTL); regval |= OTGHS_DCTL_CGINAK; stm32_putreg(regval, STM32_OTGHS_DCTL); } /**************************************************************************** * Name: stm32_ep0out_ctrlsetup * * Description: * Setup to receive a SETUP packet. * ****************************************************************************/ static void stm32_ep0out_ctrlsetup(FAR struct stm32_usbdev_s *priv) { uint32_t regval; /* Setup the hardware to perform the SETUP transfer */ regval = (USB_SIZEOF_CTRLREQ * 3 << OTGHS_DOEPTSIZ0_XFRSIZ_SHIFT) | (OTGHS_DOEPTSIZ0_PKTCNT) | (3 << OTGHS_DOEPTSIZ0_STUPCNT_SHIFT); stm32_putreg(regval, STM32_OTGHS_DOEPTSIZ0); /* Then clear NAKing and enable the transfer */ regval = stm32_getreg(STM32_OTGHS_DOEPCTL0); regval |= (OTGHS_DOEPCTL0_CNAK | OTGHS_DOEPCTL0_EPENA); stm32_putreg(regval, STM32_OTGHS_DOEPCTL0); } /**************************************************************************** * Name: stm32_txfifo_write * * Description: * Send data to the endpoint's TxFIFO. * ****************************************************************************/ static void stm32_txfifo_write(FAR struct stm32_ep_s *privep, FAR uint8_t *buf, int nbytes) { uint32_t regaddr; uint32_t regval; int nwords; int i; /* Convert the number of bytes to words */ nwords = (nbytes + 3) >> 2; /* Get the TxFIFO for this endpoint (same as the endpoint number) */ regaddr = STM32_OTGHS_DFIFO_DEP(privep->epphy); /* Then transfer each word to the TxFIFO */ for (i = 0; i < nwords; i++) { /* Read four bytes from the source buffer (to avoid unaligned accesses) * and pack these into one 32-bit word (little endian). */ regval = (uint32_t)*buf++; regval |= ((uint32_t)*buf++) << 8; regval |= ((uint32_t)*buf++) << 16; regval |= ((uint32_t)*buf++) << 24; /* Then write the packet data to the TxFIFO */ stm32_putreg(regval, regaddr); } } /**************************************************************************** * Name: stm32_epin_transfer * * Description: * Start the Tx data transfer * ****************************************************************************/ static void stm32_epin_transfer(FAR struct stm32_ep_s *privep, FAR uint8_t *buf, int nbytes) { uint32_t pktcnt; uint32_t regval; /* Read the DIEPSIZx register */ regval = stm32_getreg(STM32_OTGHS_DIEPTSIZ(privep->epphy)); /* Clear the XFRSIZ, PKTCNT, and MCNT field of the DIEPSIZx register */ regval &= ~(OTGHS_DIEPTSIZ_XFRSIZ_MASK | OTGHS_DIEPTSIZ_PKTCNT_MASK | OTGHS_DIEPTSIZ_MCNT_MASK); /* Are we sending a zero length packet (ZLP) */ if (nbytes == 0) { /* Yes.. leave the transfer size at zero and set the packet count to 1 */ pktcnt = 1; } else { /* No.. Program the transfer size and packet count . First calculate: * * xfrsize = The total number of bytes to be sent. * pktcnt = the number of packets (of maxpacket bytes) required to * perform the transfer. */ pktcnt = ((uint32_t)nbytes + (privep->ep.maxpacket - 1)) / privep->ep.maxpacket; } /* Set the XFRSIZ and PKTCNT */ regval |= (pktcnt << OTGHS_DIEPTSIZ_PKTCNT_SHIFT); regval |= ((uint32_t)nbytes << OTGHS_DIEPTSIZ_XFRSIZ_SHIFT); /* If this is an isochronous endpoint, then set the multi-count field to * the PKTCNT as well. */ if (privep->eptype == USB_EP_ATTR_XFER_ISOC) { regval |= (pktcnt << OTGHS_DIEPTSIZ_MCNT_SHIFT); } /* Save DIEPSIZx register value */ stm32_putreg(regval, STM32_OTGHS_DIEPTSIZ(privep->epphy)); /* Read the DIEPCTLx register */ regval = stm32_getreg(STM32_OTGHS_DIEPCTL(privep->epphy)); /* If this is an isochronous endpoint, then set the even/odd frame bit * the DIEPCTLx register. */ if (privep->eptype == USB_EP_ATTR_XFER_ISOC) { /* Check bit 0 of the frame number of the received SOF and set the * even/odd frame to match. */ uint32_t status = stm32_getreg(STM32_OTGHS_DSTS); if ((status & OTGHS_DSTS_SOFFN0) == OTGHS_DSTS_SOFFN_EVEN) { regval |= OTGHS_DIEPCTL_SEVNFRM; } else { regval |= OTGHS_DIEPCTL_SODDFRM; } } /* EP enable, IN data in FIFO */ regval &= ~OTGHS_DIEPCTL_EPDIS; regval |= (OTGHS_DIEPCTL_CNAK | OTGHS_DIEPCTL_EPENA); stm32_putreg(regval, STM32_OTGHS_DIEPCTL(privep->epphy)); /* Transfer the data to the TxFIFO. At this point, the caller has already * assured that there is sufficient space in the TxFIFO to hold the transfer * we can just blindly continue. */ stm32_txfifo_write(privep, buf, nbytes); } /**************************************************************************** * Name: stm32_epin_request * * Description: * Begin or continue write request processing. * ****************************************************************************/ static void stm32_epin_request(FAR struct stm32_usbdev_s *priv, FAR struct stm32_ep_s *privep) { struct stm32_req_s *privreq; uint32_t regaddr; uint32_t regval; uint8_t *buf; int nbytes; int nwords; int bytesleft; /* We get here in one of four possible ways. From three interrupting * events: * * 1. From stm32_epin as part of the transfer complete interrupt processing * This interrupt indicates that the last transfer has completed. * 2. As part of the ITTXFE interrupt processing. That interrupt indicates * that an IN token was received when the associated TxFIFO was empty. * 3. From stm32_epin_txfifoempty as part of the TXFE interrupt processing. * The TXFE interrupt is only enabled when the TxFIFO is full and the * software must wait for space to become available in the TxFIFO. * * And this function may be called immediately when the write request is * queue to start up the next transaction. * * 4. From stm32_ep_submit when a new write request is received WHILE the * endpoint is not active (privep->active == false). */ /* Check the request from the head of the endpoint request queue */ privreq = stm32_rqpeek(privep); if (!privreq) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPINREQEMPTY), privep->epphy); /* There is no TX transfer in progress and no new pending TX * requests to send. To stop transmitting any data on a particular * IN endpoint, the application must set the IN NAK bit. To set this * bit, the following field must be programmed. */ regaddr = STM32_OTGHS_DIEPCTL(privep->epphy); regval = stm32_getreg(regaddr); regval |= OTGHS_DIEPCTL_SNAK; stm32_putreg(regval, regaddr); /* The endpoint is no longer active */ privep->active = false; return; } uinfo("EP%d req=%p: len=%d xfrd=%d zlp=%d\n", privep->epphy, privreq, privreq->req.len, privreq->req.xfrd, privep->zlp); /* Check for a special case: If we are just starting a request (xfrd==0) and * the class driver is trying to send a zero-length packet (len==0). Then set * the ZLP flag so that the packet will be sent. */ if (privreq->req.len == 0) { /* The ZLP flag is set TRUE whenever we want to force the driver to * send a zero-length-packet on the next pass through the loop (below). * The flag is cleared whenever a packet is sent in the loop below. */ privep->zlp = true; } /* Add one more packet to the TxFIFO. We will wait for the transfer * complete event before we add the next packet (or part of a packet * to the TxFIFO). * * The documentation says that we can can multiple packets to the TxFIFO, * but it seems that we need to get the transfer complete event before * we can add the next (or maybe I have got something wrong?) */ #if 0 while (privreq->req.xfrd < privreq->req.len || privep->zlp) #else if (privreq->req.xfrd < privreq->req.len || privep->zlp) #endif { /* Get the number of bytes left to be sent in the request */ bytesleft = privreq->req.len - privreq->req.xfrd; nbytes = bytesleft; /* Assume no zero-length-packet on the next pass through this loop */ privep->zlp = false; /* Limit the size of the transfer to one full packet and handle * zero-length packets (ZLPs). */ if (nbytes > 0) { /* Either send the maxpacketsize or all of the remaining data in * the request. */ if (nbytes >= privep->ep.maxpacket) { nbytes = privep->ep.maxpacket; /* Handle the case where this packet is exactly the * maxpacketsize. Do we need to send a zero-length packet * in this case? */ if (bytesleft == privep->ep.maxpacket && (privreq->req.flags & USBDEV_REQFLAGS_NULLPKT) != 0) { /* The ZLP flag is set TRUE whenever we want to force * the driver to send a zero-length-packet on the next * pass through this loop. The flag is cleared (above) * whenever we are committed to sending any packet and * set here when we want to force one more pass through * the loop. */ privep->zlp = true; } } } /* Get the transfer size in 32-bit words */ nwords = (nbytes + 3) >> 2; /* Get the number of 32-bit words available in the TxFIFO. The * DXTHSTS indicates the amount of free space available in the * endpoint TxFIFO. Values are in terms of 32-bit words: * * 0: Endpoint TxFIFO is full * 1: 1 word available * 2: 2 words available * n: n words available */ regaddr = STM32_OTGHS_DTXFSTS(privep->epphy); /* Check for space in the TxFIFO. If space in the TxFIFO is not * available, then set up an interrupt to resume the transfer when * the TxFIFO is empty. */ regval = stm32_getreg(regaddr); if ((int)(regval & OTGHS_DTXFSTS_MASK) < nwords) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_EMPWAIT), (uint16_t)regval); /* There is insufficient space in the TxFIFO. Wait for a TxFIFO * empty interrupt and try again. */ uint32_t empmsk = stm32_getreg(STM32_OTGHS_DIEPEMPMSK); empmsk |= OTGHS_DIEPEMPMSK(privep->epphy); stm32_putreg(empmsk, STM32_OTGHS_DIEPEMPMSK); /* Terminate the transfer. We will try again when the TxFIFO empty * interrupt is received. */ return; } /* Transfer data to the TxFIFO */ buf = privreq->req.buf + privreq->req.xfrd; stm32_epin_transfer(privep, buf, nbytes); /* If it was not before, the OUT endpoint is now actively transferring * data. */ privep->active = true; /* EP0 is a special case */ if (privep->epphy == EP0) { priv->ep0state = EP0STATE_DATA_IN; } /* Update for the next time through the loop */ privreq->req.xfrd += nbytes; } /* Note that the ZLP, if any, must be sent as a separate transfer. The need * for a ZLP is indicated by privep->zlp. If all of the bytes were sent * (including any final null packet) then we are finished with the transfer */ if (privreq->req.xfrd >= privreq->req.len && !privep->zlp) { usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd); /* We are finished with the request (although the transfer has not * yet completed). */ stm32_req_complete(privep, OK); } } /**************************************************************************** * Name: stm32_rxfifo_read * * Description: * Read packet from the RxFIFO into a read request. * ****************************************************************************/ static void stm32_rxfifo_read(FAR struct stm32_ep_s *privep, FAR uint8_t *dest, uint16_t len) { uint32_t regaddr; int i; /* Get the address of the RxFIFO. Note: there is only one RxFIFO so * we might as well use the address associated with EP0. */ regaddr = STM32_OTGHS_DFIFO_DEP(EP0); /* Read 32-bits and write 4 x 8-bits at time (to avoid unaligned accesses) */ for (i = 0; i < len; i += 4) { union { uint32_t w; uint8_t b[4]; } data; /* Read 1 x 32-bits of EP0 packet data */ data.w = stm32_getreg(regaddr); /* Write 4 x 8-bits of EP0 packet data */ *dest++ = data.b[0]; *dest++ = data.b[1]; *dest++ = data.b[2]; *dest++ = data.b[3]; } } /**************************************************************************** * Name: stm32_rxfifo_discard * * Description: * Discard packet data from the RxFIFO. * ****************************************************************************/ static void stm32_rxfifo_discard(FAR struct stm32_ep_s *privep, int len) { if (len > 0) { uint32_t regaddr; int i; /* Get the address of the RxFIFO Note: there is only one RxFIFO so * we might as well use the address associated with EP0. */ regaddr = STM32_OTGHS_DFIFO_DEP(EP0); /* Read 32-bits at time */ for (i = 0; i < len; i += 4) { volatile uint32_t data = stm32_getreg(regaddr); (void)data; } } } /**************************************************************************** * Name: stm32_epout_complete * * Description: * This function is called when an OUT transfer complete interrupt is * received. It completes the read request at the head of the endpoint's * request queue. * ****************************************************************************/ static void stm32_epout_complete(FAR struct stm32_usbdev_s *priv, FAR struct stm32_ep_s *privep) { struct stm32_req_s *privreq; /* Since a transfer just completed, there must be a read request at the head of * the endpoint request queue. */ privreq = stm32_rqpeek(privep); DEBUGASSERT(privreq); if (!privreq) { /* An OUT transfer completed, but no packet to receive the data. This * should not happen. */ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPOUTQEMPTY), privep->epphy); privep->active = false; return; } uinfo("EP%d: len=%d xfrd=%d\n", privep->epphy, privreq->req.len, privreq->req.xfrd); /* Return the completed read request to the class driver and mark the state * IDLE. */ usbtrace(TRACE_COMPLETE(privep->epphy), privreq->req.xfrd); stm32_req_complete(privep, OK); privep->active = false; /* Now set up the next read request (if any) */ stm32_epout_request(priv, privep); } /**************************************************************************** * Name: stm32_ep0out_receive * * Description: * This function is called from the RXFLVL interrupt handler when new incoming * data is available in the endpoint's RxFIFO. This function will simply * copy the incoming data into pending request's data buffer. * ****************************************************************************/ static inline void stm32_ep0out_receive(FAR struct stm32_ep_s *privep, int bcnt) { FAR struct stm32_usbdev_s *priv; /* Sanity Checking */ DEBUGASSERT(privep && privep->ep.priv); priv = (FAR struct stm32_usbdev_s *)privep->ep.priv; uinfo("EP0: bcnt=%d\n", bcnt); usbtrace(TRACE_READ(EP0), bcnt); /* Verify that an OUT SETUP request as received before this data was * received in the RxFIFO. */ if (priv->ep0state == EP0STATE_SETUP_OUT) { /* Read the data into our special buffer for SETUP data */ int readlen = MIN(CONFIG_USBDEV_SETUP_MAXDATASIZE, bcnt); stm32_rxfifo_read(privep, priv->ep0data, readlen); /* Do we have to discard any excess bytes? */ stm32_rxfifo_discard(privep, bcnt - readlen); /* Now we can process the setup command */ privep->active = false; priv->ep0state = EP0STATE_SETUP_READY; priv->ep0datlen = readlen; stm32_ep0out_setup(priv); } else { /* This is an error. We don't have any idea what to do with the EP0 * data in this case. Just read and discard it so that the RxFIFO * does not become constipated. */ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_NOOUTSETUP), priv->ep0state); stm32_rxfifo_discard(privep, bcnt); privep->active = false; } } /**************************************************************************** * Name: stm32_epout_receive * * Description: * This function is called from the RXFLVL interrupt handler when new incoming * data is available in the endpoint's RxFIFO. This function will simply * copy the incoming data into pending request's data buffer. * ****************************************************************************/ static inline void stm32_epout_receive(FAR struct stm32_ep_s *privep, int bcnt) { struct stm32_req_s *privreq; uint8_t *dest; int buflen; int readlen; /* Get a reference to the request at the head of the endpoint's request * queue. */ privreq = stm32_rqpeek(privep); if (!privreq) { /* Incoming data is available in the RxFIFO, but there is no read setup * to receive the receive the data. This should not happen for data * endpoints; those endpoints should have been NAKing any OUT data tokens. * * We should get here normally on OUT data phase following an OUT * SETUP command. EP0 data will still receive data in this case and it * should not be NAKing. */ if (privep->epphy == 0) { stm32_ep0out_receive(privep, bcnt); } else { /* Otherwise, the data is lost. This really should not happen if * NAKing is working as expected. */ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPOUTQEMPTY), privep->epphy); /* Discard the data in the RxFIFO */ stm32_rxfifo_discard(privep, bcnt); } privep->active = false; return; } uinfo("EP%d: len=%d xfrd=%d\n", privep->epphy, privreq->req.len, privreq->req.xfrd); usbtrace(TRACE_READ(privep->epphy), bcnt); /* Get the number of bytes to transfer from the RxFIFO */ buflen = privreq->req.len - privreq->req.xfrd; DEBUGASSERT(buflen > 0 && buflen >= bcnt); readlen = MIN(buflen, bcnt); /* Get the destination of the data transfer */ dest = privreq->req.buf + privreq->req.xfrd; /* Transfer the data from the RxFIFO to the request's data buffer */ stm32_rxfifo_read(privep, dest, readlen); /* If there were more bytes in the RxFIFO than could be held in the read * request, then we will have to discard those. */ stm32_rxfifo_discard(privep, bcnt - readlen); /* Update the number of bytes transferred */ privreq->req.xfrd += readlen; } /**************************************************************************** * Name: stm32_epout_request * * Description: * This function is called when either (1) new read request is received, or * (2) a pending receive request completes. If there is no read in pending, * then this function will initiate the next OUT (read) operation. * ****************************************************************************/ static void stm32_epout_request(FAR struct stm32_usbdev_s *priv, FAR struct stm32_ep_s *privep) { struct stm32_req_s *privreq; uint32_t regaddr; uint32_t regval; uint32_t xfrsize; uint32_t pktcnt; /* Make sure that there is not already a pending request request. If there is, * just return, leaving the newly received request in the request queue. */ if (!privep->active) { /* Loop until a valid request is found (or the request queue is empty). * The loop is only need to look at the request queue again is an invalid * read request is encountered. */ for (; ; ) { /* Get a reference to the request at the head of the endpoint's request queue */ privreq = stm32_rqpeek(privep); if (!privreq) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPOUTQEMPTY), privep->epphy); /* There are no read requests to be setup. Configure the hardware to * NAK any incoming packets. (This should already be the case. I * think that the hardware will automatically NAK after a transfer is * completed until SNAK is cleared). */ regaddr = STM32_OTGHS_DOEPCTL(privep->epphy); regval = stm32_getreg(regaddr); regval |= OTGHS_DOEPCTL_SNAK; stm32_putreg(regval, regaddr); /* This endpoint is no longer actively transferring */ privep->active = false; return; } uinfo("EP%d: len=%d\n", privep->epphy, privreq->req.len); /* Ignore any attempt to receive a zero length packet (this really * should not happen. */ if (privreq->req.len <= 0) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPOUTNULLPACKET), 0); stm32_req_complete(privep, OK); } /* Otherwise, we have a usable read request... break out of the loop */ else { break; } } /* Setup the pending read into the request buffer. First calculate: * * pktcnt = the number of packets (of maxpacket bytes) required to * perform the transfer. * xfrsize = The total number of bytes required (in units of * maxpacket bytes). */ pktcnt = (privreq->req.len + (privep->ep.maxpacket - 1)) / privep->ep.maxpacket; xfrsize = pktcnt * privep->ep.maxpacket; /* Then setup the hardware to perform this transfer */ regaddr = STM32_OTGHS_DOEPTSIZ(privep->epphy); regval = stm32_getreg(regaddr); regval &= ~(OTGHS_DOEPTSIZ_XFRSIZ_MASK | OTGHS_DOEPTSIZ_PKTCNT_MASK); regval |= (xfrsize << OTGHS_DOEPTSIZ_XFRSIZ_SHIFT); regval |= (pktcnt << OTGHS_DOEPTSIZ_PKTCNT_SHIFT); stm32_putreg(regval, regaddr); /* Then enable the transfer */ regaddr = STM32_OTGHS_DOEPCTL(privep->epphy); regval = stm32_getreg(regaddr); /* When an isochronous transfer is enabled the Even/Odd frame bit must * also be set appropriately. */ #ifdef CONFIG_USBDEV_ISOCHRONOUS if (privep->eptype == USB_EP_ATTR_XFER_ISOC) { if (privep->odd) { regval |= OTGHS_DOEPCTL_SODDFRM; } else { regval |= OTGHS_DOEPCTL_SEVNFRM; } } #endif /* Clearing NAKing and enable the transfer. */ regval |= (OTGHS_DOEPCTL_CNAK | OTGHS_DOEPCTL_EPENA); stm32_putreg(regval, regaddr); /* A transfer is now active on this endpoint */ privep->active = true; /* EP0 is a special case. We need to know when to switch back to * normal SETUP processing. */ if (privep->epphy == EP0) { priv->ep0state = EP0STATE_DATA_OUT; } } } /**************************************************************************** * Name: stm32_ep_flush * * Description: * Flush any primed descriptors from this ep * ****************************************************************************/ static void stm32_ep_flush(struct stm32_ep_s *privep) { if (privep->isin) { stm32_txfifo_flush(OTGHS_GRSTCTL_TXFNUM_D(privep->epphy)); } else { stm32_rxfifo_flush(); } } /**************************************************************************** * Name: stm32_req_complete * * Description: * Handle termination of the request at the head of the endpoint request queue. * ****************************************************************************/ static void stm32_req_complete(struct stm32_ep_s *privep, int16_t result) { FAR struct stm32_req_s *privreq; /* Remove the request at the head of the request list */ privreq = stm32_req_remfirst(privep); DEBUGASSERT(privreq != NULL); /* If endpoint 0, temporarily reflect the state of protocol stalled * in the callback. */ bool stalled = privep->stalled; if (privep->epphy == EP0) { privep->stalled = privep->dev->stalled; } /* Save the result in the request structure */ privreq->req.result = result; /* Callback to the request completion handler */ privreq->req.callback(&privep->ep, &privreq->req); /* Restore the stalled indication */ privep->stalled = stalled; } /**************************************************************************** * Name: stm32_req_cancel * * Description: * Cancel all pending requests for an endpoint * ****************************************************************************/ static void stm32_req_cancel(struct stm32_ep_s *privep, int16_t status) { if (!stm32_rqempty(privep)) { stm32_ep_flush(privep); } while (!stm32_rqempty(privep)) { usbtrace(TRACE_COMPLETE(privep->epphy), (stm32_rqpeek(privep))->req.xfrd); stm32_req_complete(privep, status); } } /**************************************************************************** * Name: stm32_ep_findbyaddr * * Description: * Find the physical endpoint structure corresponding to a logic endpoint * address * ****************************************************************************/ static struct stm32_ep_s *stm32_ep_findbyaddr(struct stm32_usbdev_s *priv, uint16_t eplog) { struct stm32_ep_s *privep; uint8_t epphy = USB_EPNO(eplog); if (epphy >= STM32_NENDPOINTS) { return NULL; } /* Is this an IN or an OUT endpoint? */ if (USB_ISEPIN(eplog)) { privep = &priv->epin[epphy]; } else { privep = &priv->epout[epphy]; } /* Return endpoint reference */ DEBUGASSERT(privep->epphy == epphy); return privep; } /**************************************************************************** * Name: stm32_req_dispatch * * Description: * Provide unhandled setup actions to the class driver. This is logically part * of the USB interrupt handler. * ****************************************************************************/ static int stm32_req_dispatch(struct stm32_usbdev_s *priv, const struct usb_ctrlreq_s *ctrl) { int ret = -EIO; usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_DISPATCH), 0); if (priv->driver) { /* Forward to the control request to the class driver implementation */ ret = CLASS_SETUP(priv->driver, &priv->usbdev, ctrl, priv->ep0data, priv->ep0datlen); } if (ret < 0) { /* Stall on failure */ usbtrace(TRACE_DEVERROR(STM32_TRACEERR_DISPATCHSTALL), 0); priv->stalled = true; } return ret; } /**************************************************************************** * Name: stm32_usbreset * * Description: * Reset Usb engine * ****************************************************************************/ static void stm32_usbreset(struct stm32_usbdev_s *priv) { FAR struct stm32_ep_s *privep; uint32_t regval; int i; /* Clear the Remote Wake-up Signaling */ regval = stm32_getreg(STM32_OTGHS_DCTL); regval &= ~OTGHS_DCTL_RWUSIG; stm32_putreg(regval, STM32_OTGHS_DCTL); /* Flush the EP0 Tx FIFO */ stm32_txfifo_flush(OTGHS_GRSTCTL_TXFNUM_D(EP0)); /* Tell the class driver that we are disconnected. The class * driver should then accept any new configurations. */ if (priv->driver) { CLASS_DISCONNECT(priv->driver, &priv->usbdev); } /* Mark all endpoints as available */ priv->epavail[0] = STM32_EP_AVAILABLE; priv->epavail[1] = STM32_EP_AVAILABLE; /* Disable all end point interrupts */ for (i = 0; i < STM32_NENDPOINTS ; i++) { /* Disable endpoint interrupts */ stm32_putreg(0xff, STM32_OTGHS_DIEPINT(i)); stm32_putreg(0xff, STM32_OTGHS_DOEPINT(i)); /* Return write requests to the class implementation */ privep = &priv->epin[i]; stm32_req_cancel(privep, -ESHUTDOWN); /* Reset IN endpoint status */ privep->stalled = false; /* Return read requests to the class implementation */ privep = &priv->epout[i]; stm32_req_cancel(privep, -ESHUTDOWN); /* Reset endpoint status */ privep->stalled = false; } stm32_putreg(0xffffffff, STM32_OTGHS_DAINT); /* Mask all device endpoint interrupts except EP0 */ regval = (OTGHS_DAINT_IEP(EP0) | OTGHS_DAINT_OEP(EP0)); stm32_putreg(regval, STM32_OTGHS_DAINTMSK); /* Unmask OUT interrupts */ regval = (OTGHS_DOEPMSK_XFRCM | OTGHS_DOEPMSK_STUPM | OTGHS_DOEPMSK_EPDM); stm32_putreg(regval, STM32_OTGHS_DOEPMSK); /* Unmask IN interrupts */ regval = (OTGHS_DIEPMSK_XFRCM | OTGHS_DIEPMSK_EPDM | OTGHS_DIEPMSK_TOM); stm32_putreg(regval, STM32_OTGHS_DIEPMSK); /* Reset device address to 0 */ stm32_setaddress(priv, 0); priv->devstate = DEVSTATE_DEFAULT; priv->usbdev.speed = USB_SPEED_FULL; /* Re-configure EP0 */ stm32_ep0_configure(priv); /* Setup EP0 to receive SETUP packets */ stm32_ep0out_ctrlsetup(priv); } /**************************************************************************** * Name: stm32_ep0out_testmode * * Description: * Select test mode * ****************************************************************************/ static inline void stm32_ep0out_testmode(FAR struct stm32_usbdev_s *priv, uint16_t index) { uint8_t testmode; testmode = index >> 8; switch (testmode) { case 1: priv->testmode = OTGHS_TESTMODE_J; break; case 2: priv->testmode = OTGHS_TESTMODE_K; break; case 3: priv->testmode = OTGHS_TESTMODE_SE0_NAK; break; case 4: priv->testmode = OTGHS_TESTMODE_PACKET; break; case 5: priv->testmode = OTGHS_TESTMODE_FORCE; break; default: usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADTESTMODE), testmode); priv->dotest = false; priv->testmode = OTGHS_TESTMODE_DISABLED; priv->stalled = true; } priv->dotest = true; stm32_ep0in_transmitzlp(priv); } /**************************************************************************** * Name: stm32_ep0out_stdrequest * * Description: * Handle a stanard request on EP0. Pick off the things of interest to the * USB device controller driver; pass what is left to the class driver. * ****************************************************************************/ static inline void stm32_ep0out_stdrequest(struct stm32_usbdev_s *priv, FAR struct stm32_ctrlreq_s *ctrlreq) { FAR struct stm32_ep_s *privep; /* Handle standard request */ switch (ctrlreq->req) { case USB_REQ_GETSTATUS: { /* type: device-to-host; recipient = device, interface, endpoint * value: 0 * index: zero interface endpoint * len: 2; data = status */ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_GETSTATUS), 0); if (!priv->addressed || ctrlreq->len != 2 || USB_REQ_ISOUT(ctrlreq->type) || ctrlreq->value != 0) { priv->stalled = true; } else { switch (ctrlreq->type & USB_REQ_RECIPIENT_MASK) { case USB_REQ_RECIPIENT_ENDPOINT: { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPGETSTATUS), 0); privep = stm32_ep_findbyaddr(priv, ctrlreq->index); if (!privep) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADEPGETSTATUS), 0); priv->stalled = true; } else { if (privep->stalled) { priv->ep0data[0] = (1 << USB_FEATURE_ENDPOINTHALT); } else { priv->ep0data[0] = 0; /* Not stalled */ } priv->ep0data[1] = 0; stm32_ep0in_setupresponse(priv, priv->ep0data, 2); } } break; case USB_REQ_RECIPIENT_DEVICE: { if (ctrlreq->index == 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_DEVGETSTATUS), 0); /* Features: Remote Wakeup and self-powered */ priv->ep0data[0] = (priv->selfpowered << USB_FEATURE_SELFPOWERED); priv->ep0data[0] |= (priv->wakeup << USB_FEATURE_REMOTEWAKEUP); priv->ep0data[1] = 0; stm32_ep0in_setupresponse(priv, priv->ep0data, 2); } else { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADDEVGETSTATUS), 0); priv->stalled = true; } } break; case USB_REQ_RECIPIENT_INTERFACE: { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_IFGETSTATUS), 0); priv->ep0data[0] = 0; priv->ep0data[1] = 0; stm32_ep0in_setupresponse(priv, priv->ep0data, 2); } break; default: { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADGETSTATUS), 0); priv->stalled = true; } break; } } } break; case USB_REQ_CLEARFEATURE: { /* type: host-to-device; recipient = device, interface or endpoint * value: feature selector * index: zero interface endpoint; * len: zero, data = none */ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_CLEARFEATURE), 0); if (priv->addressed != 0 && ctrlreq->len == 0) { uint8_t recipient = ctrlreq->type & USB_REQ_RECIPIENT_MASK; if (recipient == USB_REQ_RECIPIENT_ENDPOINT && ctrlreq->value == USB_FEATURE_ENDPOINTHALT && (privep = stm32_ep_findbyaddr(priv, ctrlreq->index)) != NULL) { stm32_ep_clrstall(privep); stm32_ep0in_transmitzlp(priv); } else if (recipient == USB_REQ_RECIPIENT_DEVICE && ctrlreq->value == USB_FEATURE_REMOTEWAKEUP) { priv->wakeup = 0; stm32_ep0in_transmitzlp(priv); } else { /* Actually, I think we could just stall here. */ (void)stm32_req_dispatch(priv, &priv->ctrlreq); } } else { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADCLEARFEATURE), 0); priv->stalled = true; } } break; case USB_REQ_SETFEATURE: { /* type: host-to-device; recipient = device, interface, endpoint * value: feature selector * index: zero interface endpoint; * len: 0; data = none */ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SETFEATURE), 0); if (priv->addressed != 0 && ctrlreq->len == 0) { uint8_t recipient = ctrlreq->type & USB_REQ_RECIPIENT_MASK; if (recipient == USB_REQ_RECIPIENT_ENDPOINT && ctrlreq->value == USB_FEATURE_ENDPOINTHALT && (privep = stm32_ep_findbyaddr(priv, ctrlreq->index)) != NULL) { stm32_ep_setstall(privep); stm32_ep0in_transmitzlp(priv); } else if (recipient == USB_REQ_RECIPIENT_DEVICE && ctrlreq->value == USB_FEATURE_REMOTEWAKEUP) { priv->wakeup = 1; stm32_ep0in_transmitzlp(priv); } else if (recipient == USB_REQ_RECIPIENT_DEVICE && ctrlreq->value == USB_FEATURE_TESTMODE && ((ctrlreq->index & 0xff) == 0)) { stm32_ep0out_testmode(priv, ctrlreq->index); } else if (priv->configured) { /* Actually, I think we could just stall here. */ (void)stm32_req_dispatch(priv, &priv->ctrlreq); } else { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADSETFEATURE), 0); priv->stalled = true; } } else { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADSETFEATURE), 0); priv->stalled = true; } } break; case USB_REQ_SETADDRESS: { /* type: host-to-device; recipient = device * value: device address * index: 0 * len: 0; data = none */ usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SETADDRESS), ctrlreq->value); if ((ctrlreq->type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE && ctrlreq->index == 0 && ctrlreq->len == 0 && ctrlreq->value < 128 && priv->devstate != DEVSTATE_CONFIGURED) { /* Save the address. We cannot actually change to the next address until * the completion of the status phase. */ stm32_setaddress(priv, (uint16_t)priv->ctrlreq.value[0]); stm32_ep0in_transmitzlp(priv); } else { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADSETADDRESS), 0); priv->stalled = true; } } break; case USB_REQ_GETDESCRIPTOR: /* type: device-to-host; recipient = device * value: descriptor type and index * index: 0 or language ID; * len: descriptor len; data = descriptor */ case USB_REQ_SETDESCRIPTOR: /* type: host-to-device; recipient = device * value: descriptor type and index * index: 0 or language ID; * len: descriptor len; data = descriptor */ { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_GETSETDESC), 0); if ((ctrlreq->type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE) { (void)stm32_req_dispatch(priv, &priv->ctrlreq); } else { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADGETSETDESC), 0); priv->stalled = true; } } break; case USB_REQ_GETCONFIGURATION: /* type: device-to-host; recipient = device * value: 0; * index: 0; * len: 1; data = configuration value */ { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_GETCONFIG), 0); if (priv->addressed && (ctrlreq->type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE && ctrlreq->value == 0 && ctrlreq->index == 0 && ctrlreq->len == 1) { (void)stm32_req_dispatch(priv, &priv->ctrlreq); } else { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADGETCONFIG), 0); priv->stalled = true; } } break; case USB_REQ_SETCONFIGURATION: /* type: host-to-device; recipient = device * value: configuration value * index: 0; * len: 0; data = none */ { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SETCONFIG), 0); if (priv->addressed && (ctrlreq->type & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE && ctrlreq->index == 0 && ctrlreq->len == 0) { /* Give the configuration to the class driver */ int ret = stm32_req_dispatch(priv, &priv->ctrlreq); /* If the class driver accepted the configuration, then mark the * device state as configured (or not, depending on the * configuration). */ if (ret == OK) { uint8_t cfg = (uint8_t)ctrlreq->value; if (cfg != 0) { priv->devstate = DEVSTATE_CONFIGURED; priv->configured = true; } else { priv->devstate = DEVSTATE_ADDRESSED; priv->configured = false; } } } else { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADSETCONFIG), 0); priv->stalled = true; } } break; case USB_REQ_GETINTERFACE: /* type: device-to-host; recipient = interface * value: 0 * index: interface; * len: 1; data = alt interface */ case USB_REQ_SETINTERFACE: /* type: host-to-device; recipient = interface * value: alternate setting * index: interface; * len: 0; data = none */ { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_GETSETIF), 0); (void)stm32_req_dispatch(priv, &priv->ctrlreq); } break; case USB_REQ_SYNCHFRAME: /* type: device-to-host; recipient = endpoint * value: 0 * index: endpoint; * len: 2; data = frame number */ { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SYNCHFRAME), 0); } break; default: { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDCTRLREQ), 0); priv->stalled = true; } break; } } /**************************************************************************** * Name: stm32_ep0out_setup * * Description: * USB Ctrl EP Setup Event. This is logically part of the USB interrupt * handler. This event occurs when a setup packet is receive on EP0 OUT. * ****************************************************************************/ static inline void stm32_ep0out_setup(struct stm32_usbdev_s *priv) { struct stm32_ctrlreq_s ctrlreq; /* Verify that a SETUP was received */ if (priv->ep0state != EP0STATE_SETUP_READY) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EP0NOSETUP), priv->ep0state); return; } /* Terminate any pending requests */ stm32_req_cancel(&priv->epout[EP0], -EPROTO); stm32_req_cancel(&priv->epin[EP0], -EPROTO); /* Assume NOT stalled */ priv->epout[EP0].stalled = false; priv->epin[EP0].stalled = false; priv->stalled = false; /* Starting to process a control request - update state */ priv->ep0state = EP0STATE_SETUP_PROCESS; /* And extract the little-endian 16-bit values to host order */ ctrlreq.type = priv->ctrlreq.type; ctrlreq.req = priv->ctrlreq.req; ctrlreq.value = GETUINT16(priv->ctrlreq.value); ctrlreq.index = GETUINT16(priv->ctrlreq.index); ctrlreq.len = GETUINT16(priv->ctrlreq.len); uinfo("type=%02x req=%02x value=%04x index=%04x len=%04x\n", ctrlreq.type, ctrlreq.req, ctrlreq.value, ctrlreq.index, ctrlreq.len); /* Check for a standard request */ if ((ctrlreq.type & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_STANDARD) { /* Dispatch any non-standard requests */ (void)stm32_req_dispatch(priv, &priv->ctrlreq); } else { /* Handle standard requests. */ stm32_ep0out_stdrequest(priv, &ctrlreq); } /* Check if the setup processing resulted in a STALL */ if (priv->stalled) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EP0SETUPSTALLED), priv->ep0state); stm32_ep0_stall(priv); } /* Reset state/data associated with thie SETUP request */ priv->ep0datlen = 0; } /**************************************************************************** * Name: stm32_epout * * Description: * This is part of the OUT endpoint interrupt processing. This function * handles the OUT event for a single endpoint. * ****************************************************************************/ static inline void stm32_epout(FAR struct stm32_usbdev_s *priv, uint8_t epno) { FAR struct stm32_ep_s *privep; /* Endpoint 0 is a special case. */ if (epno == 0) { privep = &priv->epout[EP0]; /* In the EP0STATE_DATA_OUT state, we are receiving data into the * request buffer. In that case, we must continue the request * processing. */ if (priv->ep0state == EP0STATE_DATA_OUT) { /* Continue processing data from the EP0 OUT request queue */ stm32_epout_complete(priv, privep); /* If we are not actively processing an OUT request, then we * need to setup to receive the next control request. */ if (!privep->active) { stm32_ep0out_ctrlsetup(priv); priv->ep0state = EP0STATE_IDLE; } } } /* For other endpoints, the only possibility is that we are continuing * or finishing an OUT request. */ else if (priv->devstate == DEVSTATE_CONFIGURED) { stm32_epout_complete(priv, &priv->epout[epno]); } } /**************************************************************************** * Name: stm32_epout_interrupt * * Description: * USB OUT endpoint interrupt handler. The core generates this interrupt when * there is an interrupt is pending on one of the OUT endpoints of the core. * The driver must read the OTGHS DAINT register to determine the exact number * of the OUT endpoint on which the interrupt occurred, and then read the * corresponding OTGHS DOEPINTx register to determine the exact cause of the * interrupt. * ****************************************************************************/ static inline void stm32_epout_interrupt(FAR struct stm32_usbdev_s *priv) { uint32_t daint; uint32_t regval; uint32_t doepint; int epno; /* Get the pending, enabled interrupts for the OUT endpoint from the endpoint * interrupt status register. */ regval = stm32_getreg(STM32_OTGHS_DAINT); regval &= stm32_getreg(STM32_OTGHS_DAINTMSK); daint = (regval & OTGHS_DAINT_OEP_MASK) >> OTGHS_DAINT_OEP_SHIFT; if (daint == 0) { /* We got an interrupt, but there is no unmasked endpoint that caused * it ?! When this happens, the interrupt flag never gets cleared and * we are stuck in infinite interrupt loop. * * This shouldn't happen if we are diligent about handling timing * issues when masking endpoint interrupts. However, this workaround * avoids infinite loop and allows operation to continue normally. It * works by clearing each endpoint flags, masked or not. */ regval = stm32_getreg(STM32_OTGHS_DAINT); daint = (regval & OTGHS_DAINT_OEP_MASK) >> OTGHS_DAINT_OEP_SHIFT; usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPOUTUNEXPECTED), (uint16_t)regval); epno = 0; while (daint) { if ((daint & 1) != 0) { regval = stm32_getreg(STM32_OTGHS_DOEPINT(epno)); uinfo("DOEPINT(%d) = %08x\n", epno, regval); stm32_putreg(0xFF, STM32_OTGHS_DOEPINT(epno)); } epno++; daint >>= 1; } return; } /* Process each pending IN endpoint interrupt */ epno = 0; while (daint) { /* Is an OUT interrupt pending for this endpoint? */ if ((daint & 1) != 0) { /* Yes.. get the OUT endpoint interrupt status */ doepint = stm32_getreg(STM32_OTGHS_DOEPINT(epno)); doepint &= stm32_getreg(STM32_OTGHS_DOEPMSK); /* Transfer completed interrupt. This interrupt is trigged when * stm32_rxinterrupt() removes the last packet data from the RxFIFO. * In this case, core internally sets the NAK bit for this endpoint to * prevent it from receiving any more packets. */ if ((doepint & OTGHS_DOEPINT_XFRC) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPOUT_XFRC), (uint16_t)doepint); /* Clear the bit in DOEPINTn for this interrupt */ stm32_putreg(OTGHS_DOEPINT_XFRC, STM32_OTGHS_DOEPINT(epno)); /* Handle the RX transfer data ready event */ stm32_epout(priv, epno); } /* Endpoint disabled interrupt (ignored because this interrupt is * used in polled mode by the endpoint disable logic). */ #if 1 /* REVISIT: */ if ((doepint & OTGHS_DOEPINT_EPDISD) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPOUT_EPDISD), (uint16_t)doepint); /* Clear the bit in DOEPINTn for this interrupt */ stm32_putreg(OTGHS_DOEPINT_EPDISD, STM32_OTGHS_DOEPINT(epno)); } #endif /* Setup Phase Done (control EPs) */ if ((doepint & OTGHS_DOEPINT_SETUP) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPOUT_SETUP), priv->ep0state); /* Handle the receipt of the IN SETUP packets now (OUT setup * packet processing may be delayed until the accompanying * OUT DATA is received) */ if (priv->ep0state == EP0STATE_SETUP_READY) { stm32_ep0out_setup(priv); } stm32_putreg(OTGHS_DOEPINT_SETUP, STM32_OTGHS_DOEPINT(epno)); } } epno++; daint >>= 1; } } /**************************************************************************** * Name: stm32_epin_runtestmode * * Description: * Execute the test mode setup by the SET FEATURE request * ****************************************************************************/ static inline void stm32_epin_runtestmode(FAR struct stm32_usbdev_s *priv) { uint32_t regval = stm32_getreg(STM32_OTGHS_DCTL); regval &= OTGHS_DCTL_TCTL_MASK; regval |= (uint32_t)priv->testmode << OTGHS_DCTL_TCTL_SHIFT; stm32_putreg(regval , STM32_OTGHS_DCTL); priv->dotest = 0; priv->testmode = OTGHS_TESTMODE_DISABLED; } /**************************************************************************** * Name: stm32_epin * * Description: * This is part of the IN endpoint interrupt processing. This function * handles the IN event for a single endpoint. * ****************************************************************************/ static inline void stm32_epin(FAR struct stm32_usbdev_s *priv, uint8_t epno) { FAR struct stm32_ep_s *privep = &priv->epin[epno]; /* Endpoint 0 is a special case. */ if (epno == 0) { /* In the EP0STATE_DATA_IN state, we are sending data from request * buffer. In that case, we must continue the request processing. */ if (priv->ep0state == EP0STATE_DATA_IN) { /* Continue processing data from the EP0 OUT request queue */ stm32_epin_request(priv, privep); /* If we are not actively processing an OUT request, then we * need to setup to receive the next control request. */ if (!privep->active) { stm32_ep0out_ctrlsetup(priv); priv->ep0state = EP0STATE_IDLE; } } /* Test mode is another special case */ if (priv->dotest) { stm32_epin_runtestmode(priv); } } /* For other endpoints, the only possibility is that we are continuing * or finishing an IN request. */ else if (priv->devstate == DEVSTATE_CONFIGURED) { /* Continue processing data from the endpoint write request queue */ stm32_epin_request(priv, privep); } } /**************************************************************************** * Name: stm32_epin_txfifoempty * * Description: * TxFIFO empty interrupt handling * ****************************************************************************/ static inline void stm32_epin_txfifoempty(FAR struct stm32_usbdev_s *priv, int epno) { FAR struct stm32_ep_s *privep = &priv->epin[epno]; /* Continue processing the write request queue. This may mean sending * more data from the existing request or terminating the current requests * and (perhaps) starting the IN transfer from the next write request. */ stm32_epin_request(priv, privep); } /**************************************************************************** * Name: stm32_epin_interrupt * * Description: * USB IN endpoint interrupt handler. The core generates this interrupt when * an interrupt is pending on one of the IN endpoints of the core. The driver * must read the OTGHS DAINT register to determine the exact number of the IN * endpoint on which the interrupt occurred, and then read the corresponding * OTGHS DIEPINTx register to determine the exact cause of the interrupt. * ****************************************************************************/ static inline void stm32_epin_interrupt(FAR struct stm32_usbdev_s *priv) { uint32_t diepint; uint32_t daint; uint32_t mask; uint32_t empty; int epno; /* Get the pending, enabled interrupts for the IN endpoint from the endpoint * interrupt status register. */ daint = stm32_getreg(STM32_OTGHS_DAINT); daint &= stm32_getreg(STM32_OTGHS_DAINTMSK); daint &= OTGHS_DAINT_IEP_MASK; if (daint == 0) { /* We got an interrupt, but there is no unmasked endpoint that caused * it ?! When this happens, the interrupt flag never gets cleared and * we are stuck in infinite interrupt loop. * * This shouldn't happen if we are diligent about handling timing * issues when masking endpoint interrupts. However, this workaround * avoids infinite loop and allows operation to continue normally. It * works by clearing each endpoint flags, masked or not. */ daint = stm32_getreg(STM32_OTGHS_DAINT); usbtrace(TRACE_DEVERROR(STM32_TRACEERR_EPINUNEXPECTED), (uint16_t)daint); daint &= OTGHS_DAINT_IEP_MASK; epno = 0; while (daint) { if ((daint & 1) != 0) { uinfo("DIEPINT(%d) = %08x\n", epno, stm32_getreg(STM32_OTGHS_DIEPINT(epno))); stm32_putreg(0xFF, STM32_OTGHS_DIEPINT(epno)); } epno++; daint >>= 1; } return; } /* Process each pending IN endpoint interrupt */ epno = 0; while (daint) { /* Is an IN interrupt pending for this endpoint? */ if ((daint & 1) != 0) { /* Get IN interrupt mask register. Bits 0-6 correspond to enabled * interrupts as will be found in the DIEPINT interrupt status * register. */ mask = stm32_getreg(STM32_OTGHS_DIEPMSK); /* Check if the TxFIFO not empty interrupt is enabled for this * endpoint in the DIEPMSK register. Bits n corresponds to * endpoint n in the register. That condition corresponds to * bit 7 of the DIEPINT interrupt status register. There is * no TXFE bit in the mask register, so we fake one here. */ empty = stm32_getreg(STM32_OTGHS_DIEPEMPMSK); if ((empty & OTGHS_DIEPEMPMSK(epno)) != 0) { mask |= OTGHS_DIEPINT_TXFE; } /* Now, read the interrupt status and mask out all disabled * interrupts. */ diepint = stm32_getreg(STM32_OTGHS_DIEPINT(epno)) & mask; /* Decode and process the enabled, pending interrupts */ /* Transfer completed interrupt */ if ((diepint & OTGHS_DIEPINT_XFRC) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_XFRC), (uint16_t)diepint); /* It is possible that logic may be waiting for a the * TxFIFO to become empty. We disable the TxFIFO empty * interrupt here; it will be re-enabled if there is still * insufficient space in the TxFIFO. */ empty &= ~OTGHS_DIEPEMPMSK(epno); stm32_putreg(empty, STM32_OTGHS_DIEPEMPMSK); stm32_putreg(OTGHS_DIEPINT_XFRC, STM32_OTGHS_DIEPINT(epno)); /* IN transfer complete */ stm32_epin(priv, epno); } /* Timeout condition */ if ((diepint & OTGHS_DIEPINT_TOC) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_TOC), (uint16_t)diepint); stm32_putreg(OTGHS_DIEPINT_TOC, STM32_OTGHS_DIEPINT(epno)); } /* IN token received when TxFIFO is empty. Applies to non-periodic IN * endpoints only. This interrupt indicates that an IN token was received * when the associated TxFIFO (periodic/non-periodic) was empty. This * interrupt is asserted on the endpoint for which the IN token was * received. */ if ((diepint & OTGHS_DIEPINT_ITTXFE) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_ITTXFE), (uint16_t)diepint); stm32_epin_request(priv, &priv->epin[epno]); stm32_putreg(OTGHS_DIEPINT_ITTXFE, STM32_OTGHS_DIEPINT(epno)); } /* IN endpoint NAK effective (ignored as this used only in polled * mode) */ #if 0 if ((diepint & OTGHS_DIEPINT_INEPNE) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_INEPNE), (uint16_t)diepint); stm32_putreg(OTGHS_DIEPINT_INEPNE, STM32_OTGHS_DIEPINT(epno)); } #endif /* Endpoint disabled interrupt (ignored as this used only in polled * mode) */ #if 0 if ((diepint & OTGHS_DIEPINT_EPDISD) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_EPDISD), (uint16_t)diepint); stm32_putreg(OTGHS_DIEPINT_EPDISD, STM32_OTGHS_DIEPINT(epno)); } #endif /* Transmit FIFO empty */ if ((diepint & OTGHS_DIEPINT_TXFE) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN_TXFE), (uint16_t)diepint); /* If we were waiting for TxFIFO to become empty, the we might have both * XFRC and TXFE interrupts pending. Since we do the same thing for both * cases, ignore the TXFE if we have already processed the XFRC. */ if ((diepint & OTGHS_DIEPINT_XFRC) == 0) { /* Mask further FIFO empty interrupts. This will be re-enabled * whenever we need to wait for a FIFO event. */ empty &= ~OTGHS_DIEPEMPMSK(epno); stm32_putreg(empty, STM32_OTGHS_DIEPEMPMSK); /* Handle TxFIFO empty */ stm32_epin_txfifoempty(priv, epno); } /* Clear the pending TxFIFO empty interrupt */ stm32_putreg(OTGHS_DIEPINT_TXFE, STM32_OTGHS_DIEPINT(epno)); } } epno++; daint >>= 1; } } /**************************************************************************** * Name: stm32_resumeinterrupt * * Description: * Resume/remote wakeup detected interrupt * ****************************************************************************/ static inline void stm32_resumeinterrupt(FAR struct stm32_usbdev_s *priv) { uint32_t regval; /* Restart the PHY clock and un-gate USB core clock (HCLK) */ #ifdef CONFIG_USBDEV_LOWPOWER regval = stm32_getreg(STM32_OTGHS_PCGCCTL); regval &= ~(OTGHS_PCGCCTL_STPPCLK | OTGHS_PCGCCTL_GATEHCLK); stm32_putreg(regval, STM32_OTGHS_PCGCCTL); #endif /* Clear remote wake-up signaling */ regval = stm32_getreg(STM32_OTGHS_DCTL); regval &= ~OTGHS_DCTL_RWUSIG; stm32_putreg(regval, STM32_OTGHS_DCTL); /* Restore full power -- whatever that means for this particular board */ stm32_usbsuspend((struct usbdev_s *)priv, true); /* Notify the class driver of the resume event */ if (priv->driver) { CLASS_RESUME(priv->driver, &priv->usbdev); } } /**************************************************************************** * Name: stm32_suspendinterrupt * * Description: * USB suspend interrupt * ****************************************************************************/ static inline void stm32_suspendinterrupt(FAR struct stm32_usbdev_s *priv) { #ifdef CONFIG_USBDEV_LOWPOWER uint32_t regval; #endif /* Notify the class driver of the suspend event */ if (priv->driver) { CLASS_SUSPEND(priv->driver, &priv->usbdev); } #ifdef CONFIG_USBDEV_LOWPOWER /* OTGHS_DSTS_SUSPSTS is set as long as the suspend condition is detected * on USB. Check if we are still have the suspend condition, that we are * connected to the host, and that we have been configured. */ regval = stm32_getreg(STM32_OTGHS_DSTS); if ((regval & OTGHS_DSTS_SUSPSTS) != 0 && devstate == DEVSTATE_CONFIGURED) { /* Switch off OTG HS clocking. Setting OTGHS_PCGCCTL_STPPCLK stops the * PHY clock. */ regval = stm32_getreg(STM32_OTGHS_PCGCCTL); regval |= OTGHS_PCGCCTL_STPPCLK; stm32_putreg(regval, STM32_OTGHS_PCGCCTL); /* Setting OTGHS_PCGCCTL_GATEHCLK gate HCLK to modules other than * the AHB Slave and Master and wakeup logic. */ regval |= OTGHS_PCGCCTL_GATEHCLK; stm32_putreg(regval, STM32_OTGHS_PCGCCTL); } #endif /* Let the board-specific logic know that we have entered the suspend * state */ stm32_usbsuspend((FAR struct usbdev_s *)priv, false); } /**************************************************************************** * Name: stm32_rxinterrupt * * Description: * RxFIFO non-empty interrupt. This interrupt indicates that there is at * least one packet pending to be read from the RxFIFO. * ****************************************************************************/ static inline void stm32_rxinterrupt(FAR struct stm32_usbdev_s *priv) { FAR struct stm32_ep_s *privep; uint32_t regval; int bcnt; int epphy; /* Disable the Rx status queue level interrupt */ regval = stm32_getreg(STM32_OTGHS_GINTMSK); regval &= ~OTGHS_GINT_RXFLVL; stm32_putreg(regval, STM32_OTGHS_GINTMSK); /* Get the status from the top of the FIFO */ regval = stm32_getreg(STM32_OTGHS_GRXSTSP); /* Decode status fields */ epphy = (regval & OTGHS_GRXSTSD_EPNUM_MASK) >> OTGHS_GRXSTSD_EPNUM_SHIFT; if (epphy < STM32_NENDPOINTS) { privep = &priv->epout[epphy]; /* Handle the RX event according to the packet status field */ switch (regval & OTGHS_GRXSTSD_PKTSTS_MASK) { /* Global OUT NAK. This indicate that the global OUT NAK bit has taken * effect. * * PKTSTS = Global OUT NAK, BCNT = 0, EPNUM = Don't Care, DPID = Don't * Care. */ case OTGHS_GRXSTSD_PKTSTS_OUTNAK: { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_OUTNAK), 0); } break; /* OUT data packet received. * * PKTSTS = DataOUT, BCNT = size of the received data OUT packet, * EPNUM = EPNUM on which the packet was received, DPID = Actual Data PID. */ case OTGHS_GRXSTSD_PKTSTS_OUTRECVD: { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_OUTRECVD), epphy); bcnt = (regval & OTGHS_GRXSTSD_BCNT_MASK) >> OTGHS_GRXSTSD_BCNT_SHIFT; if (bcnt > 0) { stm32_epout_receive(privep, bcnt); } } break; /* OUT transfer completed. This indicates that an OUT data transfer for * the specified OUT endpoint has completed. After this entry is popped * from the receive FIFO, the core asserts a Transfer Completed interrupt * on the specified OUT endpoint. * * PKTSTS = Data OUT Transfer Done, BCNT = 0, EPNUM = OUT EP Num on * which the data transfer is complete, DPID = Don't Care. */ case OTGHS_GRXSTSD_PKTSTS_OUTDONE: { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_OUTDONE), epphy); } break; /* SETUP transaction completed. This indicates that the Setup stage for * the specified endpoint has completed and the Data stage has started. * After this entry is popped from the receive FIFO, the core asserts a * Setup interrupt on the specified control OUT endpoint (triggers an * interrupt). * * PKTSTS = Setup Stage Done, BCNT = 0, EPNUM = Control EP Num, * DPID = Don't Care. */ case OTGHS_GRXSTSD_PKTSTS_SETUPDONE: { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SETUPDONE), epphy); } break; /* SETUP data packet received. This indicates that a SETUP packet for the * specified endpoint is now available for reading from the receive FIFO. * * PKTSTS = SETUP, BCNT = 8, EPNUM = Control EP Num, DPID = D0. */ case OTGHS_GRXSTSD_PKTSTS_SETUPRECVD: { uint16_t datlen; usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SETUPRECVD), epphy); /* Read EP0 setup data. NOTE: If multiple SETUP packets are received, * the last one overwrites the previous setup packets and only that * last SETUP packet will be processed. */ stm32_rxfifo_read(&priv->epout[EP0], (FAR uint8_t *)&priv->ctrlreq, USB_SIZEOF_CTRLREQ); /* Was this an IN or an OUT SETUP packet. If it is an OUT SETUP, * then we need to wait for the completion of the data phase to * process the setup command. If it is an IN SETUP packet, then * we must processing the command BEFORE we enter the DATA phase. * * If the data associated with the OUT SETUP packet is zero length, * then, of course, we don't need to wait. */ datlen = GETUINT16(priv->ctrlreq.len); if (USB_REQ_ISOUT(priv->ctrlreq.type) && datlen > 0) { /* Clear NAKSTS so that we can receive the data */ regval = stm32_getreg(STM32_OTGHS_DOEPCTL0); regval |= OTGHS_DOEPCTL0_CNAK; stm32_putreg(regval, STM32_OTGHS_DOEPCTL0); /* Wait for the data phase. */ priv->ep0state = EP0STATE_SETUP_OUT; } else { /* We can process the setup data as soon as SETUP done word is * popped of the RxFIFO. */ priv->ep0state = EP0STATE_SETUP_READY; } } break; default: { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), (regval & OTGHS_GRXSTSD_PKTSTS_MASK) >> OTGHS_GRXSTSD_PKTSTS_SHIFT); } break; } } /* Enable the Rx Status Queue Level interrupt */ regval = stm32_getreg(STM32_OTGHS_GINTMSK); regval |= OTGHS_GINT_RXFLVL; stm32_putreg(regval, STM32_OTGHS_GINTMSK); } /**************************************************************************** * Name: stm32_enuminterrupt * * Description: * Enumeration done interrupt * ****************************************************************************/ static inline void stm32_enuminterrupt(FAR struct stm32_usbdev_s *priv) { uint32_t regval; /* Activate EP0 */ stm32_ep0in_activate(); /* Set USB turn-around time for the full speed device with internal PHY interface. */ regval = stm32_getreg(STM32_OTGHS_GUSBCFG); regval &= ~OTGHS_GUSBCFG_TRDT_MASK; regval |= OTGHS_GUSBCFG_TRDT(5); stm32_putreg(regval, STM32_OTGHS_GUSBCFG); } /**************************************************************************** * Name: stm32_isocininterrupt * * Description: * Incomplete isochronous IN transfer interrupt. Assertion of the incomplete * isochronous IN transfer interrupt indicates an incomplete isochronous IN * transfer on at least one of the isochronous IN endpoints. * ****************************************************************************/ #ifdef CONFIG_USBDEV_ISOCHRONOUS static inline void stm32_isocininterrupt(FAR struct stm32_usbdev_s *priv) { int i; /* The application must read the endpoint control register for all isochronous * IN endpoints to detect endpoints with incomplete IN data transfers. */ for (i = 0; i < STM32_NENDPOINTS; i++) { /* Is this an isochronous IN endpoint? */ privep = &priv->epin[i]; if (privep->eptype != USB_EP_ATTR_XFER_ISOC) { /* No... keep looking */ continue; } /* Is there an active read request on the isochronous OUT endpoint? */ if (!privep->active) { /* No.. the endpoint is not actively transmitting data */ continue; } /* Check if this is the endpoint that had the incomplete transfer */ regaddr = STM32_OTGHS_DIEPCTL(privep->epphy); doepctl = stm32_getreg(regaddr); dsts = stm32_getreg(STM32_OTGHS_DSTS); /* EONUM = 0:even frame, 1:odd frame * SOFFN = Frame number of the received SOF */ eonum = ((doepctl & OTGHS_DIEPCTL_EONUM) != 0); soffn = ((dsts & OTGHS_DSTS_SOFFN0) != 0); if (eonum != soffn) { /* Not this endpoint */ continue; } /* For isochronous IN endpoints with incomplete transfers, * the application must discard the data in the memory and * disable the endpoint. */ stm32_req_complete(privep, -EIO); #warning "Will clear OTGHS_DIEPCTL_USBAEP too" stm32_epin_disable(privep); break; } } #endif /**************************************************************************** * Name: stm32_isocoutinterrupt * * Description: * Incomplete periodic transfer interrupt * ****************************************************************************/ #ifdef CONFIG_USBDEV_ISOCHRONOUS static inline void stm32_isocoutinterrupt(FAR struct stm32_usbdev_s *priv) { FAR struct stm32_ep_s *privep; FAR struct stm32_req_s *privreq; uint32_t regaddr; uint32_t doepctl; uint32_t dsts; bool eonum; bool soffn; /* When it receives an IISOOXFR interrupt, the application must read the * control registers of all isochronous OUT endpoints to determine which * endpoints had an incomplete transfer in the current microframe. An * endpoint transfer is incomplete if both the following conditions are true: * * DOEPCTLx:EONUM = DSTS:SOFFN[0], and * DOEPCTLx:EPENA = 1 */ for (i = 0; i < STM32_NENDPOINTS; i++) { /* Is this an isochronous OUT endpoint? */ privep = &priv->epout[i]; if (privep->eptype != USB_EP_ATTR_XFER_ISOC) { /* No... keep looking */ continue; } /* Is there an active read request on the isochronous OUT endpoint? */ if (!privep->active) { /* No.. the endpoint is not actively transmitting data */ continue; } /* Check if this is the endpoint that had the incomplete transfer */ regaddr = STM32_OTGHS_DOEPCTL(privep->epphy); doepctl = stm32_getreg(regaddr); dsts = stm32_getreg(STM32_OTGHS_DSTS); /* EONUM = 0:even frame, 1:odd frame * SOFFN = Frame number of the received SOF */ eonum = ((doepctl & OTGHS_DOEPCTL_EONUM) != 0); soffn = ((dsts & OTGHS_DSTS_SOFFN0) != 0); if (eonum != soffn) { /* Not this endpoint */ continue; } /* For isochronous OUT endpoints with incomplete transfers, * the application must discard the data in the memory and * disable the endpoint. */ stm32_req_complete(privep, -EIO); #warning "Will clear OTGHS_DOEPCTL_USBAEP too" stm32_epout_disable(privep); break; } } #endif /**************************************************************************** * Name: stm32_sessioninterrupt * * Description: * Session request/new session detected interrupt * ****************************************************************************/ #ifdef CONFIG_USBDEV_VBUSSENSING static inline void stm32_sessioninterrupt(FAR struct stm32_usbdev_s *priv) { #warning "Missing logic" } #endif /**************************************************************************** * Name: stm32_otginterrupt * * Description: * OTG interrupt * ****************************************************************************/ #ifdef CONFIG_USBDEV_VBUSSENSING static inline void stm32_otginterrupt(FAR struct stm32_usbdev_s *priv) { uint32_t regval; /* Check for session end detected */ regval = stm32_getreg(STM32_OTGHS_GOTGINT); if ((regval & OTGHS_GOTGINT_SEDET) != 0) { #warning "Missing logic" } /* Clear OTG interrupt */ stm32_putreg(retval, STM32_OTGHS_GOTGINT); } #endif /**************************************************************************** * Name: stm32_usbinterrupt * * Description: * USB interrupt handler * ****************************************************************************/ static int stm32_usbinterrupt(int irq, FAR void *context, FAR void *arg) { /* At present, there is only a single OTG HS device support. Hence it is * pre-allocated as g_otghsdev. However, in most code, the private data * structure will be referenced using the 'priv' pointer (rather than the * global data) in order to simplify any future support for multiple devices. */ FAR struct stm32_usbdev_s *priv = &g_otghsdev; uint32_t regval; usbtrace(TRACE_INTENTRY(STM32_TRACEINTID_USB), 0); /* Assure that we are in device mode */ DEBUGASSERT((stm32_getreg(STM32_OTGHS_GINTSTS) & OTGHS_GINTSTS_CMOD) == OTGHS_GINTSTS_DEVMODE); /* Get the state of all enabled interrupts. We will do this repeatedly * some interrupts (like RXFLVL) will generate additional interrupting * events. */ for (; ; ) { /* Get the set of pending, un-masked interrupts */ regval = stm32_getreg(STM32_OTGHS_GINTSTS); regval &= stm32_getreg(STM32_OTGHS_GINTMSK); /* Break out of the loop when there are no further pending (and * unmasked) interrupts to be processes. */ if (regval == 0) { break; } usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_INTPENDING), (uint16_t)regval); /* OUT endpoint interrupt. The core sets this bit to indicate that an * interrupt is pending on one of the OUT endpoints of the core. */ if ((regval & OTGHS_GINT_OEP) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPOUT), (uint16_t)regval); stm32_epout_interrupt(priv); stm32_putreg(OTGHS_GINT_OEP, STM32_OTGHS_GINTSTS); } /* IN endpoint interrupt. The core sets this bit to indicate that * an interrupt is pending on one of the IN endpoints of the core. */ if ((regval & OTGHS_GINT_IEP) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_EPIN), (uint16_t)regval); stm32_epin_interrupt(priv); stm32_putreg(OTGHS_GINT_IEP, STM32_OTGHS_GINTSTS); } /* Host/device mode mismatch error interrupt */ #ifdef CONFIG_DEBUG_USB if ((regval & OTGHS_GINT_MMIS) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_MISMATCH), (uint16_t)regval); stm32_putreg(OTGHS_GINT_MMIS, STM32_OTGHS_GINTSTS); } #endif /* Resume/remote wakeup detected interrupt */ if ((regval & OTGHS_GINT_WKUP) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_WAKEUP), (uint16_t)regval); stm32_resumeinterrupt(priv); stm32_putreg(OTGHS_GINT_WKUP, STM32_OTGHS_GINTSTS); } /* USB suspend interrupt */ if ((regval & OTGHS_GINT_USBSUSP) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SUSPEND), (uint16_t)regval); stm32_suspendinterrupt(priv); stm32_putreg(OTGHS_GINT_USBSUSP, STM32_OTGHS_GINTSTS); } /* Start of frame interrupt */ #ifdef CONFIG_USBDEV_SOFINTERRUPT if ((regval & OTGHS_GINT_SOF) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SOF), (uint16_t)regval); stm32_putreg(OTGHS_GINT_SOF, STM32_OTGHS_GINTSTS); } #endif /* RxFIFO non-empty interrupt. Indicates that there is at least one * packet pending to be read from the RxFIFO. */ if ((regval & OTGHS_GINT_RXFLVL) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_RXFIFO), (uint16_t)regval); stm32_rxinterrupt(priv); stm32_putreg(OTGHS_GINT_RXFLVL, STM32_OTGHS_GINTSTS); } /* USB reset interrupt */ if ((regval & OTGHS_GINT_USBRST) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_DEVRESET), (uint16_t)regval); /* Perform the device reset */ stm32_usbreset(priv); usbtrace(TRACE_INTEXIT(STM32_TRACEINTID_USB), 0); stm32_putreg(OTGHS_GINT_USBRST, STM32_OTGHS_GINTSTS); return OK; } /* Enumeration done interrupt */ if ((regval & OTGHS_GINT_ENUMDNE) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_ENUMDNE), (uint16_t)regval); stm32_enuminterrupt(priv); stm32_putreg(OTGHS_GINT_ENUMDNE, STM32_OTGHS_GINTSTS); } /* Incomplete isochronous IN transfer interrupt. When the core finds * non-empty any of the isochronous IN endpoint FIFOs scheduled for * the current frame non-empty, the core generates an IISOIXFR * interrupt. */ #ifdef CONFIG_USBDEV_ISOCHRONOUS if ((regval & OTGHS_GINT_IISOIXFR) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_IISOIXFR), (uint16_t)regval); stm32_isocininterrupt(priv); stm32_putreg(OTGHS_GINT_IISOIXFR, STM32_OTGHS_GINTSTS); } /* Incomplete isochronous OUT transfer. For isochronous OUT * endpoints, the XFRC interrupt may not always be asserted. If the * core drops isochronous OUT data packets, the application could fail * to detect the XFRC interrupt. The incomplete Isochronous OUT data * interrupt indicates that an XFRC interrupt was not asserted on at * least one of the isochronous OUT endpoints. At this point, the * endpoint with the incomplete transfer remains enabled, but no active * transfers remain in progress on this endpoint on the USB. */ if ((regval & OTGHS_GINT_IISOOXFR) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_IISOOXFR), (uint16_t)regval); stm32_isocoutinterrupt(priv); stm32_putreg(OTGHS_GINT_IISOOXFR, STM32_OTGHS_GINTSTS); } #endif /* Session request/new session detected interrupt */ #ifdef CONFIG_USBDEV_VBUSSENSING if ((regval & OTGHS_GINT_SRQ) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_SRQ), (uint16_t)regval); stm32_sessioninterrupt(priv); stm32_putreg(OTGHS_GINT_SRQ, STM32_OTGHS_GINTSTS); } /* OTG interrupt */ if ((regval & OTGHS_GINT_OTG) != 0) { usbtrace(TRACE_INTDECODE(STM32_TRACEINTID_OTG), (uint16_t)regval); stm32_otginterrupt(priv); stm32_putreg(OTGHS_GINT_OTG, STM32_OTGHS_GINTSTS); } #endif } usbtrace(TRACE_INTEXIT(STM32_TRACEINTID_USB), 0); return OK; } /**************************************************************************** * Endpoint operations ****************************************************************************/ /**************************************************************************** * Name: stm32_enablegonak * * Description: * Enable global OUT NAK mode * ****************************************************************************/ static void stm32_enablegonak(FAR struct stm32_ep_s *privep) { uint32_t regval; /* First, make sure that there is no GNOAKEFF interrupt pending. */ #if 0 stm32_putreg(OTGHS_GINT_GONAKEFF, STM32_OTGHS_GINTSTS); #endif /* Enable Global OUT NAK mode in the core. */ regval = stm32_getreg(STM32_OTGHS_DCTL); regval |= OTGHS_DCTL_SGONAK; stm32_putreg(regval, STM32_OTGHS_DCTL); #if 0 /* Wait for the GONAKEFF interrupt that indicates that the OUT NAK * mode is in effect. When the interrupt handler pops the OUTNAK word * from the RxFIFO, the core sets the GONAKEFF interrupt. */ while ((stm32_getreg(STM32_OTGHS_GINTSTS) & OTGHS_GINT_GONAKEFF) == 0); stm32_putreg(OTGHS_GINT_GONAKEFF, STM32_OTGHS_GINTSTS); #else /* Since we are in the interrupt handler, we cannot wait inline for the * GONAKEFF because it cannot occur until service the RXFLVL global interrupt * and pop the OUTNAK word from the RxFIFO. * * Perhaps it is sufficient to wait for Global OUT NAK status to be reported * in OTGHS DCTL register? */ while ((stm32_getreg(STM32_OTGHS_DCTL) & OTGHS_DCTL_GONSTS) == 0); #endif } /**************************************************************************** * Name: stm32_disablegonak * * Description: * Disable global OUT NAK mode * ****************************************************************************/ static void stm32_disablegonak(FAR struct stm32_ep_s *privep) { uint32_t regval; /* Set the "Clear the Global OUT NAK bit" to disable global OUT NAK mode */ regval = stm32_getreg(STM32_OTGHS_DCTL); regval |= OTGHS_DCTL_CGONAK; stm32_putreg(regval, STM32_OTGHS_DCTL); } /**************************************************************************** * Name: stm32_epout_configure * * Description: * Configure an OUT endpoint, making it usable * * Input Parameters: * privep - a pointer to an internal endpoint structure * eptype - The type of the endpoint * maxpacket - The max packet size of the endpoint * ****************************************************************************/ static int stm32_epout_configure(FAR struct stm32_ep_s *privep, uint8_t eptype, uint16_t maxpacket) { uint32_t mpsiz; uint32_t regaddr; uint32_t regval; usbtrace(TRACE_EPCONFIGURE, privep->epphy); /* For EP0, the packet size is encoded */ if (privep->epphy == EP0) { DEBUGASSERT(eptype == USB_EP_ATTR_XFER_CONTROL); /* Map the size in bytes to the encoded value in the register */ switch (maxpacket) { case 8: mpsiz = OTGHS_DOEPCTL0_MPSIZ_8; break; case 16: mpsiz = OTGHS_DOEPCTL0_MPSIZ_16; break; case 32: mpsiz = OTGHS_DOEPCTL0_MPSIZ_32; break; case 64: mpsiz = OTGHS_DOEPCTL0_MPSIZ_64; break; default: uerr("ERROR: Unsupported maxpacket: %d\n", maxpacket); return -EINVAL; } } /* For other endpoints, the packet size is in bytes */ else { mpsiz = (maxpacket << OTGHS_DOEPCTL_MPSIZ_SHIFT); } /* If the endpoint is already active don't change the endpoint control * register. */ regaddr = STM32_OTGHS_DOEPCTL(privep->epphy); regval = stm32_getreg(regaddr); if ((regval & OTGHS_DOEPCTL_USBAEP) == 0) { if (regval & OTGHS_DOEPCTL_NAKSTS) { regval |= OTGHS_DOEPCTL_CNAK; } regval &= ~(OTGHS_DOEPCTL_MPSIZ_MASK | OTGHS_DOEPCTL_EPTYP_MASK); regval |= mpsiz; regval |= (eptype << OTGHS_DOEPCTL_EPTYP_SHIFT); regval |= (OTGHS_DOEPCTL_SD0PID | OTGHS_DOEPCTL_USBAEP); stm32_putreg(regval, regaddr); /* Save the endpoint configuration */ privep->ep.maxpacket = maxpacket; privep->eptype = eptype; privep->stalled = false; } /* Enable the interrupt for this endpoint */ regval = stm32_getreg(STM32_OTGHS_DAINTMSK); regval |= OTGHS_DAINT_OEP(privep->epphy); stm32_putreg(regval, STM32_OTGHS_DAINTMSK); return OK; } /**************************************************************************** * Name: stm32_epin_configure * * Description: * Configure an IN endpoint, making it usable * * Input Parameters: * privep - a pointer to an internal endpoint structure * eptype - The type of the endpoint * maxpacket - The max packet size of the endpoint * ****************************************************************************/ static int stm32_epin_configure(FAR struct stm32_ep_s *privep, uint8_t eptype, uint16_t maxpacket) { uint32_t mpsiz; uint32_t regaddr; uint32_t regval; usbtrace(TRACE_EPCONFIGURE, privep->epphy); /* For EP0, the packet size is encoded */ if (privep->epphy == EP0) { DEBUGASSERT(eptype == USB_EP_ATTR_XFER_CONTROL); /* Map the size in bytes to the encoded value in the register */ switch (maxpacket) { case 8: mpsiz = OTGHS_DIEPCTL0_MPSIZ_8; break; case 16: mpsiz = OTGHS_DIEPCTL0_MPSIZ_16; break; case 32: mpsiz = OTGHS_DIEPCTL0_MPSIZ_32; break; case 64: mpsiz = OTGHS_DIEPCTL0_MPSIZ_64; break; default: uerr("ERROR: Unsupported maxpacket: %d\n", maxpacket); return -EINVAL; } } /* For other endpoints, the packet size is in bytes */ else { mpsiz = (maxpacket << OTGHS_DIEPCTL_MPSIZ_SHIFT); } /* If the endpoint is already active don't change the endpoint control * register. */ regaddr = STM32_OTGHS_DIEPCTL(privep->epphy); regval = stm32_getreg(regaddr); if ((regval & OTGHS_DIEPCTL_USBAEP) == 0) { if (regval & OTGHS_DIEPCTL_NAKSTS) { regval |= OTGHS_DIEPCTL_CNAK; } regval &= ~(OTGHS_DIEPCTL_MPSIZ_MASK | OTGHS_DIEPCTL_EPTYP_MASK | OTGHS_DIEPCTL_TXFNUM_MASK); regval |= mpsiz; regval |= (eptype << OTGHS_DIEPCTL_EPTYP_SHIFT); regval |= (eptype << OTGHS_DIEPCTL_TXFNUM_SHIFT); regval |= (OTGHS_DIEPCTL_SD0PID | OTGHS_DIEPCTL_USBAEP); stm32_putreg(regval, regaddr); /* Save the endpoint configuration */ privep->ep.maxpacket = maxpacket; privep->eptype = eptype; privep->stalled = false; } /* Enable the interrupt for this endpoint */ regval = stm32_getreg(STM32_OTGHS_DAINTMSK); regval |= OTGHS_DAINT_IEP(privep->epphy); stm32_putreg(regval, STM32_OTGHS_DAINTMSK); return OK; } /**************************************************************************** * Name: stm32_ep_configure * * Description: * Configure endpoint, making it usable * * Input Parameters: * ep - the struct usbdev_ep_s instance obtained from allocep() * desc - A struct usb_epdesc_s instance describing the endpoint * last - true if this this last endpoint to be configured. Some hardware * needs to take special action when all of the endpoints have been * configured. * ****************************************************************************/ static int stm32_ep_configure(FAR struct usbdev_ep_s *ep, FAR const struct usb_epdesc_s *desc, bool last) { FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep; uint16_t maxpacket; uint8_t eptype; int ret; usbtrace(TRACE_EPCONFIGURE, privep->epphy); DEBUGASSERT(desc->addr == ep->eplog); /* Initialize EP capabilities */ maxpacket = GETUINT16(desc->mxpacketsize); eptype = desc->attr & USB_EP_ATTR_XFERTYPE_MASK; /* Setup Endpoint Control Register */ if (privep->isin) { ret = stm32_epin_configure(privep, eptype, maxpacket); } else { ret = stm32_epout_configure(privep, eptype, maxpacket); } return ret; } /**************************************************************************** * Name: stm32_ep0_configure * * Description: * Reset Usb engine * ****************************************************************************/ static void stm32_ep0_configure(FAR struct stm32_usbdev_s *priv) { /* Enable EP0 IN and OUT */ (void)stm32_epin_configure(&priv->epin[EP0], USB_EP_ATTR_XFER_CONTROL, CONFIG_USBDEV_EP0_MAXSIZE); (void)stm32_epout_configure(&priv->epout[EP0], USB_EP_ATTR_XFER_CONTROL, CONFIG_USBDEV_EP0_MAXSIZE); } /**************************************************************************** * Name: stm32_epout_disable * * Description: * Diable an OUT endpoint will no longer be used * ****************************************************************************/ static void stm32_epout_disable(FAR struct stm32_ep_s *privep) { uint32_t regaddr; uint32_t regval; irqstate_t flags; usbtrace(TRACE_EPDISABLE, privep->epphy); /* Is this an IN or an OUT endpoint */ /* Before disabling any OUT endpoint, the application must enable * Global OUT NAK mode in the core. */ flags = enter_critical_section(); stm32_enablegonak(privep); /* Disable the required OUT endpoint by setting the EPDIS and SNAK bits * int DOECPTL register. */ regaddr = STM32_OTGHS_DOEPCTL(privep->epphy); regval = stm32_getreg(regaddr); regval &= ~OTGHS_DOEPCTL_USBAEP; regval |= (OTGHS_DOEPCTL_EPDIS | OTGHS_DOEPCTL_SNAK); stm32_putreg(regval, regaddr); /* Wait for the EPDISD interrupt which indicates that the OUT * endpoint is completely disabled. */ #if 0 /* Doesn't happen */ regaddr = STM32_OTGHS_DOEPINT(privep->epphy); while ((stm32_getreg(regaddr) & OTGHS_DOEPINT_EPDISD) == 0); #else /* REVISIT: */ up_udelay(10); #endif /* Clear the EPDISD interrupt indication */ stm32_putreg(OTGHS_DOEPINT_EPDISD, STM32_OTGHS_DOEPINT(privep->epphy)); /* Then disable the Global OUT NAK mode to continue receiving data * from other non-disabled OUT endpoints. */ stm32_disablegonak(privep); /* Disable endpoint interrupts */ regval = stm32_getreg(STM32_OTGHS_DAINTMSK); regval &= ~OTGHS_DAINT_OEP(privep->epphy); stm32_putreg(regval, STM32_OTGHS_DAINTMSK); /* Cancel any queued read requests */ stm32_req_cancel(privep, -ESHUTDOWN); leave_critical_section(flags); } /**************************************************************************** * Name: stm32_epin_disable * * Description: * Disable an IN endpoint when it will no longer be used * ****************************************************************************/ static void stm32_epin_disable(FAR struct stm32_ep_s *privep) { uint32_t regaddr; uint32_t regval; irqstate_t flags; usbtrace(TRACE_EPDISABLE, privep->epphy); /* After USB reset, the endpoint will already be deactivated by the * hardware. Trying to disable again will just hang in the wait. */ regaddr = STM32_OTGHS_DIEPCTL(privep->epphy); regval = stm32_getreg(regaddr); if ((regval & OTGHS_DIEPCTL_USBAEP) == 0) { return; } /* This INEPNE wait logic is suggested by reference manual, but seems * to get stuck to infinite loop. */ #if 0 /* Make sure that there is no pending IPEPNE interrupt (because we are * to poll this bit below). */ stm32_putreg(OTGHS_DIEPINT_INEPNE, STM32_OTGHS_DIEPINT(privep->epphy)); /* Set the endpoint in NAK mode */ regaddr = STM32_OTGHS_DIEPCTL(privep->epphy); regval = stm32_getreg(regaddr); regval &= ~OTGHS_DIEPCTL_USBAEP; regval |= (OTGHS_DIEPCTL_EPDIS | OTGHS_DIEPCTL_SNAK); stm32_putreg(regval, regaddr); /* Wait for the INEPNE interrupt that indicates that we are now in NAK mode */ regaddr = STM32_OTGHS_DIEPINT(privep->epphy); while ((stm32_getreg(regaddr) & OTGHS_DIEPINT_INEPNE) == 0); /* Clear the INEPNE interrupt indication */ stm32_putreg(OTGHS_DIEPINT_INEPNE, regaddr); #endif /* Deactivate and disable the endpoint by setting the EPDIS and SNAK bits * the DIEPCTLx register. */ flags = enter_critical_section(); regaddr = STM32_OTGHS_DIEPCTL(privep->epphy); regval = stm32_getreg(regaddr); regval &= ~OTGHS_DIEPCTL_USBAEP; regval |= (OTGHS_DIEPCTL_EPDIS | OTGHS_DIEPCTL_SNAK); stm32_putreg(regval, regaddr); /* Wait for the EPDISD interrupt which indicates that the IN * endpoint is completely disabled. */ regaddr = STM32_OTGHS_DIEPINT(privep->epphy); while ((stm32_getreg(regaddr) & OTGHS_DIEPINT_EPDISD) == 0); /* Clear the EPDISD interrupt indication */ stm32_putreg(OTGHS_DIEPINT_EPDISD, stm32_getreg(regaddr)); /* Flush any data remaining in the TxFIFO */ stm32_txfifo_flush(OTGHS_GRSTCTL_TXFNUM_D(privep->epphy)); /* Disable endpoint interrupts */ regval = stm32_getreg(STM32_OTGHS_DAINTMSK); regval &= ~OTGHS_DAINT_IEP(privep->epphy); stm32_putreg(regval, STM32_OTGHS_DAINTMSK); /* Cancel any queued write requests */ stm32_req_cancel(privep, -ESHUTDOWN); leave_critical_section(flags); } /**************************************************************************** * Name: stm32_ep_disable * * Description: * The endpoint will no longer be used * ****************************************************************************/ static int stm32_ep_disable(FAR struct usbdev_ep_s *ep) { FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep; #ifdef CONFIG_DEBUG_FEATURES if (!ep) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0); return -EINVAL; } #endif usbtrace(TRACE_EPDISABLE, privep->epphy); /* Is this an IN or an OUT endpoint */ if (privep->isin) { /* Disable the IN endpoint */ stm32_epin_disable(privep); } else { /* Disable the OUT endpoint */ stm32_epout_disable(privep); } return OK; } /**************************************************************************** * Name: stm32_ep_allocreq * * Description: * Allocate an I/O request * ****************************************************************************/ static FAR struct usbdev_req_s *stm32_ep_allocreq(FAR struct usbdev_ep_s *ep) { FAR struct stm32_req_s *privreq; #ifdef CONFIG_DEBUG_FEATURES if (!ep) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0); return NULL; } #endif usbtrace(TRACE_EPALLOCREQ, ((FAR struct stm32_ep_s *)ep)->epphy); privreq = (FAR struct stm32_req_s *)kmm_malloc(sizeof(struct stm32_req_s)); if (!privreq) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_ALLOCFAIL), 0); return NULL; } memset(privreq, 0, sizeof(struct stm32_req_s)); return &privreq->req; } /**************************************************************************** * Name: stm32_ep_freereq * * Description: * Free an I/O request * ****************************************************************************/ static void stm32_ep_freereq(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req) { FAR struct stm32_req_s *privreq = (FAR struct stm32_req_s *)req; #ifdef CONFIG_DEBUG_FEATURES if (!ep || !req) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0); return; } #endif usbtrace(TRACE_EPFREEREQ, ((FAR struct stm32_ep_s *)ep)->epphy); kmm_free(privreq); } /**************************************************************************** * Name: stm32_ep_allocbuffer * * Description: * Allocate an I/O buffer * ****************************************************************************/ #ifdef CONFIG_USBDEV_DMA static void *stm32_ep_allocbuffer(FAR struct usbdev_ep_s *ep, unsigned bytes) { usbtrace(TRACE_EPALLOCBUFFER, privep->epphy); #ifdef CONFIG_USBDEV_DMAMEMORY return usbdev_dma_alloc(bytes); #else return kmm_malloc(bytes); #endif } #endif /**************************************************************************** * Name: stm32_ep_freebuffer * * Description: * Free an I/O buffer * ****************************************************************************/ #ifdef CONFIG_USBDEV_DMA static void stm32_ep_freebuffer(FAR struct usbdev_ep_s *ep, FAR void *buf) { usbtrace(TRACE_EPFREEBUFFER, privep->epphy); #ifdef CONFIG_USBDEV_DMAMEMORY usbdev_dma_free(buf); #else kmm_free(buf); #endif } #endif /**************************************************************************** * Name: stm32_ep_submit * * Description: * Submit an I/O request to the endpoint * ****************************************************************************/ static int stm32_ep_submit(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req) { FAR struct stm32_req_s *privreq = (FAR struct stm32_req_s *)req; FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep; FAR struct stm32_usbdev_s *priv; irqstate_t flags; int ret = OK; /* Some sanity checking */ #ifdef CONFIG_DEBUG_FEATURES if (!req || !req->callback || !req->buf || !ep) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0); uinfo("req=%p callback=%p buf=%p ep=%p\n", req, req->callback, req->buf, ep); return -EINVAL; } #endif usbtrace(TRACE_EPSUBMIT, privep->epphy); priv = privep->dev; #ifdef CONFIG_DEBUG_FEATURES if (!priv->driver) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_NOTCONFIGURED), priv->usbdev.speed); return -ESHUTDOWN; } #endif /* Handle the request from the class driver */ req->result = -EINPROGRESS; req->xfrd = 0; /* Disable Interrupts */ flags = enter_critical_section(); /* If we are stalled, then drop all requests on the floor */ if (privep->stalled) { ret = -EBUSY; } else { /* Add the new request to the request queue for the endpoint. */ if (stm32_req_addlast(privep, privreq) && !privep->active) { /* If a request was added to an IN endpoint, then attempt to send * the request data buffer now. */ if (privep->isin) { usbtrace(TRACE_INREQQUEUED(privep->epphy), privreq->req.len); /* If the endpoint is not busy with another write request, * then process the newly received write request now. */ if (!privep->active) { stm32_epin_request(priv, privep); } } /* If the request was added to an OUT endpoint, then attempt to * setup a read into the request data buffer now (this will, of * course, fail if there is already a read in place). */ else { usbtrace(TRACE_OUTREQQUEUED(privep->epphy), privreq->req.len); stm32_epout_request(priv, privep); } } } leave_critical_section(flags); return ret; } /**************************************************************************** * Name: stm32_ep_cancel * * Description: * Cancel an I/O request previously sent to an endpoint * ****************************************************************************/ static int stm32_ep_cancel(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req) { FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep; irqstate_t flags; #ifdef CONFIG_DEBUG_FEATURES if (!ep || !req) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0); return -EINVAL; } #endif usbtrace(TRACE_EPCANCEL, privep->epphy); flags = enter_critical_section(); /* FIXME: if the request is the first, then we need to flush the EP * otherwise just remove it from the list * * but ... all other implementations cancel all requests ... */ stm32_req_cancel(privep, -ESHUTDOWN); leave_critical_section(flags); return OK; } /**************************************************************************** * Name: stm32_epout_setstall * * Description: * Stall an OUT endpoint * ****************************************************************************/ static int stm32_epout_setstall(FAR struct stm32_ep_s *privep) { #if 1 /* This implementation follows the requirements from the STM32 F4 reference * manual. */ uint32_t regaddr; uint32_t regval; /* Put the core in the Global OUT NAK mode */ stm32_enablegonak(privep); /* Disable and STALL the OUT endpoint by setting the EPDIS and STALL bits * in the DOECPTL register. */ regaddr = STM32_OTGHS_DOEPCTL(privep->epphy); regval = stm32_getreg(regaddr); regval |= (OTGHS_DOEPCTL_EPDIS | OTGHS_DOEPCTL_STALL); stm32_putreg(regval, regaddr); /* Wait for the EPDISD interrupt which indicates that the OUT * endpoint is completely disabled. */ #if 0 /* Doesn't happen */ regaddr = STM32_OTGHS_DOEPINT(privep->epphy); while ((stm32_getreg(regaddr) & OTGHS_DOEPINT_EPDISD) == 0); #else /* REVISIT: */ up_udelay(10); #endif /* Disable Global OUT NAK mode */ stm32_disablegonak(privep); /* The endpoint is now stalled */ privep->stalled = true; return OK; #else /* This implementation follows the STMicro code example. */ /* REVISIT: */ uint32_t regaddr; uint32_t regval; /* Stall the OUT endpoint by setting the STALL bit in the DOECPTL register. */ regaddr = STM32_OTGHS_DOEPCTL(privep->epphy); regval = stm32_getreg(regaddr); regval |= OTGHS_DOEPCTL_STALL; stm32_putreg(regval, regaddr); /* The endpoint is now stalled */ privep->stalled = true; return OK; #endif } /**************************************************************************** * Name: stm32_epin_setstall * * Description: * Stall an IN endpoint * ****************************************************************************/ static int stm32_epin_setstall(FAR struct stm32_ep_s *privep) { uint32_t regaddr; uint32_t regval; /* Get the IN endpoint device control register */ regaddr = STM32_OTGHS_DIEPCTL(privep->epphy); regval = stm32_getreg(regaddr); /* Then stall the endpoint */ regval |= OTGHS_DIEPCTL_STALL; stm32_putreg(regval, regaddr); /* The endpoint is now stalled */ privep->stalled = true; return OK; } /**************************************************************************** * Name: stm32_ep_setstall * * Description: * Stall an endpoint * ****************************************************************************/ static int stm32_ep_setstall(FAR struct stm32_ep_s *privep) { usbtrace(TRACE_EPSTALL, privep->epphy); /* Is this an IN endpoint? */ if (privep->isin == 1) { return stm32_epin_setstall(privep); } else { return stm32_epout_setstall(privep); } } /**************************************************************************** * Name: stm32_ep_clrstall * * Description: * Resume a stalled endpoint * ****************************************************************************/ static int stm32_ep_clrstall(FAR struct stm32_ep_s *privep) { uint32_t regaddr; uint32_t regval; uint32_t stallbit; uint32_t data0bit; usbtrace(TRACE_EPRESUME, privep->epphy); /* Is this an IN endpoint? */ if (privep->isin == 1) { /* Clear the stall bit in the IN endpoint device control register */ regaddr = STM32_OTGHS_DIEPCTL(privep->epphy); stallbit = OTGHS_DIEPCTL_STALL; data0bit = OTGHS_DIEPCTL_SD0PID; } else { /* Clear the stall bit in the IN endpoint device control register */ regaddr = STM32_OTGHS_DOEPCTL(privep->epphy); stallbit = OTGHS_DOEPCTL_STALL; data0bit = OTGHS_DOEPCTL_SD0PID; } /* Clear the stall bit */ regval = stm32_getreg(regaddr); regval &= ~stallbit; /* Set the DATA0 pid for interrupt and bulk endpoints */ if (privep->eptype == USB_EP_ATTR_XFER_INT || privep->eptype == USB_EP_ATTR_XFER_BULK) { /* Writing this bit sets the DATA0 PID */ regval |= data0bit; } stm32_putreg(regval, regaddr); /* The endpoint is no longer stalled */ privep->stalled = false; return OK; } /**************************************************************************** * Name: stm32_ep_stall * * Description: * Stall or resume an endpoint * ****************************************************************************/ static int stm32_ep_stall(FAR struct usbdev_ep_s *ep, bool resume) { FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep; irqstate_t flags; int ret; /* Set or clear the stall condition as requested */ flags = enter_critical_section(); if (resume) { ret = stm32_ep_clrstall(privep); } else { ret = stm32_ep_setstall(privep); } leave_critical_section(flags); return ret; } /**************************************************************************** * Name: stm32_ep0_stall * * Description: * Stall endpoint 0 * ****************************************************************************/ static void stm32_ep0_stall(FAR struct stm32_usbdev_s *priv) { stm32_epin_setstall(&priv->epin[EP0]); stm32_epout_setstall(&priv->epout[EP0]); priv->stalled = true; stm32_ep0out_ctrlsetup(priv); } /**************************************************************************** * Device operations ****************************************************************************/ /**************************************************************************** * Name: stm32_ep_alloc * * Description: * Allocate an endpoint matching the parameters. * * Input Parameters: * eplog - 7-bit logical endpoint number (direction bit ignored). Zero means * that any endpoint matching the other requirements will suffice. The * assigned endpoint can be found in the eplog field. * in - true: IN (device-to-host) endpoint requested * eptype - Endpoint type. One of {USB_EP_ATTR_XFER_ISOC, USB_EP_ATTR_XFER_BULK, * USB_EP_ATTR_XFER_INT} * ****************************************************************************/ static FAR struct usbdev_ep_s *stm32_ep_alloc(FAR struct usbdev_s *dev, uint8_t eplog, bool in, uint8_t eptype) { FAR struct stm32_usbdev_s *priv = (FAR struct stm32_usbdev_s *)dev; uint8_t epavail; irqstate_t flags; int epphy; int epno = 0; usbtrace(TRACE_DEVALLOCEP, (uint16_t)eplog); /* Ignore any direction bits in the logical address */ epphy = USB_EPNO(eplog); /* Get the set of available endpoints depending on the direction */ flags = enter_critical_section(); epavail = priv->epavail[in]; /* A physical address of 0 means that any endpoint will do */ if (epphy > 0) { /* Otherwise, we will return the endpoint structure only for the requested * 'logical' endpoint. All of the other checks will still be performed. * * First, verify that the logical endpoint is in the range supported by * by the hardware. */ if (epphy >= STM32_NENDPOINTS) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BADEPNO), (uint16_t)epphy); return NULL; } /* Remove all of the candidate endpoints from the bitset except for the * this physical endpoint number. */ epavail &= (1 << epphy); } /* Is there an available endpoint? */ if (epavail) { /* Yes.. Select the lowest numbered endpoint in the set of available * endpoints. */ for (epno = 1; epno < STM32_NENDPOINTS; epno++) { uint8_t bit = 1 << epno; if ((epavail & bit) != 0) { /* Mark the endpoint no longer available */ priv->epavail[in] &= ~(1 << epno); /* And return the pointer to the standard endpoint structure */ leave_critical_section(flags); return in ? &priv->epin[epno].ep : &priv->epout[epno].ep; } } /* We should not get here */ } usbtrace(TRACE_DEVERROR(STM32_TRACEERR_NOEP), (uint16_t)eplog); leave_critical_section(flags); return NULL; } /**************************************************************************** * Name: stm32_ep_free * * Description: * Free the previously allocated endpoint * ****************************************************************************/ static void stm32_ep_free(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep) { FAR struct stm32_usbdev_s *priv = (FAR struct stm32_usbdev_s *)dev; FAR struct stm32_ep_s *privep = (FAR struct stm32_ep_s *)ep; irqstate_t flags; usbtrace(TRACE_DEVFREEEP, (uint16_t)privep->epphy); if (priv && privep) { /* Mark the endpoint as available */ flags = enter_critical_section(); priv->epavail[privep->isin] |= (1 << privep->epphy); leave_critical_section(flags); } } /**************************************************************************** * Name: stm32_getframe * * Description: * Returns the current frame number * ****************************************************************************/ static int stm32_getframe(struct usbdev_s *dev) { uint32_t regval; usbtrace(TRACE_DEVGETFRAME, 0); /* Return the last frame number of the last SOF detected by the hardware */ regval = stm32_getreg(STM32_OTGHS_DSTS); return (int)((regval & OTGHS_DSTS_SOFFN_MASK) >> OTGHS_DSTS_SOFFN_SHIFT); } /**************************************************************************** * Name: stm32_wakeup * * Description: * Exit suspend mode. * ****************************************************************************/ static int stm32_wakeup(struct usbdev_s *dev) { FAR struct stm32_usbdev_s *priv = (FAR struct stm32_usbdev_s *)dev; uint32_t regval; irqstate_t flags; usbtrace(TRACE_DEVWAKEUP, 0); /* Is wakeup enabled? */ flags = enter_critical_section(); if (priv->wakeup) { /* Yes... is the core suspended? */ regval = stm32_getreg(STM32_OTGHS_DSTS); if ((regval & OTGHS_DSTS_SUSPSTS) != 0) { /* Re-start the PHY clock and un-gate USB core clock (HCLK) */ #ifdef CONFIG_USBDEV_LOWPOWER regval = stm32_getreg(STM32_OTGHS_PCGCCTL); regval &= ~(OTGHS_PCGCCTL_STPPCLK | OTGHS_PCGCCTL_GATEHCLK); stm32_putreg(regval, STM32_OTGHS_PCGCCTL); #endif /* Activate Remote wakeup signaling */ regval = stm32_getreg(STM32_OTGHS_DCTL); regval |= OTGHS_DCTL_RWUSIG; stm32_putreg(regval, STM32_OTGHS_DCTL); up_mdelay(5); regval &= ~OTGHS_DCTL_RWUSIG; stm32_putreg(regval, STM32_OTGHS_DCTL); } } leave_critical_section(flags); return OK; } /**************************************************************************** * Name: stm32_selfpowered * * Description: * Sets/clears the device self-powered feature * ****************************************************************************/ static int stm32_selfpowered(struct usbdev_s *dev, bool selfpowered) { FAR struct stm32_usbdev_s *priv = (FAR struct stm32_usbdev_s *)dev; usbtrace(TRACE_DEVSELFPOWERED, (uint16_t)selfpowered); #ifdef CONFIG_DEBUG_FEATURES if (!dev) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0); return -ENODEV; } #endif priv->selfpowered = selfpowered; return OK; } /**************************************************************************** * Name: stm32_pullup * * Description: * Software-controlled connect to/disconnect from USB host * ****************************************************************************/ static int stm32_pullup(struct usbdev_s *dev, bool enable) { uint32_t regval; usbtrace(TRACE_DEVPULLUP, (uint16_t)enable); irqstate_t flags = enter_critical_section(); regval = stm32_getreg(STM32_OTGHS_DCTL); if (enable) { /* Connect the device by clearing the soft disconnect bit in the DCTL * register */ regval &= ~OTGHS_DCTL_SDIS; } else { /* Connect the device by setting the soft disconnect bit in the DCTL * register */ regval |= OTGHS_DCTL_SDIS; } stm32_putreg(regval, STM32_OTGHS_DCTL); leave_critical_section(flags); return OK; } /**************************************************************************** * Name: stm32_setaddress * * Description: * Set the devices USB address * ****************************************************************************/ static void stm32_setaddress(struct stm32_usbdev_s *priv, uint16_t address) { uint32_t regval; /* Set the device address in the DCFG register */ regval = stm32_getreg(STM32_OTGHS_DCFG); regval &= ~OTGHS_DCFG_DAD_MASK; regval |= ((uint32_t)address << OTGHS_DCFG_DAD_SHIFT); stm32_putreg(regval, STM32_OTGHS_DCFG); /* Are we now addressed? (i.e., do we have a non-NULL device * address?) */ if (address != 0) { priv->devstate = DEVSTATE_ADDRESSED; priv->addressed = true; } else { priv->devstate = DEVSTATE_DEFAULT; priv->addressed = false; } } /**************************************************************************** * Name: stm32_txfifo_flush * * Description: * Flush the specific TX fifo. * ****************************************************************************/ static int stm32_txfifo_flush(uint32_t txfnum) { uint32_t regval; uint32_t timeout; /* Initiate the TX FIFO flush operation */ regval = OTGHS_GRSTCTL_TXFFLSH | txfnum; stm32_putreg(regval, STM32_OTGHS_GRSTCTL); /* Wait for the FLUSH to complete */ for (timeout = 0; timeout < STM32_FLUSH_DELAY; timeout++) { regval = stm32_getreg(STM32_OTGHS_GRSTCTL); if ((regval & OTGHS_GRSTCTL_TXFFLSH) == 0) { break; } } /* Wait for 3 PHY Clocks */ up_udelay(3); return OK; } /**************************************************************************** * Name: stm32_rxfifo_flush * * Description: * Flush the RX fifo. * ****************************************************************************/ static int stm32_rxfifo_flush(void) { uint32_t regval; uint32_t timeout; /* Initiate the RX FIFO flush operation */ stm32_putreg(OTGHS_GRSTCTL_RXFFLSH, STM32_OTGHS_GRSTCTL); /* Wait for the FLUSH to complete */ for (timeout = 0; timeout < STM32_FLUSH_DELAY; timeout++) { regval = stm32_getreg(STM32_OTGHS_GRSTCTL); if ((regval & OTGHS_GRSTCTL_RXFFLSH) == 0) { break; } } /* Wait for 3 PHY Clocks */ up_udelay(3); return OK; } /**************************************************************************** * Name: stm32_swinitialize * * Description: * Initialize all driver data structures. * ****************************************************************************/ static void stm32_swinitialize(FAR struct stm32_usbdev_s *priv) { FAR struct stm32_ep_s *privep; int i; /* Initialize the device state structure */ memset(priv, 0, sizeof(struct stm32_usbdev_s)); priv->usbdev.ops = &g_devops; priv->usbdev.ep0 = &priv->epin[EP0].ep; priv->epavail[0] = STM32_EP_AVAILABLE; priv->epavail[1] = STM32_EP_AVAILABLE; priv->epin[EP0].ep.priv = priv; priv->epout[EP0].ep.priv = priv; /* Initialize the endpoint lists */ for (i = 0; i < STM32_NENDPOINTS; i++) { /* Set endpoint operations, reference to driver structure (not * really necessary because there is only one controller), and * the physical endpoint number (which is just the index to the * endpoint). */ privep = &priv->epin[i]; privep->ep.ops = &g_epops; privep->dev = priv; privep->isin = 1; /* The index, i, is the physical endpoint address; Map this * to a logical endpoint address usable by the class driver. */ privep->epphy = i; privep->ep.eplog = STM32_EPPHYIN2LOG(i); /* Control until endpoint is activated */ privep->eptype = USB_EP_ATTR_XFER_CONTROL; privep->ep.maxpacket = CONFIG_USBDEV_EP0_MAXSIZE; } /* Initialize the endpoint lists */ for (i = 0; i < STM32_NENDPOINTS; i++) { /* Set endpoint operations, reference to driver structure (not * really necessary because there is only one controller), and * the physical endpoint number (which is just the index to the * endpoint). */ privep = &priv->epout[i]; privep->ep.ops = &g_epops; privep->dev = priv; /* The index, i, is the physical endpoint address; Map this * to a logical endpoint address usable by the class driver. */ privep->epphy = i; privep->ep.eplog = STM32_EPPHYOUT2LOG(i); /* Control until endpoint is activated */ privep->eptype = USB_EP_ATTR_XFER_CONTROL; privep->ep.maxpacket = CONFIG_USBDEV_EP0_MAXSIZE; } } /**************************************************************************** * Name: stm32_hwinitialize * * Description: * Configure the OTG HS core for operation. * ****************************************************************************/ static void stm32_hwinitialize(FAR struct stm32_usbdev_s *priv) { uint32_t regval; uint32_t timeout; uint32_t address; int i; /* At start-up the core is in HS mode. */ /* Disable global interrupts by clearing the GINTMASK bit in the GAHBCFG * register; Set the TXFELVL bit in the GAHBCFG register so that TxFIFO * interrupts will occur when the TxFIFO is truly empty (not just half full). */ stm32_putreg(OTGHS_GAHBCFG_TXFELVL, STM32_OTGHS_GAHBCFG); /* Set the PHYSEL bit in the GUSBCFG register to select the OTG HS serial * transceiver: "This bit is always 1 with write-only access" */ regval = stm32_getreg(STM32_OTGHS_GUSBCFG); regval |= OTGHS_GUSBCFG_PHYSEL; stm32_putreg(regval, STM32_OTGHS_GUSBCFG); /* Common USB OTG core initialization */ /* Reset after a PHY select and set Host mode. First, wait for AHB master * IDLE state. */ for (timeout = 0; timeout < STM32_READY_DELAY; timeout++) { up_udelay(3); regval = stm32_getreg(STM32_OTGHS_GRSTCTL); if ((regval & OTGHS_GRSTCTL_AHBIDL) != 0) { break; } } /* Then perform the core soft reset. */ stm32_putreg(OTGHS_GRSTCTL_CSRST, STM32_OTGHS_GRSTCTL); for (timeout = 0; timeout < STM32_READY_DELAY; timeout++) { regval = stm32_getreg(STM32_OTGHS_GRSTCTL); if ((regval & OTGHS_GRSTCTL_CSRST) == 0) { break; } } /* Wait for 3 PHY Clocks */ up_udelay(3); /* Deactivate the power down */ regval = (OTGHS_GCCFG_PWRDWN | OTGHS_GCCFG_VBUSASEN | OTGHS_GCCFG_VBUSBSEN); #ifndef CONFIG_USBDEV_VBUSSENSING regval |= OTGHS_GCCFG_NOVBUSSENS; #endif #ifdef CONFIG_STM32_OTGHS_SOFOUTPUT regval |= OTGHS_GCCFG_SOFOUTEN; #endif stm32_putreg(regval, STM32_OTGHS_GCCFG); up_mdelay(20); /* Force Device Mode */ regval = stm32_getreg(STM32_OTGHS_GUSBCFG); regval &= ~OTGHS_GUSBCFG_FHMOD; regval |= OTGHS_GUSBCFG_FDMOD; stm32_putreg(regval, STM32_OTGHS_GUSBCFG); up_mdelay(50); /* Initialize device mode */ /* Restart the PHY Clock */ stm32_putreg(0, STM32_OTGHS_PCGCCTL); /* Device configuration register */ regval = stm32_getreg(STM32_OTGHS_DCFG); regval &= ~OTGHS_DCFG_PFIVL_MASK; regval |= OTGHS_DCFG_PFIVL_80PCT; stm32_putreg(regval, STM32_OTGHS_DCFG); /* Set full speed PHY */ regval = stm32_getreg(STM32_OTGHS_DCFG); regval &= ~OTGHS_DCFG_DSPD_MASK; regval |= OTGHS_DCFG_DSPD_FS; stm32_putreg(regval, STM32_OTGHS_DCFG); /* Set Rx FIFO size */ stm32_putreg(STM32_RXFIFO_WORDS, STM32_OTGHS_GRXFSIZ); /* EP0 TX */ address = STM32_RXFIFO_WORDS; regval = (address << OTGHS_DIEPTXF0_TX0FD_SHIFT) | (STM32_EP0_TXFIFO_WORDS << OTGHS_DIEPTXF0_TX0FSA_SHIFT); stm32_putreg(regval, STM32_OTGHS_DIEPTXF0); /* EP1 TX */ address += STM32_EP0_TXFIFO_WORDS; regval = (address << OTGHS_DIEPTXF_INEPTXSA_SHIFT) | (STM32_EP1_TXFIFO_WORDS << OTGHS_DIEPTXF_INEPTXFD_SHIFT); stm32_putreg(regval, STM32_OTGHS_DIEPTXF1); /* EP2 TX */ address += STM32_EP1_TXFIFO_WORDS; regval = (address << OTGHS_DIEPTXF_INEPTXSA_SHIFT) | (STM32_EP2_TXFIFO_WORDS << OTGHS_DIEPTXF_INEPTXFD_SHIFT); stm32_putreg(regval, STM32_OTGHS_DIEPTXF2); /* EP3 TX */ address += STM32_EP2_TXFIFO_WORDS; regval = (address << OTGHS_DIEPTXF_INEPTXSA_SHIFT) | (STM32_EP3_TXFIFO_WORDS << OTGHS_DIEPTXF_INEPTXFD_SHIFT); stm32_putreg(regval, STM32_OTGHS_DIEPTXF3); /* Flush the FIFOs */ stm32_txfifo_flush(OTGHS_GRSTCTL_TXFNUM_DALL); stm32_rxfifo_flush(); /* Clear all pending Device Interrupts */ stm32_putreg(0, STM32_OTGHS_DIEPMSK); stm32_putreg(0, STM32_OTGHS_DOEPMSK); stm32_putreg(0, STM32_OTGHS_DIEPEMPMSK); stm32_putreg(0xffffffff, STM32_OTGHS_DAINT); stm32_putreg(0, STM32_OTGHS_DAINTMSK); /* Configure all IN endpoints */ for (i = 0; i < STM32_NENDPOINTS; i++) { regval = stm32_getreg(STM32_OTGHS_DIEPCTL(i)); if ((regval & OTGHS_DIEPCTL_EPENA) != 0) { /* The endpoint is already enabled */ regval = OTGHS_DIEPCTL_EPENA | OTGHS_DIEPCTL_SNAK; } else { regval = 0; } stm32_putreg(regval, STM32_OTGHS_DIEPCTL(i)); stm32_putreg(0, STM32_OTGHS_DIEPTSIZ(i)); stm32_putreg(0xff, STM32_OTGHS_DIEPINT(i)); } /* Configure all OUT endpoints */ for (i = 0; i < STM32_NENDPOINTS; i++) { regval = stm32_getreg(STM32_OTGHS_DOEPCTL(i)); if ((regval & OTGHS_DOEPCTL_EPENA) != 0) { /* The endpoint is already enabled */ regval = OTGHS_DOEPCTL_EPENA | OTGHS_DOEPCTL_SNAK; } else { regval = 0; } stm32_putreg(regval, STM32_OTGHS_DOEPCTL(i)); stm32_putreg(0, STM32_OTGHS_DOEPTSIZ(i)); stm32_putreg(0xff, STM32_OTGHS_DOEPINT(i)); } /* Disable all interrupts. */ stm32_putreg(0, STM32_OTGHS_GINTMSK); /* Clear any pending USB_OTG Interrupts */ stm32_putreg(0xffffffff, STM32_OTGHS_GOTGINT); /* Clear any pending interrupts */ stm32_putreg(0xbfffffff, STM32_OTGHS_GINTSTS); #ifndef BOARD_ENABLE_USBOTG_HSULPI /* Disable the ULPI Clock enable in RCC AHB1 Register. This must * be done because if both the ULPI and the FS PHY clock enable bits * are set at the same time, the ARM never awakens from WFI due to * some bug / errata in the chip. */ regval = stm32_getreg(STM32_RCC_AHB1LPENR); regval &= ~RCC_AHB1ENR_OTGHSULPIEN; stm32_putreg(regval, STM32_RCC_AHB1LPENR); #endif /* Enable the interrupts in the INTMSK */ regval = (OTGHS_GINT_RXFLVL | OTGHS_GINT_USBSUSP | OTGHS_GINT_ENUMDNE | OTGHS_GINT_IEP | OTGHS_GINT_OEP | OTGHS_GINT_USBRST); #ifdef CONFIG_USBDEV_ISOCHRONOUS regval |= (OTGHS_GINT_IISOIXFR | OTGHS_GINT_IISOOXFR); #endif #ifdef CONFIG_USBDEV_SOFINTERRUPT regval |= OTGHS_GINT_SOF; #endif #ifdef CONFIG_USBDEV_VBUSSENSING regval |= (OTGHS_GINT_OTG | OTGHS_GINT_SRQ); #endif #ifdef CONFIG_DEBUG_USB regval |= OTGHS_GINT_MMIS; #endif stm32_putreg(regval, STM32_OTGHS_GINTMSK); /* Enable the USB global interrupt by setting GINTMSK in the global OTG * HS AHB configuration register; Set the TXFELVL bit in the GAHBCFG * register so that TxFIFO interrupts will occur when the TxFIFO is truly * empty (not just half full). */ stm32_putreg(OTGHS_GAHBCFG_GINTMSK | OTGHS_GAHBCFG_TXFELVL, STM32_OTGHS_GAHBCFG); } /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** * Name: up_usbinitialize * * Description: * Initialize USB hardware. * * Assumptions: * - This function is called very early in the initialization sequence * - PLL and GIO pin initialization is not performed here but should been in * the low-level boot logic: PLL1 must be configured for operation at 48MHz * and P0.23 and PO.31 in PINSEL1 must be configured for Vbus and USB connect * LED. * ****************************************************************************/ void up_usbinitialize(void) { /* At present, there is only a single OTG HS device support. Hence it is * pre-allocated as g_otghsdev. However, in most code, the private data * structure will be referenced using the 'priv' pointer (rather than the * global data) in order to simplify any future support for multiple devices. */ FAR struct stm32_usbdev_s *priv = &g_otghsdev; int ret; usbtrace(TRACE_DEVINIT, 0); /* Here we assume that: * * 1. GPIOA and OTG HS peripheral clocking has already been enabled as part * of the boot sequence. * 2. Board-specific logic has already enabled other board specific GPIOs * for things like soft pull-up, VBUS sensing, power controls, and over- * current detection. */ /* Configure OTG HS alternate function pins * * PIN* SIGNAL DIRECTION * ---- ----------- ---------- * PA8 OTG_HS_SOF SOF clock output * PA9 OTG_HS_VBUS VBUS input for device, Driven by external regulator by * host (not an alternate function) * PA10 OTG_HS_ID OTG ID pin (only needed in Dual mode) * PA11 OTG_HS_DM D- I/O * PA12 OTG_HS_DP D+ I/O * * *Pins may vary from device-to-device. */ stm32_configgpio(GPIO_OTGHS_DM); stm32_configgpio(GPIO_OTGHS_DP); stm32_configgpio(GPIO_OTGHS_ID); /* Only needed for OTG */ /* SOF output pin configuration is configurable. */ #ifdef CONFIG_STM32_OTGHS_SOFOUTPUT stm32_configgpio(GPIO_OTGHS_SOF); #endif /* Uninitialize the hardware so that we know that we are starting from a * known state. */ up_usbuninitialize(); /* Initialie the driver data structure */ stm32_swinitialize(priv); /* Attach the OTG HS interrupt handler */ ret = irq_attach(STM32_IRQ_OTGHS, stm32_usbinterrupt, NULL); if (ret < 0) { uerr("ERROR: irq_attach failed\n", ret); goto errout; } /* Initialize the USB OTG core */ stm32_hwinitialize(priv); /* Disconnect device */ stm32_pullup(&priv->usbdev, false); /* Reset/Re-initialize the USB hardware */ stm32_usbreset(priv); /* Enable USB controller interrupts at the NVIC */ up_enable_irq(STM32_IRQ_OTGHS); #ifdef CONFIG_ARCH_IRQPRIO /* Set the interrupt priority */ up_prioritize_irq(STM32_IRQ_OTGHS, CONFIG_OTGHS_PRI); #endif return; errout: up_usbuninitialize(); } /**************************************************************************** * Name: up_usbhsuninitialize ****************************************************************************/ void up_usbuninitialize(void) { /* At present, there is only a single OTG HS device support. Hence it is * pre-allocated as g_otghsdev. However, in most code, the private data * structure will be referenced using the 'priv' pointer (rather than the * global data) in order to simplify any future support for multiple devices. */ FAR struct stm32_usbdev_s *priv = &g_otghsdev; irqstate_t flags; int i; usbtrace(TRACE_DEVUNINIT, 0); if (priv->driver) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_DRIVERREGISTERED), 0); usbdev_unregister(priv->driver); } /* Disconnect device */ flags = enter_critical_section(); stm32_pullup(&priv->usbdev, false); priv->usbdev.speed = USB_SPEED_UNKNOWN; /* Disable and detach IRQs */ up_disable_irq(STM32_IRQ_OTGHS); irq_detach(STM32_IRQ_OTGHS); /* Disable all endpoint interrupts */ for (i = 0; i < STM32_NENDPOINTS; i++) { stm32_putreg(0xff, STM32_OTGHS_DIEPINT(i)); stm32_putreg(0xff, STM32_OTGHS_DOEPINT(i)); } stm32_putreg(0, STM32_OTGHS_DIEPMSK); stm32_putreg(0, STM32_OTGHS_DOEPMSK); stm32_putreg(0, STM32_OTGHS_DIEPEMPMSK); stm32_putreg(0, STM32_OTGHS_DAINTMSK); stm32_putreg(0xffffffff, STM32_OTGHS_DAINT); /* Flush the FIFOs */ stm32_txfifo_flush(OTGHS_GRSTCTL_TXFNUM_DALL); stm32_rxfifo_flush(); /* TODO: Turn off USB power and clocking */ priv->devstate = DEVSTATE_DEFAULT; leave_critical_section(flags); } /**************************************************************************** * Name: usbdev_register * * Description: * Register a USB device class driver. The class driver's bind() method will be * called to bind it to a USB device driver. * ****************************************************************************/ int usbdev_register(struct usbdevclass_driver_s *driver) { /* At present, there is only a single OTG HS device support. Hence it is * pre-allocated as g_otghsdev. However, in most code, the private data * structure will be referenced using the 'priv' pointer (rather than the * global data) in order to simplify any future support for multiple devices. */ FAR struct stm32_usbdev_s *priv = &g_otghsdev; int ret; usbtrace(TRACE_DEVREGISTER, 0); #ifdef CONFIG_DEBUG_FEATURES if (!driver || !driver->ops->bind || !driver->ops->unbind || !driver->ops->disconnect || !driver->ops->setup) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0); return -EINVAL; } if (priv->driver) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_DRIVER), 0); return -EBUSY; } #endif /* First hook up the driver */ priv->driver = driver; /* Then bind the class driver */ ret = CLASS_BIND(driver, &priv->usbdev); if (ret) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_BINDFAILED), (uint16_t)-ret); priv->driver = NULL; } else { /* Enable USB controller interrupts */ up_enable_irq(STM32_IRQ_OTGHS); /* FIXME: nothing seems to call DEV_CONNECT(), but we need to set * the RS bit to enable the controller. It kind of makes sense * to do this after the class has bound to us... * GEN: This bug is really in the class driver. It should make the * soft connect when it is ready to be enumerated. I have added * that logic to the class drivers but left this logic here. */ stm32_pullup(&priv->usbdev, true); priv->usbdev.speed = USB_SPEED_FULL; } return ret; } /**************************************************************************** * Name: usbdev_unregister * * Description: * Un-register usbdev class driver.If the USB device is connected to a USB host, * it will first disconnect(). The driver is also requested to unbind() and clean * up any device state, before this procedure finally returns. * ****************************************************************************/ int usbdev_unregister(struct usbdevclass_driver_s *driver) { /* At present, there is only a single OTG HS device support. Hence it is * pre-allocated as g_otghsdev. However, in most code, the private data * structure will be referenced using the 'priv' pointer (rather than the * global data) in order to simplify any future support for multiple devices. */ FAR struct stm32_usbdev_s *priv = &g_otghsdev; irqstate_t flags; usbtrace(TRACE_DEVUNREGISTER, 0); #ifdef CONFIG_DEBUG_FEATURES if (driver != priv->driver) { usbtrace(TRACE_DEVERROR(STM32_TRACEERR_INVALIDPARMS), 0); return -EINVAL; } #endif /* Reset the hardware and cancel all requests. All requests must be * canceled while the class driver is still bound. */ flags = enter_critical_section(); stm32_usbreset(priv); leave_critical_section(flags); /* Unbind the class driver */ CLASS_UNBIND(driver, &priv->usbdev); /* Disable USB controller interrupts */ flags = enter_critical_section(); up_disable_irq(STM32_IRQ_OTGHS); /* Disconnect device */ stm32_pullup(&priv->usbdev, false); /* Unhook the driver */ priv->driver = NULL; leave_critical_section(flags); return OK; } #endif /* CONFIG_USBDEV && CONFIG_STM32_OTGHSDEV */
495932.c
/* This is a managed file. Do not delete this comment. */ #include <include/test.h> int16_t test_LifecycleTest_construct( test_LifecycleTest this) { test_assert(this->admin != NULL); test_assert(corto_stateof(this) == CORTO_DECLARED); test_assertint(this->admin->hooksCalled, TEST_INIT_CALLED); this->admin->hooksCalled |= TEST_CONSTRUCT_CALLED; return this->constructFail; } void test_LifecycleTest_define( test_LifecycleTest this) { test_assert(this->admin != NULL); test_assert(corto_stateof(this) == (CORTO_DECLARED|CORTO_VALID)); test_assertint(this->admin->hooksCalled, TEST_INIT_CALLED|TEST_CONSTRUCT_CALLED); this->admin->hooksCalled |= TEST_DEFINE_CALLED; } void test_LifecycleTest_delete( test_LifecycleTest this) { test_assert(this->admin != NULL); test_assertint(corto_stateof(this), (CORTO_DECLARED|CORTO_DELETED)); test_assertint(this->admin->hooksCalled, TEST_INIT_CALLED|TEST_CONSTRUCT_CALLED|TEST_DEFINE_CALLED| TEST_VALIDATE_CALLED|TEST_UPDATE_CALLED|TEST_DESTRUCT_CALLED); this->admin->hooksCalled |= TEST_DELETE_CALLED; } void test_LifecycleTest_destruct( test_LifecycleTest this) { test_assert(this->admin != NULL); test_assert(corto_stateof(this) == (CORTO_DECLARED|CORTO_VALID)); test_assertint(this->admin->hooksCalled, TEST_INIT_CALLED|TEST_CONSTRUCT_CALLED|TEST_DEFINE_CALLED|TEST_VALIDATE_CALLED|TEST_UPDATE_CALLED); this->admin->hooksCalled |= TEST_DESTRUCT_CALLED; } int16_t test_LifecycleTest_init( test_LifecycleTest this) { test_assert(!this->admin); this->admin = corto_create(NULL, NULL, test_LifecycleAdmin_o); test_assert(corto_stateof(this) == CORTO_DECLARED); test_assertint(this->admin->hooksCalled, 0); this->admin->hooksCalled |= TEST_INIT_CALLED; return !strcmp(corto_idof(this), "fail"); } void test_LifecycleTest_update( test_LifecycleTest this) { test_assert(this->admin != NULL); test_assert(corto_stateof(this) == (CORTO_DECLARED|CORTO_VALID)); test_assertint(this->admin->hooksCalled, TEST_INIT_CALLED|TEST_CONSTRUCT_CALLED|TEST_DEFINE_CALLED|TEST_VALIDATE_CALLED); this->admin->hooksCalled |= TEST_UPDATE_CALLED; } int16_t test_LifecycleTest_validate( test_LifecycleTest this) { test_assert(this->admin != NULL); test_assertint(corto_stateof(this), (CORTO_DECLARED|CORTO_VALID)); test_assertint(this->admin->hooksCalled, TEST_INIT_CALLED|TEST_CONSTRUCT_CALLED|TEST_DEFINE_CALLED); this->admin->hooksCalled |= TEST_VALIDATE_CALLED; return this->validateFail; } void test_LifecycleTest_deinit( test_LifecycleTest this) { test_assert(this->admin != NULL); test_assert(corto_stateof(this) == (CORTO_DECLARED|CORTO_DELETED)); test_assertint(this->admin->hooksCalled, TEST_INIT_CALLED|TEST_CONSTRUCT_CALLED|TEST_DEFINE_CALLED|TEST_VALIDATE_CALLED| TEST_UPDATE_CALLED|TEST_DESTRUCT_CALLED|TEST_DELETE_CALLED); this->admin->hooksCalled |= TEST_DEINIT_CALLED; }
969480.c
/* * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * Copyright (c) 2003-2017 The DragonFly Project. All rights reserved. * * This code is derived from software contributed to Berkeley by * The Mach Operating System project at Carnegie-Mellon University. * * This code is derived from software contributed to The DragonFly Project * by Matthew Dillon <[email protected]> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * from: @(#)vm_map.c 8.3 (Berkeley) 1/12/94 * * * Copyright (c) 1987, 1990 Carnegie-Mellon University. * All rights reserved. * * Authors: Avadis Tevanian, Jr., Michael Wayne Young * * Permission to use, copy, modify and distribute this software and * its documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or [email protected] * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. * * $FreeBSD: src/sys/vm/vm_map.c,v 1.187.2.19 2003/05/27 00:47:02 alc Exp $ */ /* * Virtual memory mapping module. */ #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> #include <sys/proc.h> #include <sys/serialize.h> #include <sys/lock.h> #include <sys/vmmeter.h> #include <sys/mman.h> #include <sys/vnode.h> #include <sys/resourcevar.h> #include <sys/shm.h> #include <sys/tree.h> #include <sys/malloc.h> #include <sys/objcache.h> #include <vm/vm.h> #include <vm/vm_param.h> #include <vm/pmap.h> #include <vm/vm_map.h> #include <vm/vm_page.h> #include <vm/vm_object.h> #include <vm/vm_pager.h> #include <vm/vm_kern.h> #include <vm/vm_extern.h> #include <vm/swap_pager.h> #include <vm/vm_zone.h> #include <sys/random.h> #include <sys/sysctl.h> #include <sys/spinlock.h> #include <sys/thread2.h> #include <sys/spinlock2.h> /* * Virtual memory maps provide for the mapping, protection, and sharing * of virtual memory objects. In addition, this module provides for an * efficient virtual copy of memory from one map to another. * * Synchronization is required prior to most operations. * * Maps consist of an ordered doubly-linked list of simple entries. * A hint and a RB tree is used to speed-up lookups. * * Callers looking to modify maps specify start/end addresses which cause * the related map entry to be clipped if necessary, and then later * recombined if the pieces remained compatible. * * Virtual copy operations are performed by copying VM object references * from one map to another, and then marking both regions as copy-on-write. */ static boolean_t vmspace_ctor(void *obj, void *privdata, int ocflags); static void vmspace_dtor(void *obj, void *privdata); static void vmspace_terminate(struct vmspace *vm, int final); MALLOC_DEFINE(M_VMSPACE, "vmspace", "vmspace objcache backingstore"); static struct objcache *vmspace_cache; /* * per-cpu page table cross mappings are initialized in early boot * and might require a considerable number of vm_map_entry structures. */ #define MAPENTRYBSP_CACHE (MAXCPU+1) #define MAPENTRYAP_CACHE 8 /* * Partioning threaded programs with large anonymous memory areas can * improve concurrent fault performance. */ #define MAP_ENTRY_PARTITION_SIZE ((vm_offset_t)(32 * 1024 * 1024)) #define MAP_ENTRY_PARTITION_MASK (MAP_ENTRY_PARTITION_SIZE - 1) #define VM_MAP_ENTRY_WITHIN_PARTITION(entry) \ ((((entry)->start ^ (entry)->end) & ~MAP_ENTRY_PARTITION_MASK) == 0) static struct vm_zone mapentzone_store; static vm_zone_t mapentzone; static struct vm_map_entry map_entry_init[MAX_MAPENT]; static struct vm_map_entry cpu_map_entry_init_bsp[MAPENTRYBSP_CACHE]; static struct vm_map_entry cpu_map_entry_init_ap[MAXCPU][MAPENTRYAP_CACHE]; static int randomize_mmap; SYSCTL_INT(_vm, OID_AUTO, randomize_mmap, CTLFLAG_RW, &randomize_mmap, 0, "Randomize mmap offsets"); static int vm_map_relock_enable = 1; SYSCTL_INT(_vm, OID_AUTO, map_relock_enable, CTLFLAG_RW, &vm_map_relock_enable, 0, "insert pop pgtable optimization"); static int vm_map_partition_enable = 1; SYSCTL_INT(_vm, OID_AUTO, map_partition_enable, CTLFLAG_RW, &vm_map_partition_enable, 0, "Break up larger vm_map_entry's"); static void vmspace_drop_notoken(struct vmspace *vm); static void vm_map_entry_shadow(vm_map_entry_t entry, int addref); static vm_map_entry_t vm_map_entry_create(vm_map_t map, int *); static void vm_map_entry_dispose (vm_map_t map, vm_map_entry_t entry, int *); static void _vm_map_clip_end (vm_map_t, vm_map_entry_t, vm_offset_t, int *); static void _vm_map_clip_start (vm_map_t, vm_map_entry_t, vm_offset_t, int *); static void vm_map_entry_delete (vm_map_t, vm_map_entry_t, int *); static void vm_map_entry_unwire (vm_map_t, vm_map_entry_t); static void vm_map_copy_entry (vm_map_t, vm_map_t, vm_map_entry_t, vm_map_entry_t); static void vm_map_unclip_range (vm_map_t map, vm_map_entry_t start_entry, vm_offset_t start, vm_offset_t end, int *countp, int flags); static void vm_map_entry_partition(vm_map_t map, vm_map_entry_t entry, vm_offset_t vaddr, int *countp); /* * Initialize the vm_map module. Must be called before any other vm_map * routines. * * Map and entry structures are allocated from the general purpose * memory pool with some exceptions: * * - The kernel map is allocated statically. * - Initial kernel map entries are allocated out of a static pool. * - We must set ZONE_SPECIAL here or the early boot code can get * stuck if there are >63 cores. * * These restrictions are necessary since malloc() uses the * maps and requires map entries. * * Called from the low level boot code only. */ void vm_map_startup(void) { mapentzone = &mapentzone_store; zbootinit(mapentzone, "MAP ENTRY", sizeof (struct vm_map_entry), map_entry_init, MAX_MAPENT); mapentzone_store.zflags |= ZONE_SPECIAL; } /* * Called prior to any vmspace allocations. * * Called from the low level boot code only. */ void vm_init2(void) { vmspace_cache = objcache_create_mbacked(M_VMSPACE, sizeof(struct vmspace), 0, ncpus * 4, vmspace_ctor, vmspace_dtor, NULL); zinitna(mapentzone, NULL, 0, 0, ZONE_USE_RESERVE | ZONE_SPECIAL); pmap_init2(); vm_object_init2(); } /* * objcache support. We leave the pmap root cached as long as possible * for performance reasons. */ static boolean_t vmspace_ctor(void *obj, void *privdata, int ocflags) { struct vmspace *vm = obj; bzero(vm, sizeof(*vm)); vm->vm_refcnt = VM_REF_DELETED; return 1; } static void vmspace_dtor(void *obj, void *privdata) { struct vmspace *vm = obj; KKASSERT(vm->vm_refcnt == VM_REF_DELETED); pmap_puninit(vmspace_pmap(vm)); } /* * Red black tree functions * * The caller must hold the related map lock. */ static int rb_vm_map_compare(vm_map_entry_t a, vm_map_entry_t b); RB_GENERATE(vm_map_rb_tree, vm_map_entry, rb_entry, rb_vm_map_compare); /* a->start is address, and the only field has to be initialized */ static int rb_vm_map_compare(vm_map_entry_t a, vm_map_entry_t b) { if (a->start < b->start) return(-1); else if (a->start > b->start) return(1); return(0); } /* * Initialize vmspace ref/hold counts vmspace0. There is a holdcnt for * every refcnt. */ void vmspace_initrefs(struct vmspace *vm) { vm->vm_refcnt = 1; vm->vm_holdcnt = 1; } /* * Allocate a vmspace structure, including a vm_map and pmap. * Initialize numerous fields. While the initial allocation is zerod, * subsequence reuse from the objcache leaves elements of the structure * intact (particularly the pmap), so portions must be zerod. * * Returns a referenced vmspace. * * No requirements. */ struct vmspace * vmspace_alloc(vm_offset_t min, vm_offset_t max) { struct vmspace *vm; vm = objcache_get(vmspace_cache, M_WAITOK); bzero(&vm->vm_startcopy, (char *)&vm->vm_endcopy - (char *)&vm->vm_startcopy); vm_map_init(&vm->vm_map, min, max, NULL); /* initializes token */ /* * NOTE: hold to acquires token for safety. * * On return vmspace is referenced (refs=1, hold=1). That is, * each refcnt also has a holdcnt. There can be additional holds * (holdcnt) above and beyond the refcnt. Finalization is handled in * two stages, one on refs 1->0, and the the second on hold 1->0. */ KKASSERT(vm->vm_holdcnt == 0); KKASSERT(vm->vm_refcnt == VM_REF_DELETED); vmspace_initrefs(vm); vmspace_hold(vm); pmap_pinit(vmspace_pmap(vm)); /* (some fields reused) */ vm->vm_map.pmap = vmspace_pmap(vm); /* XXX */ vm->vm_shm = NULL; vm->vm_flags = 0; cpu_vmspace_alloc(vm); vmspace_drop(vm); return (vm); } /* * NOTE: Can return 0 if the vmspace is exiting. */ int vmspace_getrefs(struct vmspace *vm) { int32_t n; n = vm->vm_refcnt; cpu_ccfence(); if (n & VM_REF_DELETED) n = -1; return n; } void vmspace_hold(struct vmspace *vm) { atomic_add_int(&vm->vm_holdcnt, 1); lwkt_gettoken(&vm->vm_map.token); } /* * Drop with final termination interlock. */ void vmspace_drop(struct vmspace *vm) { lwkt_reltoken(&vm->vm_map.token); vmspace_drop_notoken(vm); } static void vmspace_drop_notoken(struct vmspace *vm) { if (atomic_fetchadd_int(&vm->vm_holdcnt, -1) == 1) { if (vm->vm_refcnt & VM_REF_DELETED) vmspace_terminate(vm, 1); } } /* * A vmspace object must not be in a terminated state to be able to obtain * additional refs on it. * * These are official references to the vmspace, the count is used to check * for vmspace sharing. Foreign accessors should use 'hold' and not 'ref'. * * XXX we need to combine hold & ref together into one 64-bit field to allow * holds to prevent stage-1 termination. */ void vmspace_ref(struct vmspace *vm) { uint32_t n; atomic_add_int(&vm->vm_holdcnt, 1); n = atomic_fetchadd_int(&vm->vm_refcnt, 1); KKASSERT((n & VM_REF_DELETED) == 0); } /* * Release a ref on the vmspace. On the 1->0 transition we do stage-1 * termination of the vmspace. Then, on the final drop of the hold we * will do stage-2 final termination. */ void vmspace_rel(struct vmspace *vm) { uint32_t n; /* * Drop refs. Each ref also has a hold which is also dropped. * * When refs hits 0 compete to get the VM_REF_DELETED flag (hold * prevent finalization) to start termination processing. * Finalization occurs when the last hold count drops to 0. */ n = atomic_fetchadd_int(&vm->vm_refcnt, -1) - 1; while (n == 0) { if (atomic_cmpset_int(&vm->vm_refcnt, 0, VM_REF_DELETED)) { vmspace_terminate(vm, 0); break; } n = vm->vm_refcnt; cpu_ccfence(); } vmspace_drop_notoken(vm); } /* * This is called during exit indicating that the vmspace is no * longer in used by an exiting process, but the process has not yet * been reaped. * * We drop refs, allowing for stage-1 termination, but maintain a holdcnt * to prevent stage-2 until the process is reaped. Note hte order of * operation, we must hold first. * * No requirements. */ void vmspace_relexit(struct vmspace *vm) { atomic_add_int(&vm->vm_holdcnt, 1); vmspace_rel(vm); } /* * Called during reap to disconnect the remainder of the vmspace from * the process. On the hold drop the vmspace termination is finalized. * * No requirements. */ void vmspace_exitfree(struct proc *p) { struct vmspace *vm; vm = p->p_vmspace; p->p_vmspace = NULL; vmspace_drop_notoken(vm); } /* * Called in two cases: * * (1) When the last refcnt is dropped and the vmspace becomes inactive, * called with final == 0. refcnt will be (u_int)-1 at this point, * and holdcnt will still be non-zero. * * (2) When holdcnt becomes 0, called with final == 1. There should no * longer be anyone with access to the vmspace. * * VMSPACE_EXIT1 flags the primary deactivation * VMSPACE_EXIT2 flags the last reap */ static void vmspace_terminate(struct vmspace *vm, int final) { int count; lwkt_gettoken(&vm->vm_map.token); if (final == 0) { KKASSERT((vm->vm_flags & VMSPACE_EXIT1) == 0); vm->vm_flags |= VMSPACE_EXIT1; /* * Get rid of most of the resources. Leave the kernel pmap * intact. * * If the pmap does not contain wired pages we can bulk-delete * the pmap as a performance optimization before removing the * related mappings. * * If the pmap contains wired pages we cannot do this * pre-optimization because currently vm_fault_unwire() * expects the pmap pages to exist and will not decrement * p->wire_count if they do not. */ shmexit(vm); if (vmspace_pmap(vm)->pm_stats.wired_count) { vm_map_remove(&vm->vm_map, VM_MIN_USER_ADDRESS, VM_MAX_USER_ADDRESS); pmap_remove_pages(vmspace_pmap(vm), VM_MIN_USER_ADDRESS, VM_MAX_USER_ADDRESS); } else { pmap_remove_pages(vmspace_pmap(vm), VM_MIN_USER_ADDRESS, VM_MAX_USER_ADDRESS); vm_map_remove(&vm->vm_map, VM_MIN_USER_ADDRESS, VM_MAX_USER_ADDRESS); } lwkt_reltoken(&vm->vm_map.token); } else { KKASSERT((vm->vm_flags & VMSPACE_EXIT1) != 0); KKASSERT((vm->vm_flags & VMSPACE_EXIT2) == 0); /* * Get rid of remaining basic resources. */ vm->vm_flags |= VMSPACE_EXIT2; shmexit(vm); count = vm_map_entry_reserve(MAP_RESERVE_COUNT); vm_map_lock(&vm->vm_map); cpu_vmspace_free(vm); /* * Lock the map, to wait out all other references to it. * Delete all of the mappings and pages they hold, then call * the pmap module to reclaim anything left. */ vm_map_delete(&vm->vm_map, vm->vm_map.min_offset, vm->vm_map.max_offset, &count); vm_map_unlock(&vm->vm_map); vm_map_entry_release(count); pmap_release(vmspace_pmap(vm)); lwkt_reltoken(&vm->vm_map.token); objcache_put(vmspace_cache, vm); } } /* * Swap useage is determined by taking the proportional swap used by * VM objects backing the VM map. To make up for fractional losses, * if the VM object has any swap use at all the associated map entries * count for at least 1 swap page. * * No requirements. */ vm_offset_t vmspace_swap_count(struct vmspace *vm) { vm_map_t map = &vm->vm_map; vm_map_entry_t cur; vm_object_t object; vm_offset_t count = 0; vm_offset_t n; vmspace_hold(vm); for (cur = map->header.next; cur != &map->header; cur = cur->next) { switch(cur->maptype) { case VM_MAPTYPE_NORMAL: case VM_MAPTYPE_VPAGETABLE: if ((object = cur->object.vm_object) == NULL) break; if (object->swblock_count) { n = (cur->end - cur->start) / PAGE_SIZE; count += object->swblock_count * SWAP_META_PAGES * n / object->size + 1; } break; default: break; } } vmspace_drop(vm); return(count); } /* * Calculate the approximate number of anonymous pages in use by * this vmspace. To make up for fractional losses, we count each * VM object as having at least 1 anonymous page. * * No requirements. */ vm_offset_t vmspace_anonymous_count(struct vmspace *vm) { vm_map_t map = &vm->vm_map; vm_map_entry_t cur; vm_object_t object; vm_offset_t count = 0; vmspace_hold(vm); for (cur = map->header.next; cur != &map->header; cur = cur->next) { switch(cur->maptype) { case VM_MAPTYPE_NORMAL: case VM_MAPTYPE_VPAGETABLE: if ((object = cur->object.vm_object) == NULL) break; if (object->type != OBJT_DEFAULT && object->type != OBJT_SWAP) { break; } count += object->resident_page_count; break; default: break; } } vmspace_drop(vm); return(count); } /* * Initialize an existing vm_map structure such as that in the vmspace * structure. The pmap is initialized elsewhere. * * No requirements. */ void vm_map_init(struct vm_map *map, vm_offset_t min, vm_offset_t max, pmap_t pmap) { map->header.next = map->header.prev = &map->header; RB_INIT(&map->rb_root); spin_init(&map->ilock_spin, "ilock"); map->ilock_base = NULL; map->nentries = 0; map->size = 0; map->system_map = 0; map->min_offset = min; map->max_offset = max; map->pmap = pmap; map->timestamp = 0; map->flags = 0; bzero(&map->freehint, sizeof(map->freehint)); lwkt_token_init(&map->token, "vm_map"); lockinit(&map->lock, "vm_maplk", (hz + 9) / 10, 0); } /* * Find the first possible free address for the specified request length. * Returns 0 if we don't have one cached. */ static vm_offset_t vm_map_freehint_find(vm_map_t map, vm_size_t length, vm_size_t align) { vm_map_freehint_t *scan; scan = &map->freehint[0]; while (scan < &map->freehint[VM_MAP_FFCOUNT]) { if (scan->length == length && scan->align == align) return(scan->start); ++scan; } return 0; } /* * Unconditionally set the freehint. Called by vm_map_findspace() after * it finds an address. This will help us iterate optimally on the next * similar findspace. */ static void vm_map_freehint_update(vm_map_t map, vm_offset_t start, vm_size_t length, vm_size_t align) { vm_map_freehint_t *scan; scan = &map->freehint[0]; while (scan < &map->freehint[VM_MAP_FFCOUNT]) { if (scan->length == length && scan->align == align) { scan->start = start; return; } ++scan; } scan = &map->freehint[map->freehint_newindex & VM_MAP_FFMASK]; scan->start = start; scan->align = align; scan->length = length; ++map->freehint_newindex; } /* * Update any existing freehints (for any alignment), for the hole we just * added. */ static void vm_map_freehint_hole(vm_map_t map, vm_offset_t start, vm_size_t length) { vm_map_freehint_t *scan; scan = &map->freehint[0]; while (scan < &map->freehint[VM_MAP_FFCOUNT]) { if (scan->length <= length && scan->start > start) scan->start = start; ++scan; } } /* * Shadow the vm_map_entry's object. This typically needs to be done when * a write fault is taken on an entry which had previously been cloned by * fork(). The shared object (which might be NULL) must become private so * we add a shadow layer above it. * * Object allocation for anonymous mappings is defered as long as possible. * When creating a shadow, however, the underlying object must be instantiated * so it can be shared. * * If the map segment is governed by a virtual page table then it is * possible to address offsets beyond the mapped area. Just allocate * a maximally sized object for this case. * * If addref is non-zero an additional reference is added to the returned * entry. This mechanic exists because the additional reference might have * to be added atomically and not after return to prevent a premature * collapse. * * The vm_map must be exclusively locked. * No other requirements. */ static void vm_map_entry_shadow(vm_map_entry_t entry, int addref) { if (entry->maptype == VM_MAPTYPE_VPAGETABLE) { vm_object_shadow(&entry->object.vm_object, &entry->offset, 0x7FFFFFFF, addref); /* XXX */ } else { vm_object_shadow(&entry->object.vm_object, &entry->offset, atop(entry->end - entry->start), addref); } entry->eflags &= ~MAP_ENTRY_NEEDS_COPY; } /* * Allocate an object for a vm_map_entry. * * Object allocation for anonymous mappings is defered as long as possible. * This function is called when we can defer no longer, generally when a map * entry might be split or forked or takes a page fault. * * If the map segment is governed by a virtual page table then it is * possible to address offsets beyond the mapped area. Just allocate * a maximally sized object for this case. * * The vm_map must be exclusively locked. * No other requirements. */ void vm_map_entry_allocate_object(vm_map_entry_t entry) { vm_object_t obj; if (entry->maptype == VM_MAPTYPE_VPAGETABLE) { obj = vm_object_allocate(OBJT_DEFAULT, 0x7FFFFFFF); /* XXX */ } else { obj = vm_object_allocate(OBJT_DEFAULT, atop(entry->end - entry->start)); } entry->object.vm_object = obj; entry->offset = 0; } /* * Set an initial negative count so the first attempt to reserve * space preloads a bunch of vm_map_entry's for this cpu. Also * pre-allocate 2 vm_map_entries which will be needed by zalloc() to * map a new page for vm_map_entry structures. SMP systems are * particularly sensitive. * * This routine is called in early boot so we cannot just call * vm_map_entry_reserve(). * * Called from the low level boot code only (for each cpu) * * WARNING! Take care not to have too-big a static/BSS structure here * as MAXCPU can be 256+, otherwise the loader's 64MB heap * can get blown out by the kernel plus the initrd image. */ void vm_map_entry_reserve_cpu_init(globaldata_t gd) { vm_map_entry_t entry; int count; int i; atomic_add_int(&gd->gd_vme_avail, -MAP_RESERVE_COUNT * 2); if (gd->gd_cpuid == 0) { entry = &cpu_map_entry_init_bsp[0]; count = MAPENTRYBSP_CACHE; } else { entry = &cpu_map_entry_init_ap[gd->gd_cpuid][0]; count = MAPENTRYAP_CACHE; } for (i = 0; i < count; ++i, ++entry) { entry->next = gd->gd_vme_base; gd->gd_vme_base = entry; } } /* * Reserves vm_map_entry structures so code later-on can manipulate * map_entry structures within a locked map without blocking trying * to allocate a new vm_map_entry. * * No requirements. * * WARNING! We must not decrement gd_vme_avail until after we have * ensured that sufficient entries exist, otherwise we can * get into an endless call recursion in the zalloc code * itself. */ int vm_map_entry_reserve(int count) { struct globaldata *gd = mycpu; vm_map_entry_t entry; /* * Make sure we have enough structures in gd_vme_base to handle * the reservation request. * * Use a critical section to protect against VM faults. It might * not be needed, but we have to be careful here. */ if (gd->gd_vme_avail < count) { crit_enter(); while (gd->gd_vme_avail < count) { entry = zalloc(mapentzone); entry->next = gd->gd_vme_base; gd->gd_vme_base = entry; atomic_add_int(&gd->gd_vme_avail, 1); } crit_exit(); } atomic_add_int(&gd->gd_vme_avail, -count); return(count); } /* * Releases previously reserved vm_map_entry structures that were not * used. If we have too much junk in our per-cpu cache clean some of * it out. * * No requirements. */ void vm_map_entry_release(int count) { struct globaldata *gd = mycpu; vm_map_entry_t entry; vm_map_entry_t efree; count = atomic_fetchadd_int(&gd->gd_vme_avail, count) + count; if (gd->gd_vme_avail > MAP_RESERVE_SLOP) { efree = NULL; crit_enter(); while (gd->gd_vme_avail > MAP_RESERVE_HYST) { entry = gd->gd_vme_base; KKASSERT(entry != NULL); gd->gd_vme_base = entry->next; atomic_add_int(&gd->gd_vme_avail, -1); entry->next = efree; efree = entry; } crit_exit(); while ((entry = efree) != NULL) { efree = efree->next; zfree(mapentzone, entry); } } } /* * Reserve map entry structures for use in kernel_map itself. These * entries have *ALREADY* been reserved on a per-cpu basis when the map * was inited. This function is used by zalloc() to avoid a recursion * when zalloc() itself needs to allocate additional kernel memory. * * This function works like the normal reserve but does not load the * vm_map_entry cache (because that would result in an infinite * recursion). Note that gd_vme_avail may go negative. This is expected. * * Any caller of this function must be sure to renormalize after * potentially eating entries to ensure that the reserve supply * remains intact. * * No requirements. */ int vm_map_entry_kreserve(int count) { struct globaldata *gd = mycpu; atomic_add_int(&gd->gd_vme_avail, -count); KASSERT(gd->gd_vme_base != NULL, ("no reserved entries left, gd_vme_avail = %d", gd->gd_vme_avail)); return(count); } /* * Release previously reserved map entries for kernel_map. We do not * attempt to clean up like the normal release function as this would * cause an unnecessary (but probably not fatal) deep procedure call. * * No requirements. */ void vm_map_entry_krelease(int count) { struct globaldata *gd = mycpu; atomic_add_int(&gd->gd_vme_avail, count); } /* * Allocates a VM map entry for insertion. No entry fields are filled in. * * The entries should have previously been reserved. The reservation count * is tracked in (*countp). * * No requirements. */ static vm_map_entry_t vm_map_entry_create(vm_map_t map, int *countp) { struct globaldata *gd = mycpu; vm_map_entry_t entry; KKASSERT(*countp > 0); --*countp; crit_enter(); entry = gd->gd_vme_base; KASSERT(entry != NULL, ("gd_vme_base NULL! count %d", *countp)); gd->gd_vme_base = entry->next; crit_exit(); return(entry); } /* * Dispose of a vm_map_entry that is no longer being referenced. * * No requirements. */ static void vm_map_entry_dispose(vm_map_t map, vm_map_entry_t entry, int *countp) { struct globaldata *gd = mycpu; ++*countp; crit_enter(); entry->next = gd->gd_vme_base; gd->gd_vme_base = entry; crit_exit(); } /* * Insert/remove entries from maps. * * The related map must be exclusively locked. * The caller must hold map->token * No other requirements. */ static __inline void vm_map_entry_link(vm_map_t map, vm_map_entry_t after_where, vm_map_entry_t entry) { ASSERT_VM_MAP_LOCKED(map); map->nentries++; entry->prev = after_where; entry->next = after_where->next; entry->next->prev = entry; after_where->next = entry; if (vm_map_rb_tree_RB_INSERT(&map->rb_root, entry)) panic("vm_map_entry_link: dup addr map %p ent %p", map, entry); } static __inline void vm_map_entry_unlink(vm_map_t map, vm_map_entry_t entry) { vm_map_entry_t prev; vm_map_entry_t next; ASSERT_VM_MAP_LOCKED(map); if (entry->eflags & MAP_ENTRY_IN_TRANSITION) { panic("vm_map_entry_unlink: attempt to mess with " "locked entry! %p", entry); } prev = entry->prev; next = entry->next; next->prev = prev; prev->next = next; vm_map_rb_tree_RB_REMOVE(&map->rb_root, entry); map->nentries--; } /* * Finds the map entry containing (or immediately preceding) the specified * address in the given map. The entry is returned in (*entry). * * The boolean result indicates whether the address is actually contained * in the map. * * The related map must be locked. * No other requirements. */ boolean_t vm_map_lookup_entry(vm_map_t map, vm_offset_t address, vm_map_entry_t *entry) { vm_map_entry_t tmp; vm_map_entry_t last; ASSERT_VM_MAP_LOCKED(map); /* * Locate the record from the top of the tree. 'last' tracks the * closest prior record and is returned if no match is found, which * in binary tree terms means tracking the most recent right-branch * taken. If there is no prior record, &map->header is returned. */ last = &map->header; tmp = RB_ROOT(&map->rb_root); while (tmp) { if (address >= tmp->start) { if (address < tmp->end) { *entry = tmp; return(TRUE); } last = tmp; tmp = RB_RIGHT(tmp, rb_entry); } else { tmp = RB_LEFT(tmp, rb_entry); } } *entry = last; return (FALSE); } /* * Inserts the given whole VM object into the target map at the specified * address range. The object's size should match that of the address range. * * The map must be exclusively locked. * The object must be held. * The caller must have reserved sufficient vm_map_entry structures. * * If object is non-NULL, ref count must be bumped by caller prior to * making call to account for the new entry. */ int vm_map_insert(vm_map_t map, int *countp, void *map_object, void *map_aux, vm_ooffset_t offset, vm_offset_t start, vm_offset_t end, vm_maptype_t maptype, vm_subsys_t id, vm_prot_t prot, vm_prot_t max, int cow) { vm_map_entry_t new_entry; vm_map_entry_t prev_entry; vm_map_entry_t temp_entry; vm_eflags_t protoeflags; int must_drop = 0; vm_object_t object; if (maptype == VM_MAPTYPE_UKSMAP) object = NULL; else object = map_object; ASSERT_VM_MAP_LOCKED(map); if (object) ASSERT_LWKT_TOKEN_HELD(vm_object_token(object)); /* * Check that the start and end points are not bogus. */ if ((start < map->min_offset) || (end > map->max_offset) || (start >= end)) return (KERN_INVALID_ADDRESS); /* * Find the entry prior to the proposed starting address; if it's part * of an existing entry, this range is bogus. */ if (vm_map_lookup_entry(map, start, &temp_entry)) return (KERN_NO_SPACE); prev_entry = temp_entry; /* * Assert that the next entry doesn't overlap the end point. */ if ((prev_entry->next != &map->header) && (prev_entry->next->start < end)) return (KERN_NO_SPACE); protoeflags = 0; if (cow & MAP_COPY_ON_WRITE) protoeflags |= MAP_ENTRY_COW|MAP_ENTRY_NEEDS_COPY; if (cow & MAP_NOFAULT) { protoeflags |= MAP_ENTRY_NOFAULT; KASSERT(object == NULL, ("vm_map_insert: paradoxical MAP_NOFAULT request")); } if (cow & MAP_DISABLE_SYNCER) protoeflags |= MAP_ENTRY_NOSYNC; if (cow & MAP_DISABLE_COREDUMP) protoeflags |= MAP_ENTRY_NOCOREDUMP; if (cow & MAP_IS_STACK) protoeflags |= MAP_ENTRY_STACK; if (cow & MAP_IS_KSTACK) protoeflags |= MAP_ENTRY_KSTACK; lwkt_gettoken(&map->token); if (object) { /* * When object is non-NULL, it could be shared with another * process. We have to set or clear OBJ_ONEMAPPING * appropriately. * * NOTE: This flag is only applicable to DEFAULT and SWAP * objects and will already be clear in other types * of objects, so a shared object lock is ok for * VNODE objects. */ if ((object->ref_count > 1) || (object->shadow_count != 0)) { vm_object_clear_flag(object, OBJ_ONEMAPPING); } } else if ((prev_entry != &map->header) && (prev_entry->eflags == protoeflags) && (prev_entry->end == start) && (prev_entry->wired_count == 0) && (prev_entry->id == id) && prev_entry->maptype == maptype && maptype == VM_MAPTYPE_NORMAL && ((prev_entry->object.vm_object == NULL) || vm_object_coalesce(prev_entry->object.vm_object, OFF_TO_IDX(prev_entry->offset), (vm_size_t)(prev_entry->end - prev_entry->start), (vm_size_t)(end - prev_entry->end)))) { /* * We were able to extend the object. Determine if we * can extend the previous map entry to include the * new range as well. */ if ((prev_entry->inheritance == VM_INHERIT_DEFAULT) && (prev_entry->protection == prot) && (prev_entry->max_protection == max)) { map->size += (end - prev_entry->end); prev_entry->end = end; vm_map_simplify_entry(map, prev_entry, countp); lwkt_reltoken(&map->token); return (KERN_SUCCESS); } /* * If we can extend the object but cannot extend the * map entry, we have to create a new map entry. We * must bump the ref count on the extended object to * account for it. object may be NULL. * * XXX if object is NULL should we set offset to 0 here ? */ object = prev_entry->object.vm_object; offset = prev_entry->offset + (prev_entry->end - prev_entry->start); if (object) { vm_object_hold(object); vm_object_chain_wait(object, 0); vm_object_reference_locked(object); must_drop = 1; map_object = object; } } /* * NOTE: if conditionals fail, object can be NULL here. This occurs * in things like the buffer map where we manage kva but do not manage * backing objects. */ /* * Create a new entry */ new_entry = vm_map_entry_create(map, countp); new_entry->start = start; new_entry->end = end; new_entry->id = id; new_entry->maptype = maptype; new_entry->eflags = protoeflags; new_entry->object.map_object = map_object; new_entry->aux.master_pde = 0; /* in case size is different */ new_entry->aux.map_aux = map_aux; new_entry->offset = offset; new_entry->inheritance = VM_INHERIT_DEFAULT; new_entry->protection = prot; new_entry->max_protection = max; new_entry->wired_count = 0; /* * Insert the new entry into the list */ vm_map_entry_link(map, prev_entry, new_entry); map->size += new_entry->end - new_entry->start; /* * Don't worry about updating freehint[] when inserting, allow * addresses to be lower than the actual first free spot. */ #if 0 /* * Temporarily removed to avoid MAP_STACK panic, due to * MAP_STACK being a huge hack. Will be added back in * when MAP_STACK (and the user stack mapping) is fixed. */ /* * It may be possible to simplify the entry */ vm_map_simplify_entry(map, new_entry, countp); #endif /* * Try to pre-populate the page table. Mappings governed by virtual * page tables cannot be prepopulated without a lot of work, so * don't try. */ if ((cow & (MAP_PREFAULT|MAP_PREFAULT_PARTIAL)) && maptype != VM_MAPTYPE_VPAGETABLE && maptype != VM_MAPTYPE_UKSMAP) { int dorelock = 0; if (vm_map_relock_enable && (cow & MAP_PREFAULT_RELOCK)) { dorelock = 1; vm_object_lock_swap(); vm_object_drop(object); } pmap_object_init_pt(map->pmap, start, prot, object, OFF_TO_IDX(offset), end - start, cow & MAP_PREFAULT_PARTIAL); if (dorelock) { vm_object_hold(object); vm_object_lock_swap(); } } if (must_drop) vm_object_drop(object); lwkt_reltoken(&map->token); return (KERN_SUCCESS); } /* * Find sufficient space for `length' bytes in the given map, starting at * `start'. Returns 0 on success, 1 on no space. * * This function will returned an arbitrarily aligned pointer. If no * particular alignment is required you should pass align as 1. Note that * the map may return PAGE_SIZE aligned pointers if all the lengths used in * the map are a multiple of PAGE_SIZE, even if you pass a smaller align * argument. * * 'align' should be a power of 2 but is not required to be. * * The map must be exclusively locked. * No other requirements. */ int vm_map_findspace(vm_map_t map, vm_offset_t start, vm_size_t length, vm_size_t align, int flags, vm_offset_t *addr) { vm_map_entry_t entry, next; vm_map_entry_t tmp; vm_offset_t hole_start; vm_offset_t end; vm_offset_t align_mask; if (start < map->min_offset) start = map->min_offset; if (start > map->max_offset) return (1); /* * If the alignment is not a power of 2 we will have to use * a mod/division, set align_mask to a special value. */ if ((align | (align - 1)) + 1 != (align << 1)) align_mask = (vm_offset_t)-1; else align_mask = align - 1; /* * Use freehint to adjust the start point, hopefully reducing * the iteration to O(1). */ hole_start = vm_map_freehint_find(map, length, align); if (start < hole_start) start = hole_start; if (vm_map_lookup_entry(map, start, &tmp)) start = tmp->end; entry = tmp; /* * Look through the rest of the map, trying to fit a new region in the * gap between existing regions, or after the very last region. */ for (;; start = (entry = next)->end) { /* * Adjust the proposed start by the requested alignment, * be sure that we didn't wrap the address. */ if (align_mask == (vm_offset_t)-1) end = roundup(start, align); else end = (start + align_mask) & ~align_mask; if (end < start) return (1); start = end; /* * Find the end of the proposed new region. Be sure we didn't * go beyond the end of the map, or wrap around the address. * Then check to see if this is the last entry or if the * proposed end fits in the gap between this and the next * entry. */ end = start + length; if (end > map->max_offset || end < start) return (1); next = entry->next; /* * If the next entry's start address is beyond the desired * end address we may have found a good entry. * * If the next entry is a stack mapping we do not map into * the stack's reserved space. * * XXX continue to allow mapping into the stack's reserved * space if doing a MAP_STACK mapping inside a MAP_STACK * mapping, for backwards compatibility. But the caller * really should use MAP_STACK | MAP_TRYFIXED if they * want to do that. */ if (next == &map->header) break; if (next->start >= end) { if ((next->eflags & MAP_ENTRY_STACK) == 0) break; if (flags & MAP_STACK) break; if (next->start - next->aux.avail_ssize >= end) break; } } /* * Update the freehint */ vm_map_freehint_update(map, start, length, align); /* * Grow the kernel_map if necessary. pmap_growkernel() will panic * if it fails. The kernel_map is locked and nothing can steal * our address space if pmap_growkernel() blocks. * * NOTE: This may be unconditionally called for kldload areas on * x86_64 because these do not bump kernel_vm_end (which would * fill 128G worth of page tables!). Therefore we must not * retry. */ if (map == &kernel_map) { vm_offset_t kstop; kstop = round_page(start + length); if (kstop > kernel_vm_end) pmap_growkernel(start, kstop); } *addr = start; return (0); } /* * vm_map_find finds an unallocated region in the target address map with * the given length and allocates it. The search is defined to be first-fit * from the specified address; the region found is returned in the same * parameter. * * If object is non-NULL, ref count must be bumped by caller * prior to making call to account for the new entry. * * No requirements. This function will lock the map temporarily. */ int vm_map_find(vm_map_t map, void *map_object, void *map_aux, vm_ooffset_t offset, vm_offset_t *addr, vm_size_t length, vm_size_t align, boolean_t fitit, vm_maptype_t maptype, vm_subsys_t id, vm_prot_t prot, vm_prot_t max, int cow) { vm_offset_t start; vm_object_t object; int result; int count; if (maptype == VM_MAPTYPE_UKSMAP) object = NULL; else object = map_object; start = *addr; count = vm_map_entry_reserve(MAP_RESERVE_COUNT); vm_map_lock(map); if (object) vm_object_hold_shared(object); if (fitit) { if (vm_map_findspace(map, start, length, align, 0, addr)) { if (object) vm_object_drop(object); vm_map_unlock(map); vm_map_entry_release(count); return (KERN_NO_SPACE); } start = *addr; } result = vm_map_insert(map, &count, map_object, map_aux, offset, start, start + length, maptype, id, prot, max, cow); if (object) vm_object_drop(object); vm_map_unlock(map); vm_map_entry_release(count); return (result); } /* * Simplify the given map entry by merging with either neighbor. This * routine also has the ability to merge with both neighbors. * * This routine guarentees that the passed entry remains valid (though * possibly extended). When merging, this routine may delete one or * both neighbors. No action is taken on entries which have their * in-transition flag set. * * The map must be exclusively locked. */ void vm_map_simplify_entry(vm_map_t map, vm_map_entry_t entry, int *countp) { vm_map_entry_t next, prev; vm_size_t prevsize, esize; if (entry->eflags & MAP_ENTRY_IN_TRANSITION) { ++mycpu->gd_cnt.v_intrans_coll; return; } if (entry->maptype == VM_MAPTYPE_SUBMAP) return; if (entry->maptype == VM_MAPTYPE_UKSMAP) return; prev = entry->prev; if (prev != &map->header) { prevsize = prev->end - prev->start; if ( (prev->end == entry->start) && (prev->maptype == entry->maptype) && (prev->object.vm_object == entry->object.vm_object) && (!prev->object.vm_object || (prev->offset + prevsize == entry->offset)) && (prev->eflags == entry->eflags) && (prev->protection == entry->protection) && (prev->max_protection == entry->max_protection) && (prev->inheritance == entry->inheritance) && (prev->id == entry->id) && (prev->wired_count == entry->wired_count)) { vm_map_entry_unlink(map, prev); entry->start = prev->start; entry->offset = prev->offset; if (prev->object.vm_object) vm_object_deallocate(prev->object.vm_object); vm_map_entry_dispose(map, prev, countp); } } next = entry->next; if (next != &map->header) { esize = entry->end - entry->start; if ((entry->end == next->start) && (next->maptype == entry->maptype) && (next->object.vm_object == entry->object.vm_object) && (!entry->object.vm_object || (entry->offset + esize == next->offset)) && (next->eflags == entry->eflags) && (next->protection == entry->protection) && (next->max_protection == entry->max_protection) && (next->inheritance == entry->inheritance) && (next->id == entry->id) && (next->wired_count == entry->wired_count)) { vm_map_entry_unlink(map, next); entry->end = next->end; if (next->object.vm_object) vm_object_deallocate(next->object.vm_object); vm_map_entry_dispose(map, next, countp); } } } /* * Asserts that the given entry begins at or after the specified address. * If necessary, it splits the entry into two. */ #define vm_map_clip_start(map, entry, startaddr, countp) \ { \ if (startaddr > entry->start) \ _vm_map_clip_start(map, entry, startaddr, countp); \ } /* * This routine is called only when it is known that the entry must be split. * * The map must be exclusively locked. */ static void _vm_map_clip_start(vm_map_t map, vm_map_entry_t entry, vm_offset_t start, int *countp) { vm_map_entry_t new_entry; /* * Split off the front portion -- note that we must insert the new * entry BEFORE this one, so that this entry has the specified * starting address. */ vm_map_simplify_entry(map, entry, countp); /* * If there is no object backing this entry, we might as well create * one now. If we defer it, an object can get created after the map * is clipped, and individual objects will be created for the split-up * map. This is a bit of a hack, but is also about the best place to * put this improvement. */ if (entry->object.vm_object == NULL && !map->system_map && VM_MAP_ENTRY_WITHIN_PARTITION(entry)) { vm_map_entry_allocate_object(entry); } new_entry = vm_map_entry_create(map, countp); *new_entry = *entry; new_entry->end = start; entry->offset += (start - entry->start); entry->start = start; vm_map_entry_link(map, entry->prev, new_entry); switch(entry->maptype) { case VM_MAPTYPE_NORMAL: case VM_MAPTYPE_VPAGETABLE: if (new_entry->object.vm_object) { vm_object_hold(new_entry->object.vm_object); vm_object_chain_wait(new_entry->object.vm_object, 0); vm_object_reference_locked(new_entry->object.vm_object); vm_object_drop(new_entry->object.vm_object); } break; default: break; } } /* * Asserts that the given entry ends at or before the specified address. * If necessary, it splits the entry into two. * * The map must be exclusively locked. */ #define vm_map_clip_end(map, entry, endaddr, countp) \ { \ if (endaddr < entry->end) \ _vm_map_clip_end(map, entry, endaddr, countp); \ } /* * This routine is called only when it is known that the entry must be split. * * The map must be exclusively locked. */ static void _vm_map_clip_end(vm_map_t map, vm_map_entry_t entry, vm_offset_t end, int *countp) { vm_map_entry_t new_entry; /* * If there is no object backing this entry, we might as well create * one now. If we defer it, an object can get created after the map * is clipped, and individual objects will be created for the split-up * map. This is a bit of a hack, but is also about the best place to * put this improvement. */ if (entry->object.vm_object == NULL && !map->system_map && VM_MAP_ENTRY_WITHIN_PARTITION(entry)) { vm_map_entry_allocate_object(entry); } /* * Create a new entry and insert it AFTER the specified entry */ new_entry = vm_map_entry_create(map, countp); *new_entry = *entry; new_entry->start = entry->end = end; new_entry->offset += (end - entry->start); vm_map_entry_link(map, entry, new_entry); switch(entry->maptype) { case VM_MAPTYPE_NORMAL: case VM_MAPTYPE_VPAGETABLE: if (new_entry->object.vm_object) { vm_object_hold(new_entry->object.vm_object); vm_object_chain_wait(new_entry->object.vm_object, 0); vm_object_reference_locked(new_entry->object.vm_object); vm_object_drop(new_entry->object.vm_object); } break; default: break; } } /* * Asserts that the starting and ending region addresses fall within the * valid range for the map. */ #define VM_MAP_RANGE_CHECK(map, start, end) \ { \ if (start < vm_map_min(map)) \ start = vm_map_min(map); \ if (end > vm_map_max(map)) \ end = vm_map_max(map); \ if (start > end) \ start = end; \ } /* * Used to block when an in-transition collison occurs. The map * is unlocked for the sleep and relocked before the return. */ void vm_map_transition_wait(vm_map_t map, int relock) { tsleep_interlock(map, 0); vm_map_unlock(map); tsleep(map, PINTERLOCKED, "vment", 0); if (relock) vm_map_lock(map); } /* * When we do blocking operations with the map lock held it is * possible that a clip might have occured on our in-transit entry, * requiring an adjustment to the entry in our loop. These macros * help the pageable and clip_range code deal with the case. The * conditional costs virtually nothing if no clipping has occured. */ #define CLIP_CHECK_BACK(entry, save_start) \ do { \ while (entry->start != save_start) { \ entry = entry->prev; \ KASSERT(entry != &map->header, ("bad entry clip")); \ } \ } while(0) #define CLIP_CHECK_FWD(entry, save_end) \ do { \ while (entry->end != save_end) { \ entry = entry->next; \ KASSERT(entry != &map->header, ("bad entry clip")); \ } \ } while(0) /* * Clip the specified range and return the base entry. The * range may cover several entries starting at the returned base * and the first and last entry in the covering sequence will be * properly clipped to the requested start and end address. * * If no holes are allowed you should pass the MAP_CLIP_NO_HOLES * flag. * * The MAP_ENTRY_IN_TRANSITION flag will be set for the entries * covered by the requested range. * * The map must be exclusively locked on entry and will remain locked * on return. If no range exists or the range contains holes and you * specified that no holes were allowed, NULL will be returned. This * routine may temporarily unlock the map in order avoid a deadlock when * sleeping. */ static vm_map_entry_t vm_map_clip_range(vm_map_t map, vm_offset_t start, vm_offset_t end, int *countp, int flags) { vm_map_entry_t start_entry; vm_map_entry_t entry; /* * Locate the entry and effect initial clipping. The in-transition * case does not occur very often so do not try to optimize it. */ again: if (vm_map_lookup_entry(map, start, &start_entry) == FALSE) return (NULL); entry = start_entry; if (entry->eflags & MAP_ENTRY_IN_TRANSITION) { entry->eflags |= MAP_ENTRY_NEEDS_WAKEUP; ++mycpu->gd_cnt.v_intrans_coll; ++mycpu->gd_cnt.v_intrans_wait; vm_map_transition_wait(map, 1); /* * entry and/or start_entry may have been clipped while * we slept, or may have gone away entirely. We have * to restart from the lookup. */ goto again; } /* * Since we hold an exclusive map lock we do not have to restart * after clipping, even though clipping may block in zalloc. */ vm_map_clip_start(map, entry, start, countp); vm_map_clip_end(map, entry, end, countp); entry->eflags |= MAP_ENTRY_IN_TRANSITION; /* * Scan entries covered by the range. When working on the next * entry a restart need only re-loop on the current entry which * we have already locked, since 'next' may have changed. Also, * even though entry is safe, it may have been clipped so we * have to iterate forwards through the clip after sleeping. */ while (entry->next != &map->header && entry->next->start < end) { vm_map_entry_t next = entry->next; if (flags & MAP_CLIP_NO_HOLES) { if (next->start > entry->end) { vm_map_unclip_range(map, start_entry, start, entry->end, countp, flags); return(NULL); } } if (next->eflags & MAP_ENTRY_IN_TRANSITION) { vm_offset_t save_end = entry->end; next->eflags |= MAP_ENTRY_NEEDS_WAKEUP; ++mycpu->gd_cnt.v_intrans_coll; ++mycpu->gd_cnt.v_intrans_wait; vm_map_transition_wait(map, 1); /* * clips might have occured while we blocked. */ CLIP_CHECK_FWD(entry, save_end); CLIP_CHECK_BACK(start_entry, start); continue; } /* * No restart necessary even though clip_end may block, we * are holding the map lock. */ vm_map_clip_end(map, next, end, countp); next->eflags |= MAP_ENTRY_IN_TRANSITION; entry = next; } if (flags & MAP_CLIP_NO_HOLES) { if (entry->end != end) { vm_map_unclip_range(map, start_entry, start, entry->end, countp, flags); return(NULL); } } return(start_entry); } /* * Undo the effect of vm_map_clip_range(). You should pass the same * flags and the same range that you passed to vm_map_clip_range(). * This code will clear the in-transition flag on the entries and * wake up anyone waiting. This code will also simplify the sequence * and attempt to merge it with entries before and after the sequence. * * The map must be locked on entry and will remain locked on return. * * Note that you should also pass the start_entry returned by * vm_map_clip_range(). However, if you block between the two calls * with the map unlocked please be aware that the start_entry may * have been clipped and you may need to scan it backwards to find * the entry corresponding with the original start address. You are * responsible for this, vm_map_unclip_range() expects the correct * start_entry to be passed to it and will KASSERT otherwise. */ static void vm_map_unclip_range(vm_map_t map, vm_map_entry_t start_entry, vm_offset_t start, vm_offset_t end, int *countp, int flags) { vm_map_entry_t entry; entry = start_entry; KASSERT(entry->start == start, ("unclip_range: illegal base entry")); while (entry != &map->header && entry->start < end) { KASSERT(entry->eflags & MAP_ENTRY_IN_TRANSITION, ("in-transition flag not set during unclip on: %p", entry)); KASSERT(entry->end <= end, ("unclip_range: tail wasn't clipped")); entry->eflags &= ~MAP_ENTRY_IN_TRANSITION; if (entry->eflags & MAP_ENTRY_NEEDS_WAKEUP) { entry->eflags &= ~MAP_ENTRY_NEEDS_WAKEUP; wakeup(map); } entry = entry->next; } /* * Simplification does not block so there is no restart case. */ entry = start_entry; while (entry != &map->header && entry->start < end) { vm_map_simplify_entry(map, entry, countp); entry = entry->next; } } /* * Mark the given range as handled by a subordinate map. * * This range must have been created with vm_map_find(), and no other * operations may have been performed on this range prior to calling * vm_map_submap(). * * Submappings cannot be removed. * * No requirements. */ int vm_map_submap(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_map_t submap) { vm_map_entry_t entry; int result = KERN_INVALID_ARGUMENT; int count; count = vm_map_entry_reserve(MAP_RESERVE_COUNT); vm_map_lock(map); VM_MAP_RANGE_CHECK(map, start, end); if (vm_map_lookup_entry(map, start, &entry)) { vm_map_clip_start(map, entry, start, &count); } else { entry = entry->next; } vm_map_clip_end(map, entry, end, &count); if ((entry->start == start) && (entry->end == end) && ((entry->eflags & MAP_ENTRY_COW) == 0) && (entry->object.vm_object == NULL)) { entry->object.sub_map = submap; entry->maptype = VM_MAPTYPE_SUBMAP; result = KERN_SUCCESS; } vm_map_unlock(map); vm_map_entry_release(count); return (result); } /* * Sets the protection of the specified address region in the target map. * If "set_max" is specified, the maximum protection is to be set; * otherwise, only the current protection is affected. * * The protection is not applicable to submaps, but is applicable to normal * maps and maps governed by virtual page tables. For example, when operating * on a virtual page table our protection basically controls how COW occurs * on the backing object, whereas the virtual page table abstraction itself * is an abstraction for userland. * * No requirements. */ int vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_prot_t new_prot, boolean_t set_max) { vm_map_entry_t current; vm_map_entry_t entry; int count; count = vm_map_entry_reserve(MAP_RESERVE_COUNT); vm_map_lock(map); VM_MAP_RANGE_CHECK(map, start, end); if (vm_map_lookup_entry(map, start, &entry)) { vm_map_clip_start(map, entry, start, &count); } else { entry = entry->next; } /* * Make a first pass to check for protection violations. */ current = entry; while ((current != &map->header) && (current->start < end)) { if (current->maptype == VM_MAPTYPE_SUBMAP) { vm_map_unlock(map); vm_map_entry_release(count); return (KERN_INVALID_ARGUMENT); } if ((new_prot & current->max_protection) != new_prot) { vm_map_unlock(map); vm_map_entry_release(count); return (KERN_PROTECTION_FAILURE); } /* * When making a SHARED+RW file mmap writable, update * v_lastwrite_ts. */ if (new_prot & PROT_WRITE && (current->eflags & MAP_ENTRY_NEEDS_COPY) == 0 && (current->maptype == VM_MAPTYPE_NORMAL || current->maptype == VM_MAPTYPE_VPAGETABLE) && current->object.vm_object && current->object.vm_object->type == OBJT_VNODE) { struct vnode *vp; vp = current->object.vm_object->handle; if (vp && vn_lock(vp, LK_EXCLUSIVE | LK_RETRY | LK_NOWAIT) == 0) { vfs_timestamp(&vp->v_lastwrite_ts); vsetflags(vp, VLASTWRITETS); vn_unlock(vp); } } current = current->next; } /* * Go back and fix up protections. [Note that clipping is not * necessary the second time.] */ current = entry; while ((current != &map->header) && (current->start < end)) { vm_prot_t old_prot; vm_map_clip_end(map, current, end, &count); old_prot = current->protection; if (set_max) { current->max_protection = new_prot; current->protection = new_prot & old_prot; } else { current->protection = new_prot; } /* * Update physical map if necessary. Worry about copy-on-write * here -- CHECK THIS XXX */ if (current->protection != old_prot) { #define MASK(entry) (((entry)->eflags & MAP_ENTRY_COW) ? ~VM_PROT_WRITE : \ VM_PROT_ALL) pmap_protect(map->pmap, current->start, current->end, current->protection & MASK(current)); #undef MASK } vm_map_simplify_entry(map, current, &count); current = current->next; } vm_map_unlock(map); vm_map_entry_release(count); return (KERN_SUCCESS); } /* * This routine traverses a processes map handling the madvise * system call. Advisories are classified as either those effecting * the vm_map_entry structure, or those effecting the underlying * objects. * * The <value> argument is used for extended madvise calls. * * No requirements. */ int vm_map_madvise(vm_map_t map, vm_offset_t start, vm_offset_t end, int behav, off_t value) { vm_map_entry_t current, entry; int modify_map = 0; int error = 0; int count; /* * Some madvise calls directly modify the vm_map_entry, in which case * we need to use an exclusive lock on the map and we need to perform * various clipping operations. Otherwise we only need a read-lock * on the map. */ count = vm_map_entry_reserve(MAP_RESERVE_COUNT); switch(behav) { case MADV_NORMAL: case MADV_SEQUENTIAL: case MADV_RANDOM: case MADV_NOSYNC: case MADV_AUTOSYNC: case MADV_NOCORE: case MADV_CORE: case MADV_SETMAP: modify_map = 1; vm_map_lock(map); break; case MADV_INVAL: case MADV_WILLNEED: case MADV_DONTNEED: case MADV_FREE: vm_map_lock_read(map); break; default: vm_map_entry_release(count); return (EINVAL); } /* * Locate starting entry and clip if necessary. */ VM_MAP_RANGE_CHECK(map, start, end); if (vm_map_lookup_entry(map, start, &entry)) { if (modify_map) vm_map_clip_start(map, entry, start, &count); } else { entry = entry->next; } if (modify_map) { /* * madvise behaviors that are implemented in the vm_map_entry. * * We clip the vm_map_entry so that behavioral changes are * limited to the specified address range. */ for (current = entry; (current != &map->header) && (current->start < end); current = current->next ) { if (current->maptype == VM_MAPTYPE_SUBMAP) continue; vm_map_clip_end(map, current, end, &count); switch (behav) { case MADV_NORMAL: vm_map_entry_set_behavior(current, MAP_ENTRY_BEHAV_NORMAL); break; case MADV_SEQUENTIAL: vm_map_entry_set_behavior(current, MAP_ENTRY_BEHAV_SEQUENTIAL); break; case MADV_RANDOM: vm_map_entry_set_behavior(current, MAP_ENTRY_BEHAV_RANDOM); break; case MADV_NOSYNC: current->eflags |= MAP_ENTRY_NOSYNC; break; case MADV_AUTOSYNC: current->eflags &= ~MAP_ENTRY_NOSYNC; break; case MADV_NOCORE: current->eflags |= MAP_ENTRY_NOCOREDUMP; break; case MADV_CORE: current->eflags &= ~MAP_ENTRY_NOCOREDUMP; break; case MADV_SETMAP: /* * Set the page directory page for a map * governed by a virtual page table. Mark * the entry as being governed by a virtual * page table if it is not. * * XXX the page directory page is stored * in the avail_ssize field if the map_entry. * * XXX the map simplification code does not * compare this field so weird things may * happen if you do not apply this function * to the entire mapping governed by the * virtual page table. */ if (current->maptype != VM_MAPTYPE_VPAGETABLE) { error = EINVAL; break; } current->aux.master_pde = value; pmap_remove(map->pmap, current->start, current->end); break; case MADV_INVAL: /* * Invalidate the related pmap entries, used * to flush portions of the real kernel's * pmap when the caller has removed or * modified existing mappings in a virtual * page table. * * (exclusive locked map version does not * need the range interlock). */ pmap_remove(map->pmap, current->start, current->end); break; default: error = EINVAL; break; } vm_map_simplify_entry(map, current, &count); } vm_map_unlock(map); } else { vm_pindex_t pindex; vm_pindex_t delta; /* * madvise behaviors that are implemented in the underlying * vm_object. * * Since we don't clip the vm_map_entry, we have to clip * the vm_object pindex and count. * * NOTE! These functions are only supported on normal maps, * except MADV_INVAL which is also supported on * virtual page tables. */ for (current = entry; (current != &map->header) && (current->start < end); current = current->next ) { vm_offset_t useStart; if (current->maptype != VM_MAPTYPE_NORMAL && (current->maptype != VM_MAPTYPE_VPAGETABLE || behav != MADV_INVAL)) { continue; } pindex = OFF_TO_IDX(current->offset); delta = atop(current->end - current->start); useStart = current->start; if (current->start < start) { pindex += atop(start - current->start); delta -= atop(start - current->start); useStart = start; } if (current->end > end) delta -= atop(current->end - end); if ((vm_spindex_t)delta <= 0) continue; if (behav == MADV_INVAL) { /* * Invalidate the related pmap entries, used * to flush portions of the real kernel's * pmap when the caller has removed or * modified existing mappings in a virtual * page table. * * (shared locked map version needs the * interlock, see vm_fault()). */ struct vm_map_ilock ilock; KASSERT(useStart >= VM_MIN_USER_ADDRESS && useStart + ptoa(delta) <= VM_MAX_USER_ADDRESS, ("Bad range %016jx-%016jx (%016jx)", useStart, useStart + ptoa(delta), delta)); vm_map_interlock(map, &ilock, useStart, useStart + ptoa(delta)); pmap_remove(map->pmap, useStart, useStart + ptoa(delta)); vm_map_deinterlock(map, &ilock); } else { vm_object_madvise(current->object.vm_object, pindex, delta, behav); } /* * Try to populate the page table. Mappings governed * by virtual page tables cannot be pre-populated * without a lot of work so don't try. */ if (behav == MADV_WILLNEED && current->maptype != VM_MAPTYPE_VPAGETABLE) { pmap_object_init_pt( map->pmap, useStart, current->protection, current->object.vm_object, pindex, (count << PAGE_SHIFT), MAP_PREFAULT_MADVISE ); } } vm_map_unlock_read(map); } vm_map_entry_release(count); return(error); } /* * Sets the inheritance of the specified address range in the target map. * Inheritance affects how the map will be shared with child maps at the * time of vm_map_fork. */ int vm_map_inherit(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_inherit_t new_inheritance) { vm_map_entry_t entry; vm_map_entry_t temp_entry; int count; switch (new_inheritance) { case VM_INHERIT_NONE: case VM_INHERIT_COPY: case VM_INHERIT_SHARE: break; default: return (KERN_INVALID_ARGUMENT); } count = vm_map_entry_reserve(MAP_RESERVE_COUNT); vm_map_lock(map); VM_MAP_RANGE_CHECK(map, start, end); if (vm_map_lookup_entry(map, start, &temp_entry)) { entry = temp_entry; vm_map_clip_start(map, entry, start, &count); } else entry = temp_entry->next; while ((entry != &map->header) && (entry->start < end)) { vm_map_clip_end(map, entry, end, &count); entry->inheritance = new_inheritance; vm_map_simplify_entry(map, entry, &count); entry = entry->next; } vm_map_unlock(map); vm_map_entry_release(count); return (KERN_SUCCESS); } /* * Implement the semantics of mlock */ int vm_map_unwire(vm_map_t map, vm_offset_t start, vm_offset_t real_end, boolean_t new_pageable) { vm_map_entry_t entry; vm_map_entry_t start_entry; vm_offset_t end; int rv = KERN_SUCCESS; int count; count = vm_map_entry_reserve(MAP_RESERVE_COUNT); vm_map_lock(map); VM_MAP_RANGE_CHECK(map, start, real_end); end = real_end; start_entry = vm_map_clip_range(map, start, end, &count, MAP_CLIP_NO_HOLES); if (start_entry == NULL) { vm_map_unlock(map); vm_map_entry_release(count); return (KERN_INVALID_ADDRESS); } if (new_pageable == 0) { entry = start_entry; while ((entry != &map->header) && (entry->start < end)) { vm_offset_t save_start; vm_offset_t save_end; /* * Already user wired or hard wired (trivial cases) */ if (entry->eflags & MAP_ENTRY_USER_WIRED) { entry = entry->next; continue; } if (entry->wired_count != 0) { entry->wired_count++; entry->eflags |= MAP_ENTRY_USER_WIRED; entry = entry->next; continue; } /* * A new wiring requires instantiation of appropriate * management structures and the faulting in of the * page. */ if (entry->maptype == VM_MAPTYPE_NORMAL || entry->maptype == VM_MAPTYPE_VPAGETABLE) { int copyflag = entry->eflags & MAP_ENTRY_NEEDS_COPY; if (copyflag && ((entry->protection & VM_PROT_WRITE) != 0)) { vm_map_entry_shadow(entry, 0); } else if (entry->object.vm_object == NULL && !map->system_map) { vm_map_entry_allocate_object(entry); } } entry->wired_count++; entry->eflags |= MAP_ENTRY_USER_WIRED; /* * Now fault in the area. Note that vm_fault_wire() * may release the map lock temporarily, it will be * relocked on return. The in-transition * flag protects the entries. */ save_start = entry->start; save_end = entry->end; rv = vm_fault_wire(map, entry, TRUE, 0); if (rv) { CLIP_CHECK_BACK(entry, save_start); for (;;) { KASSERT(entry->wired_count == 1, ("bad wired_count on entry")); entry->eflags &= ~MAP_ENTRY_USER_WIRED; entry->wired_count = 0; if (entry->end == save_end) break; entry = entry->next; KASSERT(entry != &map->header, ("bad entry clip during backout")); } end = save_start; /* unwire the rest */ break; } /* * note that even though the entry might have been * clipped, the USER_WIRED flag we set prevents * duplication so we do not have to do a * clip check. */ entry = entry->next; } /* * If we failed fall through to the unwiring section to * unwire what we had wired so far. 'end' has already * been adjusted. */ if (rv) new_pageable = 1; /* * start_entry might have been clipped if we unlocked the * map and blocked. No matter how clipped it has gotten * there should be a fragment that is on our start boundary. */ CLIP_CHECK_BACK(start_entry, start); } /* * Deal with the unwiring case. */ if (new_pageable) { /* * This is the unwiring case. We must first ensure that the * range to be unwired is really wired down. We know there * are no holes. */ entry = start_entry; while ((entry != &map->header) && (entry->start < end)) { if ((entry->eflags & MAP_ENTRY_USER_WIRED) == 0) { rv = KERN_INVALID_ARGUMENT; goto done; } KASSERT(entry->wired_count != 0, ("wired count was 0 with USER_WIRED set! %p", entry)); entry = entry->next; } /* * Now decrement the wiring count for each region. If a region * becomes completely unwired, unwire its physical pages and * mappings. */ /* * The map entries are processed in a loop, checking to * make sure the entry is wired and asserting it has a wired * count. However, another loop was inserted more-or-less in * the middle of the unwiring path. This loop picks up the * "entry" loop variable from the first loop without first * setting it to start_entry. Naturally, the secound loop * is never entered and the pages backing the entries are * never unwired. This can lead to a leak of wired pages. */ entry = start_entry; while ((entry != &map->header) && (entry->start < end)) { KASSERT(entry->eflags & MAP_ENTRY_USER_WIRED, ("expected USER_WIRED on entry %p", entry)); entry->eflags &= ~MAP_ENTRY_USER_WIRED; entry->wired_count--; if (entry->wired_count == 0) vm_fault_unwire(map, entry); entry = entry->next; } } done: vm_map_unclip_range(map, start_entry, start, real_end, &count, MAP_CLIP_NO_HOLES); vm_map_unlock(map); vm_map_entry_release(count); return (rv); } /* * Sets the pageability of the specified address range in the target map. * Regions specified as not pageable require locked-down physical * memory and physical page maps. * * The map must not be locked, but a reference must remain to the map * throughout the call. * * This function may be called via the zalloc path and must properly * reserve map entries for kernel_map. * * No requirements. */ int vm_map_wire(vm_map_t map, vm_offset_t start, vm_offset_t real_end, int kmflags) { vm_map_entry_t entry; vm_map_entry_t start_entry; vm_offset_t end; int rv = KERN_SUCCESS; int count; if (kmflags & KM_KRESERVE) count = vm_map_entry_kreserve(MAP_RESERVE_COUNT); else count = vm_map_entry_reserve(MAP_RESERVE_COUNT); vm_map_lock(map); VM_MAP_RANGE_CHECK(map, start, real_end); end = real_end; start_entry = vm_map_clip_range(map, start, end, &count, MAP_CLIP_NO_HOLES); if (start_entry == NULL) { vm_map_unlock(map); rv = KERN_INVALID_ADDRESS; goto failure; } if ((kmflags & KM_PAGEABLE) == 0) { /* * Wiring. * * 1. Holding the write lock, we create any shadow or zero-fill * objects that need to be created. Then we clip each map * entry to the region to be wired and increment its wiring * count. We create objects before clipping the map entries * to avoid object proliferation. * * 2. We downgrade to a read lock, and call vm_fault_wire to * fault in the pages for any newly wired area (wired_count is * 1). * * Downgrading to a read lock for vm_fault_wire avoids a * possible deadlock with another process that may have faulted * on one of the pages to be wired (it would mark the page busy, * blocking us, then in turn block on the map lock that we * hold). Because of problems in the recursive lock package, * we cannot upgrade to a write lock in vm_map_lookup. Thus, * any actions that require the write lock must be done * beforehand. Because we keep the read lock on the map, the * copy-on-write status of the entries we modify here cannot * change. */ entry = start_entry; while ((entry != &map->header) && (entry->start < end)) { /* * Trivial case if the entry is already wired */ if (entry->wired_count) { entry->wired_count++; entry = entry->next; continue; } /* * The entry is being newly wired, we have to setup * appropriate management structures. A shadow * object is required for a copy-on-write region, * or a normal object for a zero-fill region. We * do not have to do this for entries that point to sub * maps because we won't hold the lock on the sub map. */ if (entry->maptype == VM_MAPTYPE_NORMAL || entry->maptype == VM_MAPTYPE_VPAGETABLE) { int copyflag = entry->eflags & MAP_ENTRY_NEEDS_COPY; if (copyflag && ((entry->protection & VM_PROT_WRITE) != 0)) { vm_map_entry_shadow(entry, 0); } else if (entry->object.vm_object == NULL && !map->system_map) { vm_map_entry_allocate_object(entry); } } entry->wired_count++; entry = entry->next; } /* * Pass 2. */ /* * HACK HACK HACK HACK * * vm_fault_wire() temporarily unlocks the map to avoid * deadlocks. The in-transition flag from vm_map_clip_range * call should protect us from changes while the map is * unlocked. T * * NOTE: Previously this comment stated that clipping might * still occur while the entry is unlocked, but from * what I can tell it actually cannot. * * It is unclear whether the CLIP_CHECK_*() calls * are still needed but we keep them in anyway. * * HACK HACK HACK HACK */ entry = start_entry; while (entry != &map->header && entry->start < end) { /* * If vm_fault_wire fails for any page we need to undo * what has been done. We decrement the wiring count * for those pages which have not yet been wired (now) * and unwire those that have (later). */ vm_offset_t save_start = entry->start; vm_offset_t save_end = entry->end; if (entry->wired_count == 1) rv = vm_fault_wire(map, entry, FALSE, kmflags); if (rv) { CLIP_CHECK_BACK(entry, save_start); for (;;) { KASSERT(entry->wired_count == 1, ("wired_count changed unexpectedly")); entry->wired_count = 0; if (entry->end == save_end) break; entry = entry->next; KASSERT(entry != &map->header, ("bad entry clip during backout")); } end = save_start; break; } CLIP_CHECK_FWD(entry, save_end); entry = entry->next; } /* * If a failure occured undo everything by falling through * to the unwiring code. 'end' has already been adjusted * appropriately. */ if (rv) kmflags |= KM_PAGEABLE; /* * start_entry is still IN_TRANSITION but may have been * clipped since vm_fault_wire() unlocks and relocks the * map. No matter how clipped it has gotten there should * be a fragment that is on our start boundary. */ CLIP_CHECK_BACK(start_entry, start); } if (kmflags & KM_PAGEABLE) { /* * This is the unwiring case. We must first ensure that the * range to be unwired is really wired down. We know there * are no holes. */ entry = start_entry; while ((entry != &map->header) && (entry->start < end)) { if (entry->wired_count == 0) { rv = KERN_INVALID_ARGUMENT; goto done; } entry = entry->next; } /* * Now decrement the wiring count for each region. If a region * becomes completely unwired, unwire its physical pages and * mappings. */ entry = start_entry; while ((entry != &map->header) && (entry->start < end)) { entry->wired_count--; if (entry->wired_count == 0) vm_fault_unwire(map, entry); entry = entry->next; } } done: vm_map_unclip_range(map, start_entry, start, real_end, &count, MAP_CLIP_NO_HOLES); vm_map_unlock(map); failure: if (kmflags & KM_KRESERVE) vm_map_entry_krelease(count); else vm_map_entry_release(count); return (rv); } /* * Mark a newly allocated address range as wired but do not fault in * the pages. The caller is expected to load the pages into the object. * * The map must be locked on entry and will remain locked on return. * No other requirements. */ void vm_map_set_wired_quick(vm_map_t map, vm_offset_t addr, vm_size_t size, int *countp) { vm_map_entry_t scan; vm_map_entry_t entry; entry = vm_map_clip_range(map, addr, addr + size, countp, MAP_CLIP_NO_HOLES); for (scan = entry; scan != &map->header && scan->start < addr + size; scan = scan->next) { KKASSERT(scan->wired_count == 0); scan->wired_count = 1; } vm_map_unclip_range(map, entry, addr, addr + size, countp, MAP_CLIP_NO_HOLES); } /* * Push any dirty cached pages in the address range to their pager. * If syncio is TRUE, dirty pages are written synchronously. * If invalidate is TRUE, any cached pages are freed as well. * * This routine is called by sys_msync() * * Returns an error if any part of the specified range is not mapped. * * No requirements. */ int vm_map_clean(vm_map_t map, vm_offset_t start, vm_offset_t end, boolean_t syncio, boolean_t invalidate) { vm_map_entry_t current; vm_map_entry_t entry; vm_size_t size; vm_object_t object; vm_object_t tobj; vm_ooffset_t offset; vm_map_lock_read(map); VM_MAP_RANGE_CHECK(map, start, end); if (!vm_map_lookup_entry(map, start, &entry)) { vm_map_unlock_read(map); return (KERN_INVALID_ADDRESS); } lwkt_gettoken(&map->token); /* * Make a first pass to check for holes. */ for (current = entry; current->start < end; current = current->next) { if (current->maptype == VM_MAPTYPE_SUBMAP) { lwkt_reltoken(&map->token); vm_map_unlock_read(map); return (KERN_INVALID_ARGUMENT); } if (end > current->end && (current->next == &map->header || current->end != current->next->start)) { lwkt_reltoken(&map->token); vm_map_unlock_read(map); return (KERN_INVALID_ADDRESS); } } if (invalidate) pmap_remove(vm_map_pmap(map), start, end); /* * Make a second pass, cleaning/uncaching pages from the indicated * objects as we go. */ for (current = entry; current->start < end; current = current->next) { offset = current->offset + (start - current->start); size = (end <= current->end ? end : current->end) - start; switch(current->maptype) { case VM_MAPTYPE_SUBMAP: { vm_map_t smap; vm_map_entry_t tentry; vm_size_t tsize; smap = current->object.sub_map; vm_map_lock_read(smap); vm_map_lookup_entry(smap, offset, &tentry); tsize = tentry->end - offset; if (tsize < size) size = tsize; object = tentry->object.vm_object; offset = tentry->offset + (offset - tentry->start); vm_map_unlock_read(smap); break; } case VM_MAPTYPE_NORMAL: case VM_MAPTYPE_VPAGETABLE: object = current->object.vm_object; break; default: object = NULL; break; } if (object) vm_object_hold(object); /* * Note that there is absolutely no sense in writing out * anonymous objects, so we track down the vnode object * to write out. * We invalidate (remove) all pages from the address space * anyway, for semantic correctness. * * note: certain anonymous maps, such as MAP_NOSYNC maps, * may start out with a NULL object. */ while (object && (tobj = object->backing_object) != NULL) { vm_object_hold(tobj); if (tobj == object->backing_object) { vm_object_lock_swap(); offset += object->backing_object_offset; vm_object_drop(object); object = tobj; if (object->size < OFF_TO_IDX(offset + size)) size = IDX_TO_OFF(object->size) - offset; break; } vm_object_drop(tobj); } if (object && (object->type == OBJT_VNODE) && (current->protection & VM_PROT_WRITE) && (object->flags & OBJ_NOMSYNC) == 0) { /* * Flush pages if writing is allowed, invalidate them * if invalidation requested. Pages undergoing I/O * will be ignored by vm_object_page_remove(). * * We cannot lock the vnode and then wait for paging * to complete without deadlocking against vm_fault. * Instead we simply call vm_object_page_remove() and * allow it to block internally on a page-by-page * basis when it encounters pages undergoing async * I/O. */ int flags; /* no chain wait needed for vnode objects */ vm_object_reference_locked(object); vn_lock(object->handle, LK_EXCLUSIVE | LK_RETRY); flags = (syncio || invalidate) ? OBJPC_SYNC : 0; flags |= invalidate ? OBJPC_INVAL : 0; /* * When operating on a virtual page table just * flush the whole object. XXX we probably ought * to */ switch(current->maptype) { case VM_MAPTYPE_NORMAL: vm_object_page_clean(object, OFF_TO_IDX(offset), OFF_TO_IDX(offset + size + PAGE_MASK), flags); break; case VM_MAPTYPE_VPAGETABLE: vm_object_page_clean(object, 0, 0, flags); break; } vn_unlock(((struct vnode *)object->handle)); vm_object_deallocate_locked(object); } if (object && invalidate && ((object->type == OBJT_VNODE) || (object->type == OBJT_DEVICE) || (object->type == OBJT_MGTDEVICE))) { int clean_only = ((object->type == OBJT_DEVICE) || (object->type == OBJT_MGTDEVICE)) ? FALSE : TRUE; /* no chain wait needed for vnode/device objects */ vm_object_reference_locked(object); switch(current->maptype) { case VM_MAPTYPE_NORMAL: vm_object_page_remove(object, OFF_TO_IDX(offset), OFF_TO_IDX(offset + size + PAGE_MASK), clean_only); break; case VM_MAPTYPE_VPAGETABLE: vm_object_page_remove(object, 0, 0, clean_only); break; } vm_object_deallocate_locked(object); } start += size; if (object) vm_object_drop(object); } lwkt_reltoken(&map->token); vm_map_unlock_read(map); return (KERN_SUCCESS); } /* * Make the region specified by this entry pageable. * * The vm_map must be exclusively locked. */ static void vm_map_entry_unwire(vm_map_t map, vm_map_entry_t entry) { entry->eflags &= ~MAP_ENTRY_USER_WIRED; entry->wired_count = 0; vm_fault_unwire(map, entry); } /* * Deallocate the given entry from the target map. * * The vm_map must be exclusively locked. */ static void vm_map_entry_delete(vm_map_t map, vm_map_entry_t entry, int *countp) { vm_map_entry_unlink(map, entry); map->size -= entry->end - entry->start; switch(entry->maptype) { case VM_MAPTYPE_NORMAL: case VM_MAPTYPE_VPAGETABLE: case VM_MAPTYPE_SUBMAP: vm_object_deallocate(entry->object.vm_object); break; case VM_MAPTYPE_UKSMAP: /* XXX TODO */ break; default: break; } vm_map_entry_dispose(map, entry, countp); } /* * Deallocates the given address range from the target map. * * The vm_map must be exclusively locked. */ int vm_map_delete(vm_map_t map, vm_offset_t start, vm_offset_t end, int *countp) { vm_object_t object; vm_map_entry_t entry; vm_map_entry_t first_entry; vm_offset_t hole_start; ASSERT_VM_MAP_LOCKED(map); lwkt_gettoken(&map->token); again: /* * Find the start of the region, and clip it. Set entry to point * at the first record containing the requested address or, if no * such record exists, the next record with a greater address. The * loop will run from this point until a record beyond the termination * address is encountered. * * Adjust freehint[] for either the clip case or the extension case. * * GGG see other GGG comment. */ if (vm_map_lookup_entry(map, start, &first_entry)) { entry = first_entry; vm_map_clip_start(map, entry, start, countp); hole_start = start; } else { entry = first_entry->next; if (entry == &map->header) hole_start = first_entry->start; else hole_start = first_entry->end; } /* * Step through all entries in this region */ while ((entry != &map->header) && (entry->start < end)) { vm_map_entry_t next; vm_offset_t s, e; vm_pindex_t offidxstart, offidxend, count; /* * If we hit an in-transition entry we have to sleep and * retry. It's easier (and not really slower) to just retry * since this case occurs so rarely and the hint is already * pointing at the right place. We have to reset the * start offset so as not to accidently delete an entry * another process just created in vacated space. */ if (entry->eflags & MAP_ENTRY_IN_TRANSITION) { entry->eflags |= MAP_ENTRY_NEEDS_WAKEUP; start = entry->start; ++mycpu->gd_cnt.v_intrans_coll; ++mycpu->gd_cnt.v_intrans_wait; vm_map_transition_wait(map, 1); goto again; } vm_map_clip_end(map, entry, end, countp); s = entry->start; e = entry->end; next = entry->next; offidxstart = OFF_TO_IDX(entry->offset); count = OFF_TO_IDX(e - s); switch(entry->maptype) { case VM_MAPTYPE_NORMAL: case VM_MAPTYPE_VPAGETABLE: case VM_MAPTYPE_SUBMAP: object = entry->object.vm_object; break; default: object = NULL; break; } /* * Unwire before removing addresses from the pmap; otherwise, * unwiring will put the entries back in the pmap. * * Generally speaking, doing a bulk pmap_remove() before * removing the pages from the VM object is better at * reducing unnecessary IPIs. The pmap code is now optimized * to not blindly iterate the range when pt and pd pages * are missing. */ if (entry->wired_count != 0) vm_map_entry_unwire(map, entry); offidxend = offidxstart + count; if (object == &kernel_object) { pmap_remove(map->pmap, s, e); vm_object_hold(object); vm_object_page_remove(object, offidxstart, offidxend, FALSE); vm_object_drop(object); } else if (object && object->type != OBJT_DEFAULT && object->type != OBJT_SWAP) { /* * vnode object routines cannot be chain-locked, * but since we aren't removing pages from the * object here we can use a shared hold. */ vm_object_hold_shared(object); pmap_remove(map->pmap, s, e); vm_object_drop(object); } else if (object) { vm_object_hold(object); vm_object_chain_acquire(object, 0); pmap_remove(map->pmap, s, e); if (object != NULL && object->ref_count != 1 && (object->flags & (OBJ_NOSPLIT|OBJ_ONEMAPPING)) == OBJ_ONEMAPPING && (object->type == OBJT_DEFAULT || object->type == OBJT_SWAP)) { /* * When ONEMAPPING is set we can destroy the * pages underlying the entry's range. */ vm_object_collapse(object, NULL); vm_object_page_remove(object, offidxstart, offidxend, FALSE); if (object->type == OBJT_SWAP) { swap_pager_freespace(object, offidxstart, count); } if (offidxend >= object->size && offidxstart < object->size) { object->size = offidxstart; } } vm_object_chain_release(object); vm_object_drop(object); } else if (entry->maptype == VM_MAPTYPE_UKSMAP) { pmap_remove(map->pmap, s, e); } /* * Delete the entry (which may delete the object) only after * removing all pmap entries pointing to its pages. * (Otherwise, its page frames may be reallocated, and any * modify bits will be set in the wrong object!) */ vm_map_entry_delete(map, entry, countp); entry = next; } if (entry == &map->header) vm_map_freehint_hole(map, hole_start, entry->end - hole_start); else vm_map_freehint_hole(map, hole_start, entry->start - hole_start); lwkt_reltoken(&map->token); return (KERN_SUCCESS); } /* * Remove the given address range from the target map. * This is the exported form of vm_map_delete. * * No requirements. */ int vm_map_remove(vm_map_t map, vm_offset_t start, vm_offset_t end) { int result; int count; count = vm_map_entry_reserve(MAP_RESERVE_COUNT); vm_map_lock(map); VM_MAP_RANGE_CHECK(map, start, end); result = vm_map_delete(map, start, end, &count); vm_map_unlock(map); vm_map_entry_release(count); return (result); } /* * Assert that the target map allows the specified privilege on the * entire address region given. The entire region must be allocated. * * The caller must specify whether the vm_map is already locked or not. */ boolean_t vm_map_check_protection(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_prot_t protection, boolean_t have_lock) { vm_map_entry_t entry; vm_map_entry_t tmp_entry; boolean_t result; if (have_lock == FALSE) vm_map_lock_read(map); if (!vm_map_lookup_entry(map, start, &tmp_entry)) { if (have_lock == FALSE) vm_map_unlock_read(map); return (FALSE); } entry = tmp_entry; result = TRUE; while (start < end) { if (entry == &map->header) { result = FALSE; break; } /* * No holes allowed! */ if (start < entry->start) { result = FALSE; break; } /* * Check protection associated with entry. */ if ((entry->protection & protection) != protection) { result = FALSE; break; } /* go to next entry */ start = entry->end; entry = entry->next; } if (have_lock == FALSE) vm_map_unlock_read(map); return (result); } /* * If appropriate this function shadows the original object with a new object * and moves the VM pages from the original object to the new object. * The original object will also be collapsed, if possible. * * Caller must supply entry->object.vm_object held and chain_acquired, and * should chain_release and drop the object upon return. * * We can only do this for normal memory objects with a single mapping, and * it only makes sense to do it if there are 2 or more refs on the original * object. i.e. typically a memory object that has been extended into * multiple vm_map_entry's with non-overlapping ranges. * * This makes it easier to remove unused pages and keeps object inheritance * from being a negative impact on memory usage. * * On return the (possibly new) entry->object.vm_object will have an * additional ref on it for the caller to dispose of (usually by cloning * the vm_map_entry). The additional ref had to be done in this routine * to avoid racing a collapse. The object's ONEMAPPING flag will also be * cleared. * * The vm_map must be locked and its token held. */ static void vm_map_split(vm_map_entry_t entry, vm_object_t oobject) { /* OPTIMIZED */ vm_object_t nobject, bobject; vm_offset_t s, e; vm_page_t m; vm_pindex_t offidxstart, offidxend, idx; vm_size_t size; vm_ooffset_t offset; int useshadowlist; /* * Optimize away object locks for vnode objects. Important exit/exec * critical path. * * OBJ_ONEMAPPING doesn't apply to vnode objects but clear the flag * anyway. */ if (oobject->type != OBJT_DEFAULT && oobject->type != OBJT_SWAP) { vm_object_reference_quick(oobject); vm_object_clear_flag(oobject, OBJ_ONEMAPPING); return; } #if 0 /* * Original object cannot be split? */ if (oobject->handle == NULL) { vm_object_reference_locked_chain_held(oobject); vm_object_clear_flag(oobject, OBJ_ONEMAPPING); return; } #endif /* * Collapse original object with its backing store as an * optimization to reduce chain lengths when possible. * * If ref_count <= 1 there aren't other non-overlapping vm_map_entry's * for oobject, so there's no point collapsing it. * * Then re-check whether the object can be split. */ vm_object_collapse(oobject, NULL); if (oobject->ref_count <= 1 || (oobject->type != OBJT_DEFAULT && oobject->type != OBJT_SWAP) || (oobject->flags & (OBJ_NOSPLIT|OBJ_ONEMAPPING)) != OBJ_ONEMAPPING) { vm_object_reference_locked_chain_held(oobject); vm_object_clear_flag(oobject, OBJ_ONEMAPPING); return; } /* * Acquire the chain lock on the backing object. * * Give bobject an additional ref count for when it will be shadowed * by nobject. */ useshadowlist = 0; if ((bobject = oobject->backing_object) != NULL) { if (bobject->type != OBJT_VNODE) { useshadowlist = 1; vm_object_hold(bobject); vm_object_chain_wait(bobject, 0); /* ref for shadowing below */ vm_object_reference_locked(bobject); vm_object_chain_acquire(bobject, 0); KKASSERT(oobject->backing_object == bobject); KKASSERT((bobject->flags & OBJ_DEAD) == 0); } else { /* * vnodes are not placed on the shadow list but * they still get another ref for the backing_object * reference. */ vm_object_reference_quick(bobject); } } /* * Calculate the object page range and allocate the new object. */ offset = entry->offset; s = entry->start; e = entry->end; offidxstart = OFF_TO_IDX(offset); offidxend = offidxstart + OFF_TO_IDX(e - s); size = offidxend - offidxstart; switch(oobject->type) { case OBJT_DEFAULT: nobject = default_pager_alloc(NULL, IDX_TO_OFF(size), VM_PROT_ALL, 0); break; case OBJT_SWAP: nobject = swap_pager_alloc(NULL, IDX_TO_OFF(size), VM_PROT_ALL, 0); break; default: /* not reached */ nobject = NULL; KKASSERT(0); } /* * If we could not allocate nobject just clear ONEMAPPING on * oobject and return. */ if (nobject == NULL) { if (bobject) { if (useshadowlist) { vm_object_chain_release(bobject); vm_object_deallocate(bobject); vm_object_drop(bobject); } else { vm_object_deallocate(bobject); } } vm_object_reference_locked_chain_held(oobject); vm_object_clear_flag(oobject, OBJ_ONEMAPPING); return; } /* * The new object will replace entry->object.vm_object so it needs * a second reference (the caller expects an additional ref). */ vm_object_hold(nobject); vm_object_reference_locked(nobject); vm_object_chain_acquire(nobject, 0); /* * nobject shadows bobject (oobject already shadows bobject). * * Adding an object to bobject's shadow list requires refing bobject * which we did above in the useshadowlist case. * * XXX it is unclear if we need to clear ONEMAPPING on bobject here * or not. */ if (bobject) { nobject->backing_object_offset = oobject->backing_object_offset + IDX_TO_OFF(offidxstart); nobject->backing_object = bobject; if (useshadowlist) { bobject->shadow_count++; atomic_add_int(&bobject->generation, 1); LIST_INSERT_HEAD(&bobject->shadow_head, nobject, shadow_list); vm_object_clear_flag(bobject, OBJ_ONEMAPPING); /*XXX*/ vm_object_set_flag(nobject, OBJ_ONSHADOW); } } /* * Move the VM pages from oobject to nobject */ for (idx = 0; idx < size; idx++) { vm_page_t m; m = vm_page_lookup_busy_wait(oobject, offidxstart + idx, TRUE, "vmpg"); if (m == NULL) continue; /* * We must wait for pending I/O to complete before we can * rename the page. * * We do not have to VM_PROT_NONE the page as mappings should * not be changed by this operation. * * NOTE: The act of renaming a page updates chaingen for both * objects. */ vm_page_rename(m, nobject, idx); /* page automatically made dirty by rename and cache handled */ /* page remains busy */ } if (oobject->type == OBJT_SWAP) { vm_object_pip_add(oobject, 1); /* * copy oobject pages into nobject and destroy unneeded * pages in shadow object. */ swap_pager_copy(oobject, nobject, offidxstart, 0); vm_object_pip_wakeup(oobject); } /* * Wakeup the pages we played with. No spl protection is needed * for a simple wakeup. */ for (idx = 0; idx < size; idx++) { m = vm_page_lookup(nobject, idx); if (m) { KKASSERT(m->busy_count & PBUSY_LOCKED); vm_page_wakeup(m); } } entry->object.vm_object = nobject; entry->offset = 0LL; /* * The map is being split and nobject is going to wind up on both * vm_map_entry's, so make sure OBJ_ONEMAPPING is cleared on * nobject. */ vm_object_clear_flag(nobject, OBJ_ONEMAPPING); /* * Cleanup * * NOTE: There is no need to remove OBJ_ONEMAPPING from oobject, the * related pages were moved and are no longer applicable to the * original object. * * NOTE: Deallocate oobject (due to its entry->object.vm_object being * replaced by nobject). */ vm_object_chain_release(nobject); vm_object_drop(nobject); if (bobject && useshadowlist) { vm_object_chain_release(bobject); vm_object_drop(bobject); } #if 0 if (oobject->resident_page_count) { kprintf("oobject %p still contains %jd pages!\n", oobject, (intmax_t)oobject->resident_page_count); for (idx = 0; idx < size; idx++) { vm_page_t m; m = vm_page_lookup_busy_wait(oobject, offidxstart + idx, TRUE, "vmpg"); if (m) { kprintf("oobject %p idx %jd\n", oobject, offidxstart + idx); vm_page_wakeup(m); } } } #endif /*vm_object_clear_flag(oobject, OBJ_ONEMAPPING);*/ vm_object_deallocate_locked(oobject); } /* * Copies the contents of the source entry to the destination * entry. The entries *must* be aligned properly. * * The vm_maps must be exclusively locked. * The vm_map's token must be held. * * Because the maps are locked no faults can be in progress during the * operation. */ static void vm_map_copy_entry(vm_map_t src_map, vm_map_t dst_map, vm_map_entry_t src_entry, vm_map_entry_t dst_entry) { vm_object_t src_object; vm_object_t oobject; if (dst_entry->maptype == VM_MAPTYPE_SUBMAP || dst_entry->maptype == VM_MAPTYPE_UKSMAP) return; if (src_entry->maptype == VM_MAPTYPE_SUBMAP || src_entry->maptype == VM_MAPTYPE_UKSMAP) return; if (src_entry->wired_count == 0) { /* * If the source entry is marked needs_copy, it is already * write-protected. * * To avoid interacting with a vm_fault that might have * released its vm_map, we must acquire the fronting * object. */ oobject = src_entry->object.vm_object; if (oobject) { vm_object_hold(oobject); vm_object_chain_acquire(oobject, 0); } if ((src_entry->eflags & MAP_ENTRY_NEEDS_COPY) == 0) { pmap_protect(src_map->pmap, src_entry->start, src_entry->end, src_entry->protection & ~VM_PROT_WRITE); } /* * Make a copy of the object. * * The object must be locked prior to checking the object type * and for the call to vm_object_collapse() and vm_map_split(). * We cannot use *_hold() here because the split code will * probably try to destroy the object. The lock is a pool * token and doesn't care. * * We must bump src_map->timestamp when setting * MAP_ENTRY_NEEDS_COPY to force any concurrent fault * to retry, otherwise the concurrent fault might improperly * install a RW pte when its supposed to be a RO(COW) pte. * This race can occur because a vnode-backed fault may have * to temporarily release the map lock. This was handled * when the caller locked the map exclusively. */ if (oobject) { vm_map_split(src_entry, oobject); src_object = src_entry->object.vm_object; dst_entry->object.vm_object = src_object; src_entry->eflags |= (MAP_ENTRY_COW | MAP_ENTRY_NEEDS_COPY); dst_entry->eflags |= (MAP_ENTRY_COW | MAP_ENTRY_NEEDS_COPY); dst_entry->offset = src_entry->offset; } else { dst_entry->object.vm_object = NULL; dst_entry->offset = 0; } pmap_copy(dst_map->pmap, src_map->pmap, dst_entry->start, dst_entry->end - dst_entry->start, src_entry->start); if (oobject) { vm_object_chain_release(oobject); vm_object_drop(oobject); } } else { /* * Of course, wired down pages can't be set copy-on-write. * Cause wired pages to be copied into the new map by * simulating faults (the new pages are pageable) */ vm_fault_copy_entry(dst_map, src_map, dst_entry, src_entry); } } /* * vmspace_fork: * Create a new process vmspace structure and vm_map * based on those of an existing process. The new map * is based on the old map, according to the inheritance * values on the regions in that map. * * The source map must not be locked. * No requirements. */ static void vmspace_fork_normal_entry(vm_map_t old_map, vm_map_t new_map, vm_map_entry_t old_entry, int *countp); static void vmspace_fork_uksmap_entry(vm_map_t old_map, vm_map_t new_map, vm_map_entry_t old_entry, int *countp); struct vmspace * vmspace_fork(struct vmspace *vm1) { struct vmspace *vm2; vm_map_t old_map = &vm1->vm_map; vm_map_t new_map; vm_map_entry_t old_entry; int count; lwkt_gettoken(&vm1->vm_map.token); vm_map_lock(old_map); vm2 = vmspace_alloc(old_map->min_offset, old_map->max_offset); lwkt_gettoken(&vm2->vm_map.token); /* * We must bump the timestamp to force any concurrent fault * to retry. */ bcopy(&vm1->vm_startcopy, &vm2->vm_startcopy, (caddr_t)&vm1->vm_endcopy - (caddr_t)&vm1->vm_startcopy); new_map = &vm2->vm_map; /* XXX */ new_map->timestamp = 1; vm_map_lock(new_map); count = 0; old_entry = old_map->header.next; while (old_entry != &old_map->header) { ++count; old_entry = old_entry->next; } count = vm_map_entry_reserve(count + MAP_RESERVE_COUNT); old_entry = old_map->header.next; while (old_entry != &old_map->header) { switch(old_entry->maptype) { case VM_MAPTYPE_SUBMAP: panic("vm_map_fork: encountered a submap"); break; case VM_MAPTYPE_UKSMAP: vmspace_fork_uksmap_entry(old_map, new_map, old_entry, &count); break; case VM_MAPTYPE_NORMAL: case VM_MAPTYPE_VPAGETABLE: vmspace_fork_normal_entry(old_map, new_map, old_entry, &count); break; } old_entry = old_entry->next; } new_map->size = old_map->size; vm_map_unlock(old_map); vm_map_unlock(new_map); vm_map_entry_release(count); lwkt_reltoken(&vm2->vm_map.token); lwkt_reltoken(&vm1->vm_map.token); return (vm2); } static void vmspace_fork_normal_entry(vm_map_t old_map, vm_map_t new_map, vm_map_entry_t old_entry, int *countp) { vm_map_entry_t new_entry; vm_object_t object; switch (old_entry->inheritance) { case VM_INHERIT_NONE: break; case VM_INHERIT_SHARE: /* * Clone the entry, creating the shared object if * necessary. */ if (old_entry->object.vm_object == NULL) vm_map_entry_allocate_object(old_entry); if (old_entry->eflags & MAP_ENTRY_NEEDS_COPY) { /* * Shadow a map_entry which needs a copy, * replacing its object with a new object * that points to the old one. Ask the * shadow code to automatically add an * additional ref. We can't do it afterwords * because we might race a collapse. The call * to vm_map_entry_shadow() will also clear * OBJ_ONEMAPPING. */ vm_map_entry_shadow(old_entry, 1); } else if (old_entry->object.vm_object) { /* * We will make a shared copy of the object, * and must clear OBJ_ONEMAPPING. * * Optimize vnode objects. OBJ_ONEMAPPING * is non-applicable but clear it anyway, * and its terminal so we don't have to deal * with chains. Reduces SMP conflicts. * * XXX assert that object.vm_object != NULL * since we allocate it above. */ object = old_entry->object.vm_object; if (object->type == OBJT_VNODE) { vm_object_reference_quick(object); vm_object_clear_flag(object, OBJ_ONEMAPPING); } else { vm_object_hold(object); vm_object_chain_wait(object, 0); vm_object_reference_locked(object); vm_object_clear_flag(object, OBJ_ONEMAPPING); vm_object_drop(object); } } /* * Clone the entry. We've already bumped the ref on * any vm_object. */ new_entry = vm_map_entry_create(new_map, countp); *new_entry = *old_entry; new_entry->eflags &= ~MAP_ENTRY_USER_WIRED; new_entry->wired_count = 0; /* * Insert the entry into the new map -- we know we're * inserting at the end of the new map. */ vm_map_entry_link(new_map, new_map->header.prev, new_entry); /* * Update the physical map */ pmap_copy(new_map->pmap, old_map->pmap, new_entry->start, (old_entry->end - old_entry->start), old_entry->start); break; case VM_INHERIT_COPY: /* * Clone the entry and link into the map. */ new_entry = vm_map_entry_create(new_map, countp); *new_entry = *old_entry; new_entry->eflags &= ~MAP_ENTRY_USER_WIRED; new_entry->wired_count = 0; new_entry->object.vm_object = NULL; vm_map_entry_link(new_map, new_map->header.prev, new_entry); vm_map_copy_entry(old_map, new_map, old_entry, new_entry); break; } } /* * When forking user-kernel shared maps, the map might change in the * child so do not try to copy the underlying pmap entries. */ static void vmspace_fork_uksmap_entry(vm_map_t old_map, vm_map_t new_map, vm_map_entry_t old_entry, int *countp) { vm_map_entry_t new_entry; new_entry = vm_map_entry_create(new_map, countp); *new_entry = *old_entry; new_entry->eflags &= ~MAP_ENTRY_USER_WIRED; new_entry->wired_count = 0; vm_map_entry_link(new_map, new_map->header.prev, new_entry); } /* * Create an auto-grow stack entry * * No requirements. */ int vm_map_stack (vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, int flags, vm_prot_t prot, vm_prot_t max, int cow) { vm_map_entry_t prev_entry; vm_map_entry_t new_stack_entry; vm_size_t init_ssize; int rv; int count; vm_offset_t tmpaddr; cow |= MAP_IS_STACK; if (max_ssize < sgrowsiz) init_ssize = max_ssize; else init_ssize = sgrowsiz; count = vm_map_entry_reserve(MAP_RESERVE_COUNT); vm_map_lock(map); /* * Find space for the mapping */ if ((flags & (MAP_FIXED | MAP_TRYFIXED)) == 0) { if (vm_map_findspace(map, addrbos, max_ssize, 1, flags, &tmpaddr)) { vm_map_unlock(map); vm_map_entry_release(count); return (KERN_NO_SPACE); } addrbos = tmpaddr; } /* If addr is already mapped, no go */ if (vm_map_lookup_entry(map, addrbos, &prev_entry)) { vm_map_unlock(map); vm_map_entry_release(count); return (KERN_NO_SPACE); } #if 0 /* XXX already handled by kern_mmap() */ /* If we would blow our VMEM resource limit, no go */ if (map->size + init_ssize > curproc->p_rlimit[RLIMIT_VMEM].rlim_cur) { vm_map_unlock(map); vm_map_entry_release(count); return (KERN_NO_SPACE); } #endif /* * If we can't accomodate max_ssize in the current mapping, * no go. However, we need to be aware that subsequent user * mappings might map into the space we have reserved for * stack, and currently this space is not protected. * * Hopefully we will at least detect this condition * when we try to grow the stack. */ if ((prev_entry->next != &map->header) && (prev_entry->next->start < addrbos + max_ssize)) { vm_map_unlock(map); vm_map_entry_release(count); return (KERN_NO_SPACE); } /* * We initially map a stack of only init_ssize. We will * grow as needed later. Since this is to be a grow * down stack, we map at the top of the range. * * Note: we would normally expect prot and max to be * VM_PROT_ALL, and cow to be 0. Possibly we should * eliminate these as input parameters, and just * pass these values here in the insert call. */ rv = vm_map_insert(map, &count, NULL, NULL, 0, addrbos + max_ssize - init_ssize, addrbos + max_ssize, VM_MAPTYPE_NORMAL, VM_SUBSYS_STACK, prot, max, cow); /* Now set the avail_ssize amount */ if (rv == KERN_SUCCESS) { if (prev_entry != &map->header) vm_map_clip_end(map, prev_entry, addrbos + max_ssize - init_ssize, &count); new_stack_entry = prev_entry->next; if (new_stack_entry->end != addrbos + max_ssize || new_stack_entry->start != addrbos + max_ssize - init_ssize) panic ("Bad entry start/end for new stack entry"); else new_stack_entry->aux.avail_ssize = max_ssize - init_ssize; } vm_map_unlock(map); vm_map_entry_release(count); return (rv); } /* * Attempts to grow a vm stack entry. Returns KERN_SUCCESS if the * desired address is already mapped, or if we successfully grow * the stack. Also returns KERN_SUCCESS if addr is outside the * stack range (this is strange, but preserves compatibility with * the grow function in vm_machdep.c). * * No requirements. */ int vm_map_growstack (vm_map_t map, vm_offset_t addr) { vm_map_entry_t prev_entry; vm_map_entry_t stack_entry; vm_map_entry_t new_stack_entry; struct vmspace *vm; struct lwp *lp; struct proc *p; vm_offset_t end; int grow_amount; int rv = KERN_SUCCESS; int is_procstack; int use_read_lock = 1; int count; /* * Find the vm */ lp = curthread->td_lwp; p = curthread->td_proc; KKASSERT(lp != NULL); vm = lp->lwp_vmspace; /* * Growstack is only allowed on the current process. We disallow * other use cases, e.g. trying to access memory via procfs that * the stack hasn't grown into. */ if (map != &vm->vm_map) { return KERN_FAILURE; } count = vm_map_entry_reserve(MAP_RESERVE_COUNT); Retry: if (use_read_lock) vm_map_lock_read(map); else vm_map_lock(map); /* If addr is already in the entry range, no need to grow.*/ if (vm_map_lookup_entry(map, addr, &prev_entry)) goto done; if ((stack_entry = prev_entry->next) == &map->header) goto done; if (prev_entry == &map->header) end = stack_entry->start - stack_entry->aux.avail_ssize; else end = prev_entry->end; /* * This next test mimics the old grow function in vm_machdep.c. * It really doesn't quite make sense, but we do it anyway * for compatibility. * * If not growable stack, return success. This signals the * caller to proceed as he would normally with normal vm. */ if (stack_entry->aux.avail_ssize < 1 || addr >= stack_entry->start || addr < stack_entry->start - stack_entry->aux.avail_ssize) { goto done; } /* Find the minimum grow amount */ grow_amount = roundup (stack_entry->start - addr, PAGE_SIZE); if (grow_amount > stack_entry->aux.avail_ssize) { rv = KERN_NO_SPACE; goto done; } /* * If there is no longer enough space between the entries * nogo, and adjust the available space. Note: this * should only happen if the user has mapped into the * stack area after the stack was created, and is * probably an error. * * This also effectively destroys any guard page the user * might have intended by limiting the stack size. */ if (grow_amount > stack_entry->start - end) { if (use_read_lock && vm_map_lock_upgrade(map)) { /* lost lock */ use_read_lock = 0; goto Retry; } use_read_lock = 0; stack_entry->aux.avail_ssize = stack_entry->start - end; rv = KERN_NO_SPACE; goto done; } is_procstack = addr >= (vm_offset_t)vm->vm_maxsaddr; /* If this is the main process stack, see if we're over the * stack limit. */ if (is_procstack && (ctob(vm->vm_ssize) + grow_amount > p->p_rlimit[RLIMIT_STACK].rlim_cur)) { rv = KERN_NO_SPACE; goto done; } /* Round up the grow amount modulo SGROWSIZ */ grow_amount = roundup (grow_amount, sgrowsiz); if (grow_amount > stack_entry->aux.avail_ssize) { grow_amount = stack_entry->aux.avail_ssize; } if (is_procstack && (ctob(vm->vm_ssize) + grow_amount > p->p_rlimit[RLIMIT_STACK].rlim_cur)) { grow_amount = p->p_rlimit[RLIMIT_STACK].rlim_cur - ctob(vm->vm_ssize); } /* If we would blow our VMEM resource limit, no go */ if (map->size + grow_amount > p->p_rlimit[RLIMIT_VMEM].rlim_cur) { rv = KERN_NO_SPACE; goto done; } if (use_read_lock && vm_map_lock_upgrade(map)) { /* lost lock */ use_read_lock = 0; goto Retry; } use_read_lock = 0; /* Get the preliminary new entry start value */ addr = stack_entry->start - grow_amount; /* If this puts us into the previous entry, cut back our growth * to the available space. Also, see the note above. */ if (addr < end) { stack_entry->aux.avail_ssize = stack_entry->start - end; addr = end; } rv = vm_map_insert(map, &count, NULL, NULL, 0, addr, stack_entry->start, VM_MAPTYPE_NORMAL, VM_SUBSYS_STACK, VM_PROT_ALL, VM_PROT_ALL, 0); /* Adjust the available stack space by the amount we grew. */ if (rv == KERN_SUCCESS) { if (prev_entry != &map->header) vm_map_clip_end(map, prev_entry, addr, &count); new_stack_entry = prev_entry->next; if (new_stack_entry->end != stack_entry->start || new_stack_entry->start != addr) panic ("Bad stack grow start/end in new stack entry"); else { new_stack_entry->aux.avail_ssize = stack_entry->aux.avail_ssize - (new_stack_entry->end - new_stack_entry->start); if (is_procstack) vm->vm_ssize += btoc(new_stack_entry->end - new_stack_entry->start); } if (map->flags & MAP_WIREFUTURE) vm_map_unwire(map, new_stack_entry->start, new_stack_entry->end, FALSE); } done: if (use_read_lock) vm_map_unlock_read(map); else vm_map_unlock(map); vm_map_entry_release(count); return (rv); } /* * Unshare the specified VM space for exec. If other processes are * mapped to it, then create a new one. The new vmspace is null. * * No requirements. */ void vmspace_exec(struct proc *p, struct vmspace *vmcopy) { struct vmspace *oldvmspace = p->p_vmspace; struct vmspace *newvmspace; vm_map_t map = &p->p_vmspace->vm_map; /* * If we are execing a resident vmspace we fork it, otherwise * we create a new vmspace. Note that exitingcnt is not * copied to the new vmspace. */ lwkt_gettoken(&oldvmspace->vm_map.token); if (vmcopy) { newvmspace = vmspace_fork(vmcopy); lwkt_gettoken(&newvmspace->vm_map.token); } else { newvmspace = vmspace_alloc(map->min_offset, map->max_offset); lwkt_gettoken(&newvmspace->vm_map.token); bcopy(&oldvmspace->vm_startcopy, &newvmspace->vm_startcopy, (caddr_t)&oldvmspace->vm_endcopy - (caddr_t)&oldvmspace->vm_startcopy); } /* * Finish initializing the vmspace before assigning it * to the process. The vmspace will become the current vmspace * if p == curproc. */ pmap_pinit2(vmspace_pmap(newvmspace)); pmap_replacevm(p, newvmspace, 0); lwkt_reltoken(&newvmspace->vm_map.token); lwkt_reltoken(&oldvmspace->vm_map.token); vmspace_rel(oldvmspace); } /* * Unshare the specified VM space for forcing COW. This * is called by rfork, for the (RFMEM|RFPROC) == 0 case. */ void vmspace_unshare(struct proc *p) { struct vmspace *oldvmspace = p->p_vmspace; struct vmspace *newvmspace; lwkt_gettoken(&oldvmspace->vm_map.token); if (vmspace_getrefs(oldvmspace) == 1) { lwkt_reltoken(&oldvmspace->vm_map.token); return; } newvmspace = vmspace_fork(oldvmspace); lwkt_gettoken(&newvmspace->vm_map.token); pmap_pinit2(vmspace_pmap(newvmspace)); pmap_replacevm(p, newvmspace, 0); lwkt_reltoken(&newvmspace->vm_map.token); lwkt_reltoken(&oldvmspace->vm_map.token); vmspace_rel(oldvmspace); } /* * vm_map_hint: return the beginning of the best area suitable for * creating a new mapping with "prot" protection. * * No requirements. */ vm_offset_t vm_map_hint(struct proc *p, vm_offset_t addr, vm_prot_t prot) { struct vmspace *vms = p->p_vmspace; if (!randomize_mmap || addr != 0) { /* * Set a reasonable start point for the hint if it was * not specified or if it falls within the heap space. * Hinted mmap()s do not allocate out of the heap space. */ if (addr == 0 || (addr >= round_page((vm_offset_t)vms->vm_taddr) && addr < round_page((vm_offset_t)vms->vm_daddr + maxdsiz))) { addr = round_page((vm_offset_t)vms->vm_daddr + maxdsiz); } return addr; } addr = (vm_offset_t)vms->vm_daddr + MAXDSIZ; addr += karc4random() & (MIN((256 * 1024 * 1024), MAXDSIZ) - 1); return (round_page(addr)); } /* * Finds the VM object, offset, and protection for a given virtual address * in the specified map, assuming a page fault of the type specified. * * Leaves the map in question locked for read; return values are guaranteed * until a vm_map_lookup_done call is performed. Note that the map argument * is in/out; the returned map must be used in the call to vm_map_lookup_done. * * A handle (out_entry) is returned for use in vm_map_lookup_done, to make * that fast. * * If a lookup is requested with "write protection" specified, the map may * be changed to perform virtual copying operations, although the data * referenced will remain the same. * * No requirements. */ int vm_map_lookup(vm_map_t *var_map, /* IN/OUT */ vm_offset_t vaddr, vm_prot_t fault_typea, vm_map_entry_t *out_entry, /* OUT */ vm_object_t *object, /* OUT */ vm_pindex_t *pindex, /* OUT */ vm_prot_t *out_prot, /* OUT */ int *wflags) /* OUT */ { vm_map_entry_t entry; vm_map_t map = *var_map; vm_prot_t prot; vm_prot_t fault_type = fault_typea; int use_read_lock = 1; int rv = KERN_SUCCESS; int count; thread_t td = curthread; /* * vm_map_entry_reserve() implements an important mitigation * against mmap() span running the kernel out of vm_map_entry * structures, but it can also cause an infinite call recursion. * Use td_nest_count to prevent an infinite recursion (allows * the vm_map code to dig into the pcpu vm_map_entry reserve). */ count = 0; if (td->td_nest_count == 0) { ++td->td_nest_count; count = vm_map_entry_reserve(MAP_RESERVE_COUNT); --td->td_nest_count; } RetryLookup: if (use_read_lock) vm_map_lock_read(map); else vm_map_lock(map); /* * Always do a full lookup. The hint doesn't get us much anymore * now that the map is RB'd. */ cpu_ccfence(); *out_entry = &map->header; *object = NULL; { vm_map_entry_t tmp_entry; if (!vm_map_lookup_entry(map, vaddr, &tmp_entry)) { rv = KERN_INVALID_ADDRESS; goto done; } entry = tmp_entry; *out_entry = entry; } /* * Handle submaps. */ if (entry->maptype == VM_MAPTYPE_SUBMAP) { vm_map_t old_map = map; *var_map = map = entry->object.sub_map; if (use_read_lock) vm_map_unlock_read(old_map); else vm_map_unlock(old_map); use_read_lock = 1; goto RetryLookup; } /* * Check whether this task is allowed to have this page. * Note the special case for MAP_ENTRY_COW pages with an override. * This is to implement a forced COW for debuggers. */ if (fault_type & VM_PROT_OVERRIDE_WRITE) prot = entry->max_protection; else prot = entry->protection; fault_type &= (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE); if ((fault_type & prot) != fault_type) { rv = KERN_PROTECTION_FAILURE; goto done; } if ((entry->eflags & MAP_ENTRY_USER_WIRED) && (entry->eflags & MAP_ENTRY_COW) && (fault_type & VM_PROT_WRITE) && (fault_typea & VM_PROT_OVERRIDE_WRITE) == 0) { rv = KERN_PROTECTION_FAILURE; goto done; } /* * If this page is not pageable, we have to get it for all possible * accesses. */ *wflags = 0; if (entry->wired_count) { *wflags |= FW_WIRED; prot = fault_type = entry->protection; } /* * Virtual page tables may need to update the accessed (A) bit * in a page table entry. Upgrade the fault to a write fault for * that case if the map will support it. If the map does not support * it the page table entry simply will not be updated. */ if (entry->maptype == VM_MAPTYPE_VPAGETABLE) { if (prot & VM_PROT_WRITE) fault_type |= VM_PROT_WRITE; } if (curthread->td_lwp && curthread->td_lwp->lwp_vmspace && pmap_emulate_ad_bits(&curthread->td_lwp->lwp_vmspace->vm_pmap)) { if ((prot & VM_PROT_WRITE) == 0) fault_type |= VM_PROT_WRITE; } /* * Only NORMAL and VPAGETABLE maps are object-based. UKSMAPs are not. */ if (entry->maptype != VM_MAPTYPE_NORMAL && entry->maptype != VM_MAPTYPE_VPAGETABLE) { *object = NULL; goto skip; } /* * If the entry was copy-on-write, we either ... */ if (entry->eflags & MAP_ENTRY_NEEDS_COPY) { /* * If we want to write the page, we may as well handle that * now since we've got the map locked. * * If we don't need to write the page, we just demote the * permissions allowed. */ if (fault_type & VM_PROT_WRITE) { /* * Not allowed if TDF_NOFAULT is set as the shadowing * operation can deadlock against the faulting * function due to the copy-on-write. */ if (curthread->td_flags & TDF_NOFAULT) { rv = KERN_FAILURE_NOFAULT; goto done; } /* * Make a new object, and place it in the object * chain. Note that no new references have appeared * -- one just moved from the map to the new * object. */ if (use_read_lock && vm_map_lock_upgrade(map)) { /* lost lock */ use_read_lock = 0; goto RetryLookup; } use_read_lock = 0; vm_map_entry_shadow(entry, 0); *wflags |= FW_DIDCOW; } else { /* * We're attempting to read a copy-on-write page -- * don't allow writes. */ prot &= ~VM_PROT_WRITE; } } /* * Create an object if necessary. This code also handles * partitioning large entries to improve vm_fault performance. */ if (entry->object.vm_object == NULL && !map->system_map) { if (use_read_lock && vm_map_lock_upgrade(map)) { /* lost lock */ use_read_lock = 0; goto RetryLookup; } use_read_lock = 0; /* * Partition large entries, giving each its own VM object, * to improve concurrent fault performance. This is only * applicable to userspace. */ if (map != &kernel_map && entry->maptype == VM_MAPTYPE_NORMAL && ((entry->start ^ entry->end) & ~MAP_ENTRY_PARTITION_MASK) && vm_map_partition_enable) { if (entry->eflags & MAP_ENTRY_IN_TRANSITION) { entry->eflags |= MAP_ENTRY_NEEDS_WAKEUP; ++mycpu->gd_cnt.v_intrans_coll; ++mycpu->gd_cnt.v_intrans_wait; vm_map_transition_wait(map, 0); goto RetryLookup; } vm_map_entry_partition(map, entry, vaddr, &count); } vm_map_entry_allocate_object(entry); } /* * Return the object/offset from this entry. If the entry was * copy-on-write or empty, it has been fixed up. */ *object = entry->object.vm_object; skip: *pindex = OFF_TO_IDX((vaddr - entry->start) + entry->offset); /* * Return whether this is the only map sharing this data. On * success we return with a read lock held on the map. On failure * we return with the map unlocked. */ *out_prot = prot; done: if (rv == KERN_SUCCESS) { if (use_read_lock == 0) vm_map_lock_downgrade(map); } else if (use_read_lock) { vm_map_unlock_read(map); } else { vm_map_unlock(map); } if (count > 0) vm_map_entry_release(count); return (rv); } /* * Releases locks acquired by a vm_map_lookup() * (according to the handle returned by that lookup). * * No other requirements. */ void vm_map_lookup_done(vm_map_t map, vm_map_entry_t entry, int count) { /* * Unlock the main-level map */ vm_map_unlock_read(map); if (count) vm_map_entry_release(count); } static void vm_map_entry_partition(vm_map_t map, vm_map_entry_t entry, vm_offset_t vaddr, int *countp) { vaddr &= ~MAP_ENTRY_PARTITION_MASK; vm_map_clip_start(map, entry, vaddr, countp); vaddr += MAP_ENTRY_PARTITION_SIZE; vm_map_clip_end(map, entry, vaddr, countp); } /* * Quick hack, needs some help to make it more SMP friendly. */ void vm_map_interlock(vm_map_t map, struct vm_map_ilock *ilock, vm_offset_t ran_beg, vm_offset_t ran_end) { struct vm_map_ilock *scan; ilock->ran_beg = ran_beg; ilock->ran_end = ran_end; ilock->flags = 0; spin_lock(&map->ilock_spin); restart: for (scan = map->ilock_base; scan; scan = scan->next) { if (ran_end > scan->ran_beg && ran_beg < scan->ran_end) { scan->flags |= ILOCK_WAITING; ssleep(scan, &map->ilock_spin, 0, "ilock", 0); goto restart; } } ilock->next = map->ilock_base; map->ilock_base = ilock; spin_unlock(&map->ilock_spin); } void vm_map_deinterlock(vm_map_t map, struct vm_map_ilock *ilock) { struct vm_map_ilock *scan; struct vm_map_ilock **scanp; spin_lock(&map->ilock_spin); scanp = &map->ilock_base; while ((scan = *scanp) != NULL) { if (scan == ilock) { *scanp = ilock->next; spin_unlock(&map->ilock_spin); if (ilock->flags & ILOCK_WAITING) wakeup(ilock); return; } scanp = &scan->next; } spin_unlock(&map->ilock_spin); panic("vm_map_deinterlock: missing ilock!"); } #include "opt_ddb.h" #ifdef DDB #include <ddb/ddb.h> /* * Debugging only */ DB_SHOW_COMMAND(map, vm_map_print) { static int nlines; /* XXX convert args. */ vm_map_t map = (vm_map_t)addr; boolean_t full = have_addr; vm_map_entry_t entry; db_iprintf("Task map %p: pmap=%p, nentries=%d, version=%u\n", (void *)map, (void *)map->pmap, map->nentries, map->timestamp); nlines++; if (!full && db_indent) return; db_indent += 2; for (entry = map->header.next; entry != &map->header; entry = entry->next) { db_iprintf("map entry %p: start=%p, end=%p\n", (void *)entry, (void *)entry->start, (void *)entry->end); nlines++; { static char *inheritance_name[4] = {"share", "copy", "none", "donate_copy"}; db_iprintf(" prot=%x/%x/%s", entry->protection, entry->max_protection, inheritance_name[(int)(unsigned char) entry->inheritance]); if (entry->wired_count != 0) db_printf(", wired"); } switch(entry->maptype) { case VM_MAPTYPE_SUBMAP: /* XXX no %qd in kernel. Truncate entry->offset. */ db_printf(", share=%p, offset=0x%lx\n", (void *)entry->object.sub_map, (long)entry->offset); nlines++; if ((entry->prev == &map->header) || (entry->prev->object.sub_map != entry->object.sub_map)) { db_indent += 2; vm_map_print((db_expr_t)(intptr_t) entry->object.sub_map, full, 0, NULL); db_indent -= 2; } break; case VM_MAPTYPE_NORMAL: case VM_MAPTYPE_VPAGETABLE: /* XXX no %qd in kernel. Truncate entry->offset. */ db_printf(", object=%p, offset=0x%lx", (void *)entry->object.vm_object, (long)entry->offset); if (entry->eflags & MAP_ENTRY_COW) db_printf(", copy (%s)", (entry->eflags & MAP_ENTRY_NEEDS_COPY) ? "needed" : "done"); db_printf("\n"); nlines++; if ((entry->prev == &map->header) || (entry->prev->object.vm_object != entry->object.vm_object)) { db_indent += 2; vm_object_print((db_expr_t)(intptr_t) entry->object.vm_object, full, 0, NULL); nlines += 4; db_indent -= 2; } break; case VM_MAPTYPE_UKSMAP: db_printf(", uksmap=%p, offset=0x%lx", (void *)entry->object.uksmap, (long)entry->offset); if (entry->eflags & MAP_ENTRY_COW) db_printf(", copy (%s)", (entry->eflags & MAP_ENTRY_NEEDS_COPY) ? "needed" : "done"); db_printf("\n"); nlines++; break; default: break; } } db_indent -= 2; if (db_indent == 0) nlines = 0; } /* * Debugging only */ DB_SHOW_COMMAND(procvm, procvm) { struct proc *p; if (have_addr) { p = (struct proc *) addr; } else { p = curproc; } db_printf("p = %p, vmspace = %p, map = %p, pmap = %p\n", (void *)p, (void *)p->p_vmspace, (void *)&p->p_vmspace->vm_map, (void *)vmspace_pmap(p->p_vmspace)); vm_map_print((db_expr_t)(intptr_t)&p->p_vmspace->vm_map, 1, 0, NULL); } #endif /* DDB */
175429.c
/* * DECnet An implementation of the DECnet protocol suite for the LINUX * operating system. DECnet is implemented using the BSD Socket * interface as the means of communication with the user level. * * DECnet Routing Forwarding Information Base (Rules) * * Author: Steve Whitehouse <[email protected]> * Mostly copied from Alexey Kuznetsov's ipv4/fib_rules.c * * * Changes: * Steve Whitehouse <[email protected]> * Updated for Thomas Graf's generic rules * */ #include <linux/net.h> #include <linux/init.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> #include <linux/netdevice.h> #include <linux/spinlock.h> #include <linux/list.h> #include <linux/rcupdate.h> #include <linux/export.h> #include <net/neighbour.h> #include <net/dst.h> #include <net/flow.h> #include <net/fib_rules.h> #include <net/dn.h> #include <net/dn_fib.h> #include <net/dn_neigh.h> #include <net/dn_dev.h> #include <net/dn_route.h> static struct fib_rules_ops *dn_fib_rules_ops; struct dn_fib_rule { struct fib_rule common; unsigned char dst_len; unsigned char src_len; __le16 src; __le16 srcmask; __le16 dst; __le16 dstmask; __le16 srcmap; u8 flags; }; int dn_fib_lookup(struct flowidn *flp, struct dn_fib_res *res) { struct fib_lookup_arg arg = { .result = res, }; int err; err = fib_rules_lookup(dn_fib_rules_ops, flowidn_to_flowi(flp), 0, &arg); res->r = arg.rule; return err; } static int dn_fib_rule_action(struct fib_rule *rule, struct flowi *flp, int flags, struct fib_lookup_arg *arg) { struct flowidn *fld = &flp->u.dn; int err = -EAGAIN; struct dn_fib_table *tbl; switch(rule->action) { case FR_ACT_TO_TBL: break; case FR_ACT_UNREACHABLE: err = -ENETUNREACH; goto errout; case FR_ACT_PROHIBIT: err = -EACCES; goto errout; case FR_ACT_BLACKHOLE: default: err = -EINVAL; goto errout; } tbl = dn_fib_get_table(rule->table, 0); if (tbl == NULL) goto errout; err = tbl->lookup(tbl, fld, (struct dn_fib_res *)arg->result); if (err > 0) err = -EAGAIN; errout: return err; } static const struct nla_policy dn_fib_rule_policy[FRA_MAX+1] = { FRA_GENERIC_POLICY, }; static int dn_fib_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) { struct dn_fib_rule *r = (struct dn_fib_rule *)rule; struct flowidn *fld = &fl->u.dn; __le16 daddr = fld->daddr; __le16 saddr = fld->saddr; if (((saddr ^ r->src) & r->srcmask) || ((daddr ^ r->dst) & r->dstmask)) return 0; return 1; } static int dn_fib_rule_configure(struct fib_rule *rule, struct sk_buff *skb, struct fib_rule_hdr *frh, struct nlattr **tb) { int err = -EINVAL; struct dn_fib_rule *r = (struct dn_fib_rule *)rule; if (frh->tos) goto errout; if (rule->table == RT_TABLE_UNSPEC) { if (rule->action == FR_ACT_TO_TBL) { struct dn_fib_table *table; table = dn_fib_empty_table(); if (table == NULL) { err = -ENOBUFS; goto errout; } rule->table = table->n; } } if (frh->src_len) r->src = nla_get_le16(tb[FRA_SRC]); if (frh->dst_len) r->dst = nla_get_le16(tb[FRA_DST]); r->src_len = frh->src_len; r->srcmask = dnet_make_mask(r->src_len); r->dst_len = frh->dst_len; r->dstmask = dnet_make_mask(r->dst_len); err = 0; errout: return err; } static int dn_fib_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh, struct nlattr **tb) { struct dn_fib_rule *r = (struct dn_fib_rule *)rule; if (frh->src_len && (r->src_len != frh->src_len)) return 0; if (frh->dst_len && (r->dst_len != frh->dst_len)) return 0; if (frh->src_len && (r->src != nla_get_le16(tb[FRA_SRC]))) return 0; if (frh->dst_len && (r->dst != nla_get_le16(tb[FRA_DST]))) return 0; return 1; } unsigned int dnet_addr_type(__le16 addr) { struct flowidn fld = { .daddr = addr }; struct dn_fib_res res; unsigned int ret = RTN_UNICAST; struct dn_fib_table *tb = dn_fib_get_table(RT_TABLE_LOCAL, 0); res.r = NULL; if (tb) { if (!tb->lookup(tb, &fld, &res)) { ret = res.type; dn_fib_res_put(&res); } } return ret; } static int dn_fib_rule_fill(struct fib_rule *rule, struct sk_buff *skb, struct fib_rule_hdr *frh) { struct dn_fib_rule *r = (struct dn_fib_rule *)rule; frh->dst_len = r->dst_len; frh->src_len = r->src_len; frh->tos = 0; if ((r->dst_len && nla_put_le16(skb, FRA_DST, r->dst)) || (r->src_len && nla_put_le16(skb, FRA_SRC, r->src))) goto nla_put_failure; return 0; nla_put_failure: return -ENOBUFS; } static void dn_fib_rule_flush_cache(struct fib_rules_ops *ops) { dn_rt_cache_flush(-1); } static const struct fib_rules_ops __net_initconst dn_fib_rules_ops_template = { .family = AF_DECnet, .rule_size = sizeof(struct dn_fib_rule), .addr_size = sizeof(u16), .action = dn_fib_rule_action, .match = dn_fib_rule_match, .configure = dn_fib_rule_configure, .compare = dn_fib_rule_compare, .fill = dn_fib_rule_fill, .default_pref = fib_default_rule_pref, .flush_cache = dn_fib_rule_flush_cache, .nlgroup = RTNLGRP_DECnet_RULE, .policy = dn_fib_rule_policy, .owner = THIS_MODULE, .fro_net = &init_net, }; void __init dn_fib_rules_init(void) { dn_fib_rules_ops = fib_rules_register(&dn_fib_rules_ops_template, &init_net); BUG_ON(IS_ERR(dn_fib_rules_ops)); BUG_ON(fib_default_rule_add(dn_fib_rules_ops, 0x7fff, RT_TABLE_MAIN, 0)); } void __exit dn_fib_rules_cleanup(void) { fib_rules_unregister(dn_fib_rules_ops); rcu_barrier(); }
754411.c
/** * \file * * \brief User Interface * * Copyright (c) 2009 - 2014 Atmel Corporation. All rights reserved. * * \asf_license_start * * \page License * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The name of Atmel may not be used to endorse or promote products derived * from this software without specific prior written permission. * * 4. This software may only be redistributed and used in connection with an * Atmel microcontroller product. * * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * \asf_license_stop * */ /** * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> */ #include <asf.h> #include "ui.h" #define MOUSE_MOVE_RANGE (3*4) // Interrupt on "pin change" from switch to do wakeup on USB // Note: // This interrupt is enable when the USB host enable remotewakeup feature // This interrupt wakeup the CPU if this one is in idle mode ISR(ui_wakeup_isr, AVR32_GPIO_IRQ_GROUP, 0) { // Clear GPIO interrupts. gpio_clear_pin_interrupt_flag(GPIO_PUSH_BUTTON_0); gpio_clear_pin_interrupt_flag(GPIO_PUSH_BUTTON_1); // Clear External Interrupt Line else Wakeup event always enabled eic_clear_interrupt_line(&AVR32_EIC, EXT_INT6); eic_clear_interrupt_line(&AVR32_EIC, EXT_INT7); // It is a wakeup then send wakeup USB udc_remotewakeup(); } void ui_init(void) { // Initialize accelerometer driver sysclk_enable_pba_module(SYSCLK_ADC); acc_init(); /* register joystick handler on level 0 */ irqflags_t flags = cpu_irq_save(); irq_register_handler(ui_wakeup_isr, AVR32_GPIO_IRQ_0 + (GPIO_PUSH_BUTTON_0 / 8), 0); cpu_irq_restore(flags); LED_On(LED0); LED_Off(LED1); } void ui_powerdown(void) { LED_Off(LED0); LED_Off(LED1); } //! Structure holding the configuration parameters of the EIC low level driver. static eic_options_t eic_options = { // Enable level-triggered interrupt. .eic_mode = EIC_MODE_LEVEL_TRIGGERED, // Don't care value because the chosen eic mode is level-triggered. .eic_edge = 0, // Interrupt will trigger on low-level. .eic_level = EIC_LEVEL_LOW_LEVEL, // Enable filter. .eic_filter = EIC_FILTER_ENABLED, // For Wake Up mode, initialize in asynchronous mode .eic_async = EIC_ASYNCH_MODE }; void ui_wakeup_enable(void) { /* configure buttons to produce IT on all state change */ gpio_enable_pin_interrupt(GPIO_PUSH_BUTTON_0, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt(GPIO_PUSH_BUTTON_1, GPIO_PIN_CHANGE); /* * Configure pin change interrupt for asynchronous wake-up (required to * wake up from the STATIC sleep mode). * * First, map the interrupt line to the GPIO pin with the right * peripheral function. */ gpio_enable_module_pin(GPIO_PUSH_BUTTON_0, AVR32_EIC_EXTINT_6_FUNCTION); gpio_enable_module_pin(GPIO_PUSH_BUTTON_1, AVR32_EIC_EXTINT_7_FUNCTION); /* * Enable the internal pull-up resistor on that pin (because the EIC is * configured such that the interrupt will trigger on low-level, see * eic_options.eic_level). */ gpio_enable_pin_pull_up(GPIO_PUSH_BUTTON_0); gpio_enable_pin_pull_up(GPIO_PUSH_BUTTON_1); // Init the EIC controller with the set options. eic_options.eic_line = EXT_INT6; eic_init(&AVR32_EIC, &eic_options, sizeof(eic_options) / sizeof(eic_options_t)); eic_options.eic_line = EXT_INT7; eic_init(&AVR32_EIC, &eic_options, sizeof(eic_options) / sizeof(eic_options_t)); // Enable External Interrupt Controller Line eic_enable_line(&AVR32_EIC, EXT_INT6); eic_enable_line(&AVR32_EIC, EXT_INT7); } void ui_wakeup_disable(void) { eic_disable_line(&AVR32_EIC, EXT_INT6); eic_disable_line(&AVR32_EIC, EXT_INT7); /* Disable joystick input change ITs. */ gpio_disable_pin_interrupt(GPIO_PUSH_BUTTON_0); gpio_disable_pin_interrupt(GPIO_PUSH_BUTTON_1); } void ui_wakeup(void) { LED_On(LED0); } void ui_process(uint16_t framenumber) { bool b_btn_state; static bool btn_left_last_state = HID_MOUSE_BTN_UP; static bool btn_right_last_state = HID_MOUSE_BTN_UP; static bool btn_middle_last_state = HID_MOUSE_BTN_UP; uint8_t i; signed int val; struct cal_t { uint8_t angle; int8_t move; } calibration_acc[5] = { { 40, 10 * MOUSE_MOVE_RANGE}, { 30, 6 * MOUSE_MOVE_RANGE}, { 20, 4 * MOUSE_MOVE_RANGE}, { 15, 2 * MOUSE_MOVE_RANGE}, { 10, 1 * MOUSE_MOVE_RANGE}}; static uint8_t cpt_sof = 0; if ((framenumber % 1000) == 0) { LED_On(LED1); } if ((framenumber % 1000) == 500) { LED_Off(LED1); } // Scan process running each 40ms cpt_sof++; if (40 > cpt_sof) return; cpt_sof = 0; // Scan buttons on switch 0 (left), 1 (right), joystick_press (middle), b_btn_state = (!gpio_get_pin_value(GPIO_PUSH_BUTTON_0)) ? HID_MOUSE_BTN_DOWN : HID_MOUSE_BTN_UP; if (b_btn_state != btn_left_last_state) { udi_hid_mouse_btnleft(b_btn_state); btn_left_last_state = b_btn_state; } b_btn_state = (is_joystick_pressed())? HID_MOUSE_BTN_DOWN : HID_MOUSE_BTN_UP; if (b_btn_state != btn_middle_last_state) { udi_hid_mouse_btnmiddle(b_btn_state); btn_middle_last_state = b_btn_state; } b_btn_state = (!gpio_get_pin_value(GPIO_PUSH_BUTTON_1)) ? HID_MOUSE_BTN_DOWN : HID_MOUSE_BTN_UP; if (b_btn_state != btn_right_last_state) { udi_hid_mouse_btnright(b_btn_state); btn_right_last_state = b_btn_state; } // Look joystick activity for the Wheel events if (is_joystick_up()) udi_hid_mouse_moveScroll(MOUSE_MOVE_RANGE); if (is_joystick_down()) udi_hid_mouse_moveScroll(-MOUSE_MOVE_RANGE); // Look accelerometer activity for the X and Y events acc_update(); // Get accelerometer acquisition and process data for (i = 0; i < (sizeof(calibration_acc) / sizeof(struct cal_t)); i++) { val = is_acc_abs_angle_x(calibration_acc[i].angle); if (0 == val) continue; if (0 < val) udi_hid_mouse_moveX(0 - calibration_acc[i].move); else udi_hid_mouse_moveX(calibration_acc[i].move); break; } for (i = 0; i < (sizeof(calibration_acc) / sizeof(struct cal_t)); i++) { val = is_acc_abs_angle_y(calibration_acc[i].angle); if (0 == val) continue; if (0 < val) udi_hid_mouse_moveY(0 - calibration_acc[i].move); else udi_hid_mouse_moveY(calibration_acc[i].move); break; } } /** * \defgroup UI User Interface * * Human interface on EVK1101 : * - PWR led is on when power present * - Led 0 is on when USB line is in IDLE mode, and off in SUSPEND mode * - Led 1 blinks when USB host has checked and enabled HID mouse interface * - Mouse buttons are linked to switch PB0 (left), PB1 (right), joystick press (middle) * - Look accelerometer activity for the X and Y mouse events * - Look joystick activity for the Wheel events * - The PB0 and PB1 can be used to wakeup USB Host in remote wakeup mode. */
272882.c
/* * File : cputime.h * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2017, RT-Thread Development Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * Change Logs: * Date Author Notes * 2017-12-23 Bernard first version */ #include <rtdevice.h> #include <rtthread.h> static const struct rt_clock_cputime_ops *_cputime_ops = RT_NULL; /** * The clock_cpu_getres() function shall return the resolution of CPU time, the * number of nanosecond per tick. * * @return the number of nanosecond per tick */ float clock_cpu_getres(void) { if (_cputime_ops) return _cputime_ops->cputime_getres(); rt_set_errno(-ENOSYS); return 0; } /** * The clock_cpu_gettime() function shall return the current value of cpu time tick. * * @return the cpu tick */ uint32_t clock_cpu_gettime(void) { if (_cputime_ops) return _cputime_ops->cputime_gettime(); rt_set_errno(-ENOSYS); return 0; } /** * The clock_cpu_microsecond() fucntion shall return the microsecond according to * cpu_tick parameter. * * @param cpu_tick the cpu tick * * @return the microsecond */ uint32_t clock_cpu_microsecond(uint32_t cpu_tick) { float unit = clock_cpu_getres(); return (cpu_tick * unit) / 1000; } /** * The clock_cpu_microsecond() fucntion shall return the millisecond according to * cpu_tick parameter. * * @param cpu_tick the cpu tick * * @return the millisecond */ uint32_t clock_cpu_millisecond(uint32_t cpu_tick) { float unit = clock_cpu_getres(); return (cpu_tick * unit) / (1000 * 1000); } /** * The clock_cpu_seops() function shall set the ops of cpu time. * * @return always return 0. */ int clock_cpu_setops(const struct rt_clock_cputime_ops *ops) { _cputime_ops = ops; if (ops) { RT_ASSERT(ops->cputime_getres != RT_NULL); RT_ASSERT(ops->cputime_gettime != RT_NULL); } return 0; }
773357.c
/* * Copyright (c) 2015-2021, Renesas Electronics Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #include "common.h" #include "dgtable.h" #include "memory_cmd.h" #include "devdrv.h" #include "devdrv.h" #include "bit.h" #include "cpudrv.h" #include "scifdrv.h" extern const char *const AllHelpMess[ALL_HELP_MESS_LINE]; extern const com_menu MonCom[COMMAND_UNIT]; extern int32_t gComNo; extern char gKeyBuf[64]; extern uintptr_t gUDump[3]; extern uintptr_t gUMem[3]; extern uint32_t gDumpMode; extern uint32_t gDumpStatus; static void ChgDumpAsciiCode(uintptr_t chCode, char *buf, char chPtr, uint32_t width) { unsigned char tmpBCode,i; uintptr_t tmpLCode; switch(width) { case SIZE_8BIT: tmpLCode = 0xFF & chCode; tmpBCode = (unsigned char)tmpLCode; if ((0x20 <= tmpBCode) && (tmpBCode <= 0x7E)) { *((unsigned char *)(buf+chPtr)) = tmpBCode; } else { *((unsigned char *)(buf+chPtr)) = '.'; } break; case SIZE_16BIT: for (i = 0; i < width; i++) { tmpLCode = chCode; tmpLCode = 0xFF & (tmpLCode>>(8-(i*8))); tmpBCode = (unsigned char)tmpLCode; if ((0x20 <= tmpBCode) && (tmpBCode <= 0x7E)) { *((unsigned char *)(buf+i+chPtr)) = tmpBCode; } else { *((unsigned char *)(buf+i+chPtr)) = '.'; } } break; case SIZE_32BIT: for (i = 0; i < width; i++) { tmpLCode = chCode; tmpLCode = 0xFF & (tmpLCode>>(24-(i*8))); tmpBCode = (unsigned char)tmpLCode; if ((0x20 <= tmpBCode) && (tmpBCode <= 0x7E)) { *((unsigned char *)(buf+i+chPtr)) = tmpBCode; } else { *((unsigned char *)(buf+i+chPtr)) = '.'; } } break; case SIZE_64BIT: for (i = 0; i < width; i++) { tmpLCode = chCode; tmpLCode = 0xFF & (tmpLCode>>(56-(i*8))); tmpBCode = (unsigned char)tmpLCode; if ((0x20 <= tmpBCode) && (tmpBCode <= 0x7E)) { *((unsigned char *)(buf+i+chPtr)) = tmpBCode; } else { *((unsigned char *)(buf+i+chPtr)) = '.'; } } break; default: break; } } static void ChgDumpAsciiStr(char *buf) { unsigned char i; buf[18] = 0; buf[17] = 0x22; for (i = 16; i > 0; i--) { buf[i] = buf[i-1]; } buf[0] = 0x22; } static void Get1ByteMem(uintptr_t readAdd, uintptr_t *readData, uint32_t width) { unsigned char tmpB; uint16_t tmpW; uint32_t tmpL; uint64_t tmpX; switch(width) { case SIZE_8BIT: tmpB = *((volatile uint8_t *)readAdd); *readData = (uintptr_t)tmpB; break; case SIZE_16BIT: tmpW = *((volatile uint16_t *)readAdd); *readData = (uintptr_t)tmpW; break; case SIZE_32BIT: tmpL = *((volatile uint32_t *)readAdd); *readData = (uintptr_t)tmpL; break; case SIZE_64BIT: tmpX = *((volatile uint64_t *)readAdd); *readData = (uintptr_t)tmpX; break; default: break; } } static void Put1ByteMem(uintptr_t writeAdd, uintptr_t writeData, uint32_t width) { uint8_t tmpB; uint16_t tmpW; uint32_t tmpL; switch(width) { case SIZE_8BIT: tmpB = (uint8_t)writeData; *((volatile uint8_t *)writeAdd) = tmpB; break; case SIZE_16BIT: tmpW = (uint16_t)writeData; *((volatile uint16_t *)writeAdd) = tmpW; break; case SIZE_32BIT: tmpL = (uint32_t)writeData; *((volatile uint32_t *)writeAdd) = tmpL; break; case SIZE_64BIT: *((uint64_t *)writeAdd) = writeData; break; break; } } static void DisplayDump(uintptr_t stAdd, uintptr_t dumpSize, uint32_t width) { char buf[32], asciiBuf[20]; uintptr_t readAdd, readData; uint32_t blankCnt, byte_count; byte_count = 0x0; /********* Dump Data 1Line All Display *********************/ if (!((dumpSize&0x0000000F) == 0x0000000F)) { dumpSize = dumpSize | 0x0000000F; } for (readAdd = stAdd; readAdd <= (stAdd+dumpSize); readAdd += width) { /********* Dump Address Display ************************/ if ((!(byte_count & 0x0000000F)) || (byte_count == 0)) { Data2HexAscii_64(readAdd,buf,CPU_BYTE_SIZE); PutStr(buf, 0); PutStr(" ", 0); } Get1ByteMem(readAdd, &readData, width); Data2HexAscii_64(readData, buf, (char)width); ChgDumpAsciiCode(readData, asciiBuf, (char)(byte_count & 0xF), (char)width); /********* Dump Data Display blank ********************/ if (!(byte_count & 0x8)) { PutStr(buf, 0); for (blankCnt = 0; blankCnt < width; blankCnt++) { PutStr(" ",0); } } else { for (blankCnt = 0; blankCnt < width; blankCnt++) { PutStr(" ",0); } PutStr(buf, 0); } if (((width == SIZE_8BIT) && ((byte_count & 0xF) ==0xF)) || ((width == SIZE_16BIT) && ((byte_count & 0xF) ==0xE)) || ((width == SIZE_32BIT) && ((byte_count & 0xF) ==0xC)) || ((width == SIZE_64BIT) && ((byte_count & 0xF) ==0x8))) { ChgDumpAsciiStr(asciiBuf); PutStr(" ", 0); PutStr(asciiBuf, 1); } byte_count += width; } } static char CheckAccessSize(char *buf, uint32_t *sizeId) { ChgLtl2Lrg(buf); if ((*buf == 'B') && (*(buf+1) == 0)) { *sizeId = SIZE_8BIT; } else if ((*buf == 'W') && (*(buf+1) == 0)) { *sizeId = SIZE_16BIT; } else if ((*buf == 'L') && (*(buf+1) == 0)) { *sizeId = SIZE_32BIT; } else if ((*buf == 'X') && (*(buf+1) == 0)) { *sizeId = SIZE_64BIT; } else { return(1); } return(0); } static void DisplayMemEd(uintptr_t mem1st, uint32_t width, uint32_t verifyFlg) { uintptr_t readData, wrData; char mEnd, buf[32], key[32], chCnt, chPtr; mEnd = 0; while(!mEnd) { Data2HexAscii_64(mem1st, buf, CPU_BYTE_SIZE); PutStr(buf, 0); PutStr(" ", 0); Get1ByteMem(mem1st, &readData, width); Data2HexAscii_64(readData, buf, (char)width); PutStr(buf, 0); PutStr(" ? ", 0); GetStr_MemEd(key, &chCnt); chPtr = 0; if (!GetStrBlk(key, buf, &chPtr, 0)) { if (chPtr == 1) { /* Case Return */ mem1st += width; } else if ((buf[0] == '.')) { /* Case End */ mEnd = 1; } else if ((buf[0] == '^')) { /* Case ^ */ mem1st -= width; } else if (chPtr > (char)((width<<1)+1)) { /* Case Data Size Over */ PutStr("Syntax Error", 1); } else { if (HexAscii2Data_64((unsigned char*)buf, &wrData)) { PutStr("Syntax Error", 1); } else { /* Case Mem Edit */ Put1ByteMem(mem1st, wrData, width); if (verifyFlg == VERIFY_ON) { Get1ByteMem(mem1st, &readData, width); if (wrData != readData) { PutStr("Verify Error", 1); } } mem1st += width; } } } else { PutStr("Syntax Error",1); } } gUMem[0] = mem1st; } static void dgMemEdit(uint32_t width) { uint32_t verifyFlg; uintptr_t mem1st; char decRtn; // verifyFlg = VERIFY_ON; verifyFlg = VERIFY_OFF; mem1st = gUMem[0]; /* Start Address */ decRtn = DecodeForm02(&mem1st); if (decRtn == 1) { PutStr("Syntax Error", 1); } else if(decRtn == 0) { switch(width) { case SIZE_16BIT: if (mem1st & 0x00000001) { PutStr("Memory Boundary Error", 1); return; } break; case SIZE_32BIT: if (mem1st & 0x00000003) { PutStr("Memory Boundary Error", 1); return; } break; case SIZE_64BIT: if (mem1st & 0x00000007) { PutStr("Memory Boundary Error", 1); return; } break; default: break; } DisplayMemEd(mem1st, width, verifyFlg); gUMem[0] = gUMem[0] + width; /* Start Address */ } } /**************************************************************** MODULE : dgDump * FUNCTION : Memory Dump * COMMAND : D * INPUT PARAMETER : D {sadr {eadr}} * *****************************************************************/ void dgDump(void) { uintptr_t dmp1st, dmp2nd; char decRtn; gDumpStatus = ENABLE; /* Init Dump Parameter */ dmp1st = gUDump[0]; /* Start Address */ dmp2nd = gUDump[1]; /* End Address */ decRtn = DecodeForm01(&dmp1st, &dmp2nd); /* format check */ /* dmp1st: Start Address */ /* dmp2nd: dumpSize */ switch(gDumpMode) { case SIZE_16BIT: if (dmp1st & 0x00000001) { PutStr("Memory Boundary Error", 1); return; } break; case SIZE_32BIT: if (dmp1st & 0x00000003) { PutStr("Memory Boundary Error", 1); return; } break; case SIZE_64BIT: if (dmp1st & 0x00000007) { PutStr("Memory Boundary Error", 1); return; } break; default: break; } if (decRtn == 1) { PutStr("Syntax Error", 1); } if (decRtn == 2) { PutStr("Address Size Error", 1); } if (decRtn == 0) { DisplayDump(dmp1st, dmp2nd, gDumpMode); dmp2nd=dmp2nd | 0x0000000F; /* Start line adjustment */ gUDump[0] = dmp1st+dmp2nd+1; /* Start Address */ gUDump[1] = 255; /* Dump Size (Byte) Return to initial value */ } } /**************************************************************** MODULE : dgDumpMode * FUNCTION : set&disp dump mode * COMMAND : DM * INPUT PARAMETER : DM {B|W|L} * *****************************************************************/ void dgDumpMode(void) { uint32_t setPara; char tmp[64], chPtr; char endCh; chPtr = 0; setPara = gDumpMode; /*DM (Display DumpMode) */ endCh = GetStrBlk(gKeyBuf, tmp, &chPtr, 0); if (endCh == 0) { // When nothing other than DM is entered PutStr("DMmode = ", 0); switch(gDumpMode) { case SIZE_8BIT: PutStr("byte", 1); break; case SIZE_16BIT: PutStr("word", 1); break; case SIZE_32BIT: PutStr("long", 1); break; case SIZE_64BIT: PutStr("long long", 1); break; default: break; } } /*DM <size> (Set DumpMode Size)*/ else { /*********** Ana 2nd parameter check ****************/ GetStrBlk(gKeyBuf, tmp, &chPtr, 0); if (CheckAccessSize(tmp, &setPara)) { PutStr("Syntax Error", 1); } gDumpMode=setPara; } } /**************************************************************** MODULE : dgMemEdit_byte * FUNCTION : set memory(BYTE) * COMMAND : M * INPUT PARAMETER : M [adr] * *****************************************************************/ void dgMemEdit_byte(void) { dgMemEdit(SIZE_8BIT); } /**************************************************************** MODULE : dgMemEdit_word * FUNCTION : set memory(WORD) * COMMAND : MW * INPUT PARAMETER : MW [adr] * *****************************************************************/ void dgMemEdit_word(void) { dgMemEdit(SIZE_16BIT); } /**************************************************************** MODULE : dgMemEdit_long * FUNCTION : set memory(LONG) * COMMAND : ML * INPUT PARAMETER : ML [adr] * *****************************************************************/ void dgMemEdit_long(void) { dgMemEdit(SIZE_32BIT); } /**************************************************************** MODULE : dgMemEdit_long_long * FUNCTION : set memory(LONG LONG) * COMMAND : MX * INPUT PARAMETER : MX [adr] * *****************************************************************/ void dgMemEdit_longlong(void) { dgMemEdit(SIZE_64BIT); } /**************************************************************** FUNCTION : fill memory * *****************************************************************/ static void dgFill(uint32_t width) { uintptr_t fill1st, fill2nd, fill3rd, wrAdd; uint32_t setPara; char decRtn; /* fill1st: Start Address */ /* fill2nd: FillSize */ /* fill3rd: FillData */ decRtn = DecodeForm03(&fill1st, &fill2nd, &fill3rd, &setPara); if (!(setPara == 0x03)) { if (decRtn == 1) { PutStr("Syntax Error",1); } else if (decRtn == 2) { PutStr("Address Size Error",1); } else { PutStr("Syntax Error",1); } } else { if (width == SIZE_32BIT) { if (fill1st & 0x00000003) { PutStr("Memory Boundary Error",1); return; } } if (width == SIZE_64BIT) { if (fill1st & 0x00000007) { PutStr("Memory Boundary Error",1); return; } } for (wrAdd = fill1st; wrAdd <= (fill1st + fill2nd); wrAdd += width) { Put1ByteMem(wrAdd, fill3rd, width); } } } /**************************************************************** MODULE : dgFill_byte * FUNCTION : fill memory (Byte) * COMMAND : F * INPUT PARAMETER : F [sadr] [eadr] [data] * *****************************************************************/ void dgFill_byte(void) { dgFill(SIZE_8BIT); } /**************************************************************** MODULE : dgFill_long * FUNCTION : fill memory (LONG) * COMMAND : FL * INPUT PARAMETER : FL [sadr] [eadr] [data] * *****************************************************************/ void dgFill_long(void) { dgFill(SIZE_32BIT); } /**************************************************************** MODULE : dgFill_longlong * FUNCTION : fill memory (LONG LONG) * COMMAND : FX * INPUT PARAMETER : FX [sadr] [eadr] [data] * *****************************************************************/ void dgFill_longlong(void) { dgFill(SIZE_64BIT); }
792599.c
/* TEMPLATE GENERATED TESTCASE FILE Filename: CWE134_Uncontrolled_Format_String__char_environment_fprintf_54c.c Label Definition File: CWE134_Uncontrolled_Format_String.label.xml Template File: sources-sinks-54c.tmpl.c */ /* * @description * CWE: 134 Uncontrolled Format String * BadSource: environment Read input from an environment variable * GoodSource: Copy a fixed string into data * Sinks: fprintf * GoodSink: fprintf with "%s" as the second argument and data as the third * BadSink : fprintf with data as the second argument * Flow Variant: 54 Data flow: data passed as an argument from one function through three others to a fifth; all five functions are in different source files * * */ #include "std_testcase.h" #ifndef _WIN32 #include <wchar.h> #endif #define ENV_VARIABLE "ADD" #ifdef _WIN32 #define GETENV getenv #else #define GETENV getenv #endif #ifndef OMITBAD /* bad function declaration */ void CWE134_Uncontrolled_Format_String__char_environment_fprintf_54d_badSink(char * data); void CWE134_Uncontrolled_Format_String__char_environment_fprintf_54c_badSink(char * data) { CWE134_Uncontrolled_Format_String__char_environment_fprintf_54d_badSink(data); } #endif /* OMITBAD */ #ifndef OMITGOOD /* goodG2B uses the GoodSource with the BadSink */ void CWE134_Uncontrolled_Format_String__char_environment_fprintf_54d_goodG2BSink(char * data); void CWE134_Uncontrolled_Format_String__char_environment_fprintf_54c_goodG2BSink(char * data) { CWE134_Uncontrolled_Format_String__char_environment_fprintf_54d_goodG2BSink(data); } /* goodB2G uses the BadSource with the GoodSink */ void CWE134_Uncontrolled_Format_String__char_environment_fprintf_54d_goodB2GSink(char * data); void CWE134_Uncontrolled_Format_String__char_environment_fprintf_54c_goodB2GSink(char * data) { CWE134_Uncontrolled_Format_String__char_environment_fprintf_54d_goodB2GSink(data); } #endif /* OMITGOOD */
533105.c
/** * \file htu21d.c * * \brief HTU21 Temperature & Humidity sensor driver source file * * Copyright (c) 2016 Measurement Specialties. All rights reserved. * * For details on programming, refer to htu21 datasheet : * http://www.meas-spec.com/downloads/HTU21D.pdf * */ #include "htu21d.h" /** * The header "i2c.h" has to be implemented for your own platform to // brad -> changed to esp32_i2c.h * conform the following protocol : * * enum i2c_transfer_direction { * I2C_TRANSFER_WRITE = 0, * I2C_TRANSFER_READ = 1, * }; * * enum status_code { * STATUS_OK = 0x00, * STATUS_ERR_OVERFLOW = 0x01, * STATUS_ERR_TIMEOUT = 0x02, * }; * * struct i2c_master_packet { * // Address to slave device * uint16_t address; * // Length of data array * uint16_t data_length; * // Data array containing all data to be transferred * uint8_t *data; * }; * * void i2c_master_init(void); * enum status_code i2c_master_read_packet_wait(struct i2c_master_packet *const packet); * enum status_code i2c_master_write_packet_wait(struct i2c_master_packet *const packet); * enum status_code i2c_master_write_packet_wait_no_stop(struct i2c_master_packet *const packet); */ #ifdef __cplusplus extern "C" { #endif // HTU21 device address #define HTU21_ADDR 0x40 //0b1000000 // HTU21 device commands #define HTU21_RESET_COMMAND 0xFE #define HTU21_READ_TEMPERATURE_W_HOLD_COMMAND 0xE3 #define HTU21_READ_TEMPERATURE_WO_HOLD_COMMAND 0xF3 #define HTU21_READ_HUMIDITY_W_HOLD_COMMAND 0xE5 #define HTU21_READ_HUMIDITY_WO_HOLD_COMMAND 0xF5 #define HTU21_READ_SERIAL_FIRST_8BYTES_COMMAND 0xFA0F #define HTU21_READ_SERIAL_LAST_6BYTES_COMMAND 0xFCC9 #define HTU21_WRITE_USER_REG_COMMAND 0xE6 #define HTU21_READ_USER_REG_COMMAND 0xE7 #define RESET_TIME 15 // ms value // Processing constants #define HTU21_TEMPERATURE_COEFFICIENT (float)(-0.15) #define HTU21_CONSTANT_A (float)(8.1332) #define HTU21_CONSTANT_B (float)(1762.39) #define HTU21_CONSTANT_C (float)(235.66) // Coefficients for temperature computation #define TEMPERATURE_COEFF_MUL (175.72) #define TEMPERATURE_COEFF_ADD (-46.85) // Coefficients for relative humidity computation #define HUMIDITY_COEFF_MUL (125) #define HUMIDITY_COEFF_ADD (-6) // Conversion timings #define HTU21_TEMPERATURE_CONVERSION_TIME_T_14b_RH_12b 50000 #define HTU21_TEMPERATURE_CONVERSION_TIME_T_13b_RH_10b 25000 #define HTU21_TEMPERATURE_CONVERSION_TIME_T_12b_RH_8b 13000 #define HTU21_TEMPERATURE_CONVERSION_TIME_T_11b_RH_11b 7000 #define HTU21_HUMIDITY_CONVERSION_TIME_T_14b_RH_12b 16000 #define HTU21_HUMIDITY_CONVERSION_TIME_T_13b_RH_10b 5000 #define HTU21_HUMIDITY_CONVERSION_TIME_T_12b_RH_8b 3000 #define HTU21_HUMIDITY_CONVERSION_TIME_T_11b_RH_11b 8000 // HTU21 User Register masks and bit position #define HTU21_USER_REG_RESOLUTION_MASK 0x81 #define HTU21_USER_REG_END_OF_BATTERY_MASK 0x40 #define HTU21_USER_REG_ENABLE_ONCHIP_HEATER_MASK 0x4 #define HTU21_USER_REG_DISABLE_OTP_RELOAD_MASK 0x2 #define HTU21_USER_REG_RESERVED_MASK (~( HTU21_USER_REG_RESOLUTION_MASK \ | HTU21_USER_REG_END_OF_BATTERY_MASK \ | HTU21_USER_REG_ENABLE_ONCHIP_HEATER_MASK \ | HTU21_USER_REG_DISABLE_OTP_RELOAD_MASK )) // HTU User Register values // Resolution #define HTU21_USER_REG_RESOLUTION_T_14b_RH_12b 0x00 #define HTU21_USER_REG_RESOLUTION_T_13b_RH_10b 0x80 #define HTU21_USER_REG_RESOLUTION_T_12b_RH_8b 0x01 #define HTU21_USER_REG_RESOLUTION_T_11b_RH_11b 0x81 // End of battery status #define HTU21_USER_REG_END_OF_BATTERY_VDD_ABOVE_2_25V 0x00 #define HTU21_USER_REG_END_OF_BATTERY_VDD_BELOW_2_25V 0x40 // Enable on chip heater #define HTU21_USER_REG_ONCHIP_HEATER_ENABLE 0x04 #define HTU21_USER_REG_OTP_RELOAD_DISABLE 0x02 uint32_t htu21_temperature_conversion_time = HTU21_TEMPERATURE_CONVERSION_TIME_T_14b_RH_12b; uint32_t htu21_humidity_conversion_time = HTU21_HUMIDITY_CONVERSION_TIME_T_14b_RH_12b; enum htu21_i2c_master_mode i2c_master_mode; // Static functions //static enum htu21_status htu21_write_command(uint8_t); //static enum htu21_status htu21_write_command_no_stop(uint8_t); static enum htu21_status htu21_read_user_register(uint8_t *); static enum htu21_status htu21_write_user_register(uint8_t ); static enum htu21_status htu21_temperature_conversion_and_read_adc( uint16_t *); static enum htu21_status htu21_humidity_conversion_and_read_adc( uint16_t *); static enum htu21_status htu21_crc_check( uint16_t, uint8_t); static const char *TAG = "htu21d"; void i2c_master_init(void) { i2c_config_t *i2c_cfg_0 = get_i2c_num_0_cfg(); if (i2c_cfg_0 == NULL) { ESP_LOGE(TAG, "ERROR: i2c_master_init() returned NULL."); } } //void delay_ms(int ms) { // if (ms >= 0) { // vTaskDelay(ms / portTICK_PERIOD_MS); // } //} /** * \brief Configures the SERCOM I2C master to be used with the htu21 device. */ void htu21_init(void) { i2c_master_mode = htu21_i2c_no_hold; /* Initialize and enable device with config. */ i2c_master_init(); } /** * \brief Check whether HTU21 device is connected * * \return bool : status of HTU21 * - true : Device is present * - false : Device is not acknowledging I2C address */ bool htu21_is_connected(void) { enum status_code i2c_status; struct i2c_master_packet transfer = { .address = HTU21_ADDR, .data_length = 0, .data = NULL, }; /* Do the transfer */ esp_err_t err = write_address(HTU21_ADDR); if (err != ESP_OK) { ESP_LOGE(TAG, "write_address(HTU21D_ADDR(0x%.2x) returned error code: %d", HTU21_ADDR, err); return false; } return true; } /** * \brief Reset the HTU21 device * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge */ enum htu21_status htu21_reset(void) { enum htu21_status status; esp_err_t err = write_byte(HTU21_ADDR, HTU21_RESET_COMMAND); status = (err == ESP_OK) ? htu21_status_ok : htu21_status_i2c_transfer_error; htu21_temperature_conversion_time = HTU21_TEMPERATURE_CONVERSION_TIME_T_14b_RH_12b; htu21_humidity_conversion_time = HTU21_HUMIDITY_CONVERSION_TIME_T_14b_RH_12b; return status; } /** * \brief Set I2C master mode. * This determines whether the program will hold while ADC is accessed or will wait some time * * \param[in] htu21_i2c_master_mode : I2C mode * */ void htu21_set_i2c_master_mode(enum htu21_i2c_master_mode mode) { i2c_master_mode = mode; return; } /** * \brief Writes the HTU21 8-bits command with the value passed * * \param[in] uint8_t : Command value to be written. * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge */ // NOT USED in this implementation - brad //enum htu21_status htu21_write_command( uint8_t cmd) //{ // enum status_code i2c_status; // uint8_t data[1]; // // data[0] = cmd; // // struct i2c_master_packet transfer = { // .address = HTU21_ADDR, // .data_length = 1, // .data = data, // }; // /* Do the transfer */ // i2c_status = i2c_master_write_packet_wait(&transfer); // if( i2c_status == STATUS_ERR_OVERFLOW ) // return htu21_status_no_i2c_acknowledge; // if( i2c_status != STATUS_OK) // return htu21_status_i2c_transfer_error; // // return htu21_status_ok; //} /** * \brief Writes the HTU21 8-bits command with the value passed * Do not send the STOP bit in the I2C transfer * * \param[in] uint8_t : Command value to be written. * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge */ // NOT USED in this implementation - brad //enum htu21_status htu21_write_command_no_stop( uint8_t cmd) //{ // enum status_code i2c_status; // uint8_t data[1]; // // data[0] = cmd; // // struct i2c_master_packet transfer = { // .address = HTU21_ADDR, // .data_length = 1, // .data = data, // }; // // /* Do the transfer */ // i2c_status = i2c_master_write_packet_wait_no_stop(&transfer); // if( i2c_status == STATUS_ERR_OVERFLOW ) // return htu21_status_no_i2c_acknowledge; // if( i2c_status != STATUS_OK) // return htu21_status_i2c_transfer_error; // // return htu21_status_ok; //} /** * \brief Check CRC * * \param[in] uint16_t : variable on which to check CRC * \param[in] uint8_t : CRC value * * \return htu21_status : status of HTU21 * - htu21_status_ok : CRC check is OK * - htu21_status_crc_error : CRC check error */ enum htu21_status htu21_crc_check( uint16_t value, uint8_t crc) { uint32_t polynom = 0x988000; // x^8 + x^5 + x^4 + 1 uint32_t msb = 0x800000; uint32_t mask = 0xFF8000; uint32_t result = (uint32_t) value << 8; // Pad with zeros as specified in spec while (msb != 0x80) { // Check if msb of current value is 1 and apply XOR mask if (result & msb) result = ((result ^ polynom) & mask) | (result & ~mask); // Shift by one msb >>= 1; mask >>= 1; polynom >>= 1; } if (result == crc) return htu21_status_ok; else return htu21_status_crc_error; } /** * \brief Reads the HTU21 user register. * * \param[out] uint8_t* : Storage of user register value * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge */ enum htu21_status htu21_read_user_register(uint8_t *value) { // enum htu21_status status; // enum status_code i2c_status; // uint8_t buffer[1]; // buffer[0] = 0; /* Read data */ // struct i2c_master_packet read_transfer = { // .address = HTU21_ADDR, // .data_length = 1, // .data = buffer, // }; // Send the Read Register Command *value = read_register_8(HTU21_ADDR, HTU21_READ_USER_REG_COMMAND); //// status = htu21_write_command(HTU21_READ_USER_REG_COMMAND); // if (err != ESP_OK) { // status = htu21_status_i2c_transfer_error; // return status; // } // // i2c_status = i2c_master_read_packet_wait(&read_transfer); // if( i2c_status == STATUS_ERR_OVERFLOW ) // return htu21_status_no_i2c_acknowledge; // if( i2c_status != STATUS_OK) // return htu21_status_i2c_transfer_error; // // *value = buffer[0]; return htu21_status_ok; } /** * \brief Writes the htu21 user register with value * Will read and keep the unreserved bits of the register * * \param[in] uint8_t : Register value to be set. * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge */ enum htu21_status htu21_write_user_register(uint8_t value) { enum htu21_status status; enum status_code i2c_status; uint8_t reg; uint8_t data[2]; status = htu21_read_user_register(&reg); if (status != htu21_status_ok) return status; // Clear bits of reg that are not reserved reg &= HTU21_USER_REG_RESERVED_MASK; // Set bits from value that are not reserved reg |= (value & ~HTU21_USER_REG_RESERVED_MASK); // data[0] = HTU21_WRITE_USER_REG_COMMAND; // data[1] = reg; // // struct i2c_master_packet transfer = { // .address = HTU21_ADDR, // .data_length = 2, // .data = data, // }; /* Do the transfer */ uint16_t len = write_register(HTU21_ADDR, HTU21_WRITE_USER_REG_COMMAND, &reg, 1); // i2c_status = i2c_master_write_packet_wait(&transfer); // if( i2c_status == STATUS_ERR_OVERFLOW ) // return htu21_status_no_i2c_acknowledge; // if( i2c_status != STATUS_OK) // return htu21_status_i2c_transfer_error; return (len == 1) ? htu21_status_ok : htu21_status_i2c_transfer_error; } /** * \brief Reads the temperature ADC value * * \param[out] uint16_t* : Temperature ADC value. * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge * - htu21_status_crc_error : CRC check error */ enum htu21_status htu21_temperature_conversion_and_read_adc( uint16_t *adc) { enum htu21_status status = htu21_status_ok; enum status_code i2c_status; uint16_t _adc; uint8_t buffer[3]; uint8_t crc; buffer[0] = 0; buffer[1] = 0; buffer[2] = 0; /* Read data */ // struct i2c_master_packet read_transfer = { // .address = HTU21_ADDR, // .data_length = 3, // .data = buffer, // }; uint8_t cmd = (i2c_master_mode == htu21_i2c_hold) ? HTU21_READ_TEMPERATURE_W_HOLD_COMMAND : HTU21_READ_TEMPERATURE_WO_HOLD_COMMAND; esp_err_t w_err = write_byte(HTU21_ADDR, cmd); if (w_err != ESP_OK) { return htu21_status_i2c_transfer_error; } vTaskDelay((htu21_temperature_conversion_time / 1000) / portTICK_PERIOD_MS); // delay_ms(htu21_temperature_conversion_time/1000); // if( i2c_master_mode == htu21_i2c_hold) { // status = htu21_write_command_no_stop(HTU21_READ_TEMPERATURE_W_HOLD_COMMAND); // } // else { // status = htu21_write_command(HTU21_READ_TEMPERATURE_WO_HOLD_COMMAND); // delay_ms(htu21_temperature_conversion_time/1000); // } // if( status != htu21_status_ok) // return status; uint16_t len_read = read_bytes(HTU21_ADDR, buffer, 3); if (len_read != 3) { return htu21_status_i2c_transfer_error; } //// i2c_status = i2c_master_read_packet_wait(&read_transfer); // if( i2c_status == STATUS_ERR_OVERFLOW ) // return htu21_status_no_i2c_acknowledge; // if( i2c_status != STATUS_OK) // return htu21_status_i2c_transfer_error; _adc = (buffer[0] << 8) | buffer[1]; crc = buffer[2]; // compute CRC status = htu21_crc_check(_adc, crc); if (status != htu21_status_ok) return status; *adc = _adc; return status; } /** * \brief Reads the relative humidity ADC value * * \param[out] uint16_t* : Relative humidity ADC value. * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge * - htu21_status_crc_error : CRC check error */ enum htu21_status htu21_humidity_conversion_and_read_adc( uint16_t *adc) { enum htu21_status status = htu21_status_ok; enum status_code i2c_status; uint16_t _adc; uint8_t buffer[3]; uint8_t crc; buffer[0] = 0; buffer[1] = 0; buffer[2] = 0; /* Read data */ // struct i2c_master_packet read_transfer = { // .address = HTU21_ADDR, // .data_length = 3, // .data = buffer, // }; uint8_t cmd = (i2c_master_mode == htu21_i2c_hold) ? HTU21_READ_HUMIDITY_W_HOLD_COMMAND : HTU21_READ_HUMIDITY_WO_HOLD_COMMAND; esp_err_t w_err = write_byte(HTU21_ADDR, cmd); if (w_err != ESP_OK) { return htu21_status_i2c_transfer_error; } vTaskDelay((htu21_humidity_conversion_time / 1000) / portTICK_PERIOD_MS); // delay_ms(htu21_humidity_conversion_time/1000); // if( i2c_master_mode == htu21_i2c_hold) { // status = htu21_write_command_no_stop(HTU21_READ_HUMIDITY_W_HOLD_COMMAND); // } // else { // status = htu21_write_command(HTU21_READ_HUMIDITY_WO_HOLD_COMMAND); // delay_ms(htu21_humidity_conversion_time/1000); // } // if( status != htu21_status_ok) // return status; // i2c_status = i2c_master_read_packet_wait(&read_transfer); // if( i2c_status == STATUS_ERR_OVERFLOW ) // return htu21_status_no_i2c_acknowledge; // if( i2c_status != STATUS_OK) // return htu21_status_i2c_transfer_error; uint16_t len_read = read_bytes(HTU21_ADDR, buffer, 3); if (len_read != 3) { return htu21_status_i2c_transfer_error; } _adc = (buffer[0] << 8) | buffer[1]; crc = buffer[2]; // compute CRC status = htu21_crc_check(_adc, crc); if (status != htu21_status_ok) return status; *adc = _adc; return status; } /** * \brief Reads the htu21 serial number. * * \param[out] uint64_t* : Serial number * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge * - htu21_status_crc_error : CRC check error */ enum htu21_status htu21_read_serial_number(uint64_t * serial_number) { enum htu21_status status; enum status_code i2c_status; uint8_t cmd_data[2]; uint8_t rcv_data[14]; uint8_t i; struct i2c_master_packet transfer = { .address = HTU21_ADDR, .data_length = 2, .data = cmd_data, }; struct i2c_master_packet read_transfer = { .address = HTU21_ADDR, .data_length = 8, .data = rcv_data, }; // Read the first 8 bytes // cmd_data[0] = (HTU21_READ_SERIAL_FIRST_8BYTES_COMMAND>>8)&0xFF; // cmd_data[1] = HTU21_READ_SERIAL_FIRST_8BYTES_COMMAND&0xFF; // // /* Do the transfer */ // i2c_master_write_packet_wait_no_stop(&transfer); // i2c_status = i2c_master_read_packet_wait(&read_transfer); // if( i2c_status == STATUS_ERR_OVERFLOW ) // return htu21_status_no_i2c_acknowledge; // if( i2c_status != STATUS_OK) // return htu21_status_i2c_transfer_error; esp_err_t err = write_byte(HTU21_ADDR, (HTU21_READ_SERIAL_FIRST_8BYTES_COMMAND >> 8) & 0xFF); if (err != ESP_OK) { return htu21_status_i2c_transfer_error; } err = write_byte(HTU21_ADDR, HTU21_READ_SERIAL_FIRST_8BYTES_COMMAND & 0xFF); if (err != ESP_OK) { return htu21_status_i2c_transfer_error; } uint16_t len_read = read_bytes(HTU21_ADDR, rcv_data, 8); if (len_read != 8) { return htu21_status_i2c_transfer_error; } // // Read the last 6 bytes // cmd_data[0] = (HTU21_READ_SERIAL_LAST_6BYTES_COMMAND>>8)&0xFF; // cmd_data[1] = HTU21_READ_SERIAL_LAST_6BYTES_COMMAND&0xFF; // // read_transfer.data = &rcv_data[8]; // read_transfer.data_length = 6; // // /* Do the transfer */ // i2c_master_write_packet_wait_no_stop(&transfer); // i2c_status = i2c_master_read_packet_wait(&read_transfer); // if( i2c_status == STATUS_ERR_OVERFLOW ) // return htu21_status_no_i2c_acknowledge; // if( i2c_status != STATUS_OK) // return htu21_status_i2c_transfer_error; err = write_byte(HTU21_ADDR, (HTU21_READ_SERIAL_LAST_6BYTES_COMMAND >> 8) & 0xFF); if (err != ESP_OK) { return htu21_status_i2c_transfer_error; } err = write_byte(HTU21_ADDR, HTU21_READ_SERIAL_LAST_6BYTES_COMMAND & 0xFF); if (err != ESP_OK) { return htu21_status_i2c_transfer_error; } len_read = read_bytes(HTU21_ADDR, &rcv_data[8], 6); if (len_read != 6) { return htu21_status_i2c_transfer_error; } for (i = 0; i < 8; i += 2) { status = htu21_crc_check(rcv_data[i], rcv_data[i + 1]); if (status != htu21_status_ok) return status; } for (i = 8; i < 14; i += 3) { status = htu21_crc_check(((rcv_data[i] << 8) | (rcv_data[i + 1])), rcv_data[i + 2]); if (status != htu21_status_ok) return status; } *serial_number = ((uint64_t) rcv_data[0] << 56) | ((uint64_t) rcv_data[2] << 48) | ((uint64_t) rcv_data[4] << 40) | ((uint64_t) rcv_data[6] << 32) | ((uint64_t) rcv_data[8] << 24) | ((uint64_t) rcv_data[9] << 16) | ((uint64_t) rcv_data[11] << 8) | ((uint64_t) rcv_data[12] << 0); return htu21_status_ok; } /** * \brief Set temperature & humidity ADC resolution. * * \param[in] htu21_resolution : Resolution requested * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge * - htu21_status_crc_error : CRC check error */ enum htu21_status htu21_set_resolution(enum htu21_resolution res) { enum htu21_status status; uint8_t reg_value, tmp = 0; uint32_t temperature_conversion_time = HTU21_TEMPERATURE_CONVERSION_TIME_T_14b_RH_12b; uint32_t humidity_conversion_time = HTU21_HUMIDITY_CONVERSION_TIME_T_14b_RH_12b; if (res == htu21_resolution_t_14b_rh_12b) { tmp = HTU21_USER_REG_RESOLUTION_T_14b_RH_12b; temperature_conversion_time = HTU21_TEMPERATURE_CONVERSION_TIME_T_14b_RH_12b; humidity_conversion_time = HTU21_HUMIDITY_CONVERSION_TIME_T_14b_RH_12b; } else if (res == htu21_resolution_t_13b_rh_10b) { tmp = HTU21_USER_REG_RESOLUTION_T_13b_RH_10b; temperature_conversion_time = HTU21_TEMPERATURE_CONVERSION_TIME_T_13b_RH_10b; humidity_conversion_time = HTU21_HUMIDITY_CONVERSION_TIME_T_13b_RH_10b; } else if (res == htu21_resolution_t_12b_rh_8b) { tmp = HTU21_USER_REG_RESOLUTION_T_12b_RH_8b; temperature_conversion_time = HTU21_TEMPERATURE_CONVERSION_TIME_T_12b_RH_8b; humidity_conversion_time = HTU21_HUMIDITY_CONVERSION_TIME_T_12b_RH_8b; } else if (res == htu21_resolution_t_11b_rh_11b) { tmp = HTU21_USER_REG_RESOLUTION_T_11b_RH_11b; temperature_conversion_time = HTU21_TEMPERATURE_CONVERSION_TIME_T_11b_RH_11b; humidity_conversion_time = HTU21_HUMIDITY_CONVERSION_TIME_T_11b_RH_11b; } status = htu21_read_user_register(&reg_value); if (status != htu21_status_ok) return status; // Clear the resolution bits reg_value &= ~HTU21_USER_REG_RESOLUTION_MASK; reg_value |= tmp & HTU21_USER_REG_RESOLUTION_MASK; htu21_temperature_conversion_time = temperature_conversion_time; htu21_humidity_conversion_time = humidity_conversion_time; status = htu21_write_user_register(reg_value); return status; } /** * \brief Provide battery status * * \param[out] htu21_battery_status* : Battery status * - htu21_battery_ok, * - htu21_battery_low * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge */ enum htu21_status htu21_get_battery_status(enum htu21_battery_status *bat) { enum htu21_status status; uint8_t reg_value; status = htu21_read_user_register(&reg_value); if (status != htu21_status_ok) return status; if (reg_value & HTU21_USER_REG_END_OF_BATTERY_VDD_BELOW_2_25V) *bat = htu21_battery_low; else *bat = htu21_battery_ok; return status; } /** * \brief Enable heater * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge */ enum htu21_status htu21_enable_heater(void) { enum htu21_status status; uint8_t reg_value; status = htu21_read_user_register(&reg_value); if (status != htu21_status_ok) return status; // Clear the resolution bits reg_value |= HTU21_USER_REG_ONCHIP_HEATER_ENABLE; status = htu21_write_user_register(reg_value); return status; } /** * \brief Disable heater * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge */ enum htu21_status htu21_disable_heater(void) { enum htu21_status status; uint8_t reg_value; status = htu21_read_user_register(&reg_value); if (status != htu21_status_ok) return status; // Clear the resolution bits reg_value &= ~HTU21_USER_REG_ONCHIP_HEATER_ENABLE; status = htu21_write_user_register(reg_value); return status; } /** * \brief Get heater status * * \param[in] htu21_heater_status* : Return heater status (above or below 2.5V) * - htu21_heater_off, * - htu21_heater_on * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge */ enum htu21_status htu21_get_heater_status(enum htu21_heater_status *heater) { enum htu21_status status; uint8_t reg_value; status = htu21_read_user_register(&reg_value); if (status != htu21_status_ok) return status; // Get the heater enable bit in reg_value if (reg_value & HTU21_USER_REG_ONCHIP_HEATER_ENABLE) *heater = htu21_heater_on; else *heater = htu21_heater_off; return status; } /** * \brief Reads the relative humidity value. * * \param[out] float* : Celsius Degree temperature value * \param[out] float* : %RH Relative Humidity value * * \return htu21_status : status of HTU21 * - htu21_status_ok : I2C transfer completed successfully * - htu21_status_i2c_transfer_error : Problem with i2c transfer * - htu21_status_no_i2c_acknowledge : I2C did not acknowledge * - htu21_status_crc_error : CRC check error */ enum htu21_status htu21_read_temperature_and_relative_humidity( float *temperature, float *humidity) { enum htu21_status status; uint16_t adc; status = htu21_temperature_conversion_and_read_adc(&adc); if (status != htu21_status_ok) return status; // Perform conversion function *temperature = (float) adc * TEMPERATURE_COEFF_MUL / (1UL << 16) + TEMPERATURE_COEFF_ADD; status = htu21_humidity_conversion_and_read_adc(&adc); if (status != htu21_status_ok) return status; // Perform conversion function *humidity = (float) adc * HUMIDITY_COEFF_MUL / (1UL << 16) + HUMIDITY_COEFF_ADD; return status; } /** * \brief Returns result of compensated humidity * * \param[in] float - Actual temperature measured (degC) * \param[in] float - Actual relative humidity measured (%RH) * * \return float - Compensated humidity (%RH). */ float htu21_compute_compensated_humidity(float temperature,float relative_humidity) { return (relative_humidity + (25 - temperature) * HTU21_TEMPERATURE_COEFFICIENT); } /** * \brief Returns the computed dew point * * \param[in] float - Actual temperature measured (degC) * \param[in] float - Actual relative humidity measured (%RH) * * \return float - Dew point temperature (DegC). */ float htu21_compute_dew_point(float temperature,float relative_humidity) { double partial_pressure; double dew_point; // Missing power of 10 partial_pressure = pow(10, HTU21_CONSTANT_A - HTU21_CONSTANT_B / (temperature + HTU21_CONSTANT_C)); dew_point = -HTU21_CONSTANT_B / (log10(relative_humidity * partial_pressure / 100) - HTU21_CONSTANT_A) - HTU21_CONSTANT_C; return (float) dew_point; } #ifdef __cplusplus } #endif
44175.c
// Test the handling of >> operator #define TOTAL_KEYS_LOG_2 16 #define NUM_BUCKETS_LOG_2 9 #define TOTAL_KEYS (1 << TOTAL_KEYS_LOG_2) #define NUM_KEYS TOTAL_KEYS #define SIZE_OF_BUFFERS NUM_KEYS #define NUM_BUCKETS (1 << NUM_BUCKETS_LOG_2) // 1<< 9 int key_array[65536]; // 1<<9 int bucket_size[512]; void foo(int shift) { int i; // 1<<9 for (i = 0; i <= 65535; i += 1) { bucket_size[key_array[i] >> shift]++; } }
63633.c
/* $OpenBSD: pdq.c,v 1.15 2011/04/05 19:54:35 jasper Exp $ */ /* $NetBSD: pdq.c,v 1.9 1996/10/13 01:37:26 christos Exp $ */ /*- * Copyright (c) 1995,1996 Matt Thomas <[email protected]> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Id: pdq.c,v 1.27 1996/06/07 20:02:25 thomas Exp * */ /* * DEC PDQ FDDI Controller O/S independent code * * This module should work any PDQ based board. Note that changes for * MIPS and Alpha architectures (or any other architecture which requires * a flushing of memory or write buffers and/or has incoherent caches) * have yet to be made. * * However, it is expected that the PDQ_CSR_WRITE macro will cause a * flushing of the write buffers. */ #define PDQ_HWSUPPORT /* for pdq.h */ #include "pdqvar.h" #include "pdqreg.h" #define PDQ_ROUNDUP(n, x) (((n) + ((x) - 1)) & ~((x) - 1)) #define PDQ_CMD_RX_ALIGNMENT 16 #if (defined(PDQTEST) && !defined(PDQ_NOPRINTF)) || defined(PDQVERBOSE) #define PDQ_PRINTF(x) printf x #else #define PDQ_PRINTF(x) do { } while (0) #endif static const char * const pdq_halt_codes[] = { "Selftest Timeout", "Host Bus Parity Error", "Host Directed Fault", "Software Fault", "Hardware Fault", "PC Trace Path Test", "DMA Error", "Image CRC Error", "Adapter Processer Error" }; static const char * const pdq_adapter_states[] = { "Reset", "Upgrade", "DMA Unavailable", "DMA Available", "Link Available", "Link Unavailable", "Halted", "Ring Member" }; /* * The following are used in conjunction with * unsolicited events */ static const char * const pdq_entities[] = { "Station", "Link", "Phy Port" }; static const char * const pdq_station_events[] = { "Trace Received" }; static const char * const pdq_station_arguments[] = { "Reason" }; static const char * const pdq_link_events[] = { "Transmit Underrun", "Transmit Failed", "Block Check Error (CRC)", "Frame Status Error", "PDU Length Error", NULL, NULL, "Receive Data Overrun", NULL, "No User Buffer", "Ring Initialization Initiated", "Ring Initialization Received", "Ring Beacon Initiated", "Duplicate Address Failure", "Duplicate Token Detected", "Ring Purger Error", "FCI Strip Error", "Trace Initiated", "Directed Beacon Received", }; static const char * const pdq_link_arguments[] = { "Reason", "Data Link Header", "Source", "Upstream Neighbor" }; static const char * const pdq_phy_events[] = { "LEM Error Monitor Reject", "Elasticy Buffer Error", "Link Confidence Test Reject" }; static const char * const pdq_phy_arguments[] = { "Direction" }; static const char * const * const pdq_event_arguments[] = { pdq_station_arguments, pdq_link_arguments, pdq_phy_arguments }; static const char * const * const pdq_event_codes[] = { pdq_station_events, pdq_link_events, pdq_phy_events }; static const char * const pdq_station_types[] = { "SAS", "DAC", "SAC", "NAC", "DAS" }; static const char * const pdq_smt_versions[] = { "", "V6.2", "V7.2", "V7.3" }; static const char pdq_phy_types[] = "ABSM"; static const char * const pdq_pmd_types0[] = { "ANSI Multi-Mode", "ANSI Single-Mode Type 1", "ANSI Single-Mode Type 2", "ANSI Sonet" }; static const char * const pdq_pmd_types100[] = { "Low Power", "Thin Wire", "Shielded Twisted Pair", "Unshielded Twisted Pair" }; static const char * const * const pdq_pmd_types[] = { pdq_pmd_types0, pdq_pmd_types100 }; static const char * const pdq_descriptions[] = { "DEFPA PCI", "DEFEA EISA", "DEFTA TC", "DEFAA Futurebus", "DEFQA Q-bus", }; static void pdq_print_fddi_chars( pdq_t *pdq, const pdq_response_status_chars_get_t *rsp) { const char hexchars[] = "0123456789abcdef"; printf(PDQ_OS_PREFIX "DEC %s FDDI %s Controller\n", PDQ_OS_PREFIX_ARGS, pdq_descriptions[pdq->pdq_type], pdq_station_types[rsp->status_chars_get.station_type]); printf(PDQ_OS_PREFIX "FDDI address %c%c:%c%c:%c%c:%c%c:%c%c:%c%c, FW=%c%c%c%c, HW=%c", PDQ_OS_PREFIX_ARGS, hexchars[pdq->pdq_hwaddr.lanaddr_bytes[0] >> 4], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[0] & 0x0F], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[1] >> 4], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[1] & 0x0F], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[2] >> 4], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[2] & 0x0F], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[3] >> 4], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[3] & 0x0F], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[4] >> 4], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[4] & 0x0F], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[5] >> 4], hexchars[pdq->pdq_hwaddr.lanaddr_bytes[5] & 0x0F], pdq->pdq_fwrev.fwrev_bytes[0], pdq->pdq_fwrev.fwrev_bytes[1], pdq->pdq_fwrev.fwrev_bytes[2], pdq->pdq_fwrev.fwrev_bytes[3], rsp->status_chars_get.module_rev.fwrev_bytes[0]); if (rsp->status_chars_get.smt_version_id < PDQ_ARRAY_SIZE(pdq_smt_versions)) { printf(", SMT %s\n", pdq_smt_versions[rsp->status_chars_get.smt_version_id]); } printf(PDQ_OS_PREFIX "FDDI Port%s = %c (PMD = %s)", PDQ_OS_PREFIX_ARGS, rsp->status_chars_get.station_type == PDQ_STATION_TYPE_DAS ? "[A]" : "", pdq_phy_types[rsp->status_chars_get.phy_type[0]], pdq_pmd_types[rsp->status_chars_get.pmd_type[0] / 100][rsp->status_chars_get.pmd_type[0] % 100]); if (rsp->status_chars_get.station_type == PDQ_STATION_TYPE_DAS) printf(", FDDI Port[B] = %c (PMD = %s)", pdq_phy_types[rsp->status_chars_get.phy_type[1]], pdq_pmd_types[rsp->status_chars_get.pmd_type[1] / 100][rsp->status_chars_get.pmd_type[1] % 100]); printf("\n"); } static void pdq_init_csrs( pdq_csrs_t *csrs, pdq_bus_t bus, pdq_bus_memaddr_t csr_base, size_t csrsize) { csrs->csr_bus = bus; csrs->csr_base = csr_base; csrs->csr_port_reset = PDQ_CSR_OFFSET(csr_base, 0 * csrsize); csrs->csr_host_data = PDQ_CSR_OFFSET(csr_base, 1 * csrsize); csrs->csr_port_control = PDQ_CSR_OFFSET(csr_base, 2 * csrsize); csrs->csr_port_data_a = PDQ_CSR_OFFSET(csr_base, 3 * csrsize); csrs->csr_port_data_b = PDQ_CSR_OFFSET(csr_base, 4 * csrsize); csrs->csr_port_status = PDQ_CSR_OFFSET(csr_base, 5 * csrsize); csrs->csr_host_int_type_0 = PDQ_CSR_OFFSET(csr_base, 6 * csrsize); csrs->csr_host_int_enable = PDQ_CSR_OFFSET(csr_base, 7 * csrsize); csrs->csr_type_2_producer = PDQ_CSR_OFFSET(csr_base, 8 * csrsize); csrs->csr_cmd_response_producer = PDQ_CSR_OFFSET(csr_base, 10 * csrsize); csrs->csr_cmd_request_producer = PDQ_CSR_OFFSET(csr_base, 11 * csrsize); csrs->csr_host_smt_producer = PDQ_CSR_OFFSET(csr_base, 12 * csrsize); csrs->csr_unsolicited_producer = PDQ_CSR_OFFSET(csr_base, 13 * csrsize); } static void pdq_init_pci_csrs( pdq_pci_csrs_t *csrs, pdq_bus_t bus, pdq_bus_memaddr_t csr_base, size_t csrsize) { csrs->csr_bus = bus; csrs->csr_base = csr_base; csrs->csr_pfi_mode_control = PDQ_CSR_OFFSET(csr_base, 16 * csrsize); csrs->csr_pfi_status = PDQ_CSR_OFFSET(csr_base, 17 * csrsize); csrs->csr_fifo_write = PDQ_CSR_OFFSET(csr_base, 18 * csrsize); csrs->csr_fifo_read = PDQ_CSR_OFFSET(csr_base, 19 * csrsize); } static void pdq_flush_databuf_queue( pdq_databuf_queue_t *q) { PDQ_OS_DATABUF_T *pdu; for (;;) { PDQ_OS_DATABUF_DEQUEUE(q, pdu); if (pdu == NULL) return; PDQ_OS_DATABUF_FREE(pdu); } } static pdq_boolean_t pdq_do_port_control( const pdq_csrs_t * const csrs, pdq_uint32_t cmd) { int cnt = 0; PDQ_CSR_WRITE(csrs, csr_host_int_type_0, PDQ_HOST_INT_CSR_CMD_DONE); PDQ_CSR_WRITE(csrs, csr_port_control, PDQ_PCTL_CMD_ERROR | cmd); while ((PDQ_CSR_READ(csrs, csr_host_int_type_0) & PDQ_HOST_INT_CSR_CMD_DONE) == 0 && cnt < 33000000) cnt++; PDQ_PRINTF(("CSR cmd spun %d times\n", cnt)); if (PDQ_CSR_READ(csrs, csr_host_int_type_0) & PDQ_HOST_INT_CSR_CMD_DONE) { PDQ_CSR_WRITE(csrs, csr_host_int_type_0, PDQ_HOST_INT_CSR_CMD_DONE); return (PDQ_CSR_READ(csrs, csr_port_control) & PDQ_PCTL_CMD_ERROR) ? PDQ_FALSE : PDQ_TRUE; } /* adapter failure */ PDQ_ASSERT(0); return PDQ_FALSE; } static void pdq_read_mla( const pdq_csrs_t * const csrs, pdq_lanaddr_t *hwaddr) { pdq_uint32_t data; PDQ_CSR_WRITE(csrs, csr_port_data_a, 0); pdq_do_port_control(csrs, PDQ_PCTL_MLA_READ); data = PDQ_CSR_READ(csrs, csr_host_data); hwaddr->lanaddr_bytes[0] = (data >> 0) & 0xFF; hwaddr->lanaddr_bytes[1] = (data >> 8) & 0xFF; hwaddr->lanaddr_bytes[2] = (data >> 16) & 0xFF; hwaddr->lanaddr_bytes[3] = (data >> 24) & 0xFF; PDQ_CSR_WRITE(csrs, csr_port_data_a, 1); pdq_do_port_control(csrs, PDQ_PCTL_MLA_READ); data = PDQ_CSR_READ(csrs, csr_host_data); hwaddr->lanaddr_bytes[4] = (data >> 0) & 0xFF; hwaddr->lanaddr_bytes[5] = (data >> 8) & 0xFF; } static void pdq_read_fwrev( const pdq_csrs_t * const csrs, pdq_fwrev_t *fwrev) { pdq_uint32_t data; pdq_do_port_control(csrs, PDQ_PCTL_FW_REV_READ); data = PDQ_CSR_READ(csrs, csr_host_data); fwrev->fwrev_bytes[3] = (data >> 0) & 0xFF; fwrev->fwrev_bytes[2] = (data >> 8) & 0xFF; fwrev->fwrev_bytes[1] = (data >> 16) & 0xFF; fwrev->fwrev_bytes[0] = (data >> 24) & 0xFF; } static pdq_boolean_t pdq_read_error_log( pdq_t *pdq, pdq_response_error_log_get_t *log_entry) { const pdq_csrs_t * const csrs = &pdq->pdq_csrs; pdq_uint32_t *ptr = (pdq_uint32_t *) log_entry; pdq_do_port_control(csrs, PDQ_PCTL_ERROR_LOG_START); while (pdq_do_port_control(csrs, PDQ_PCTL_FW_REV_READ) == PDQ_TRUE) { *ptr++ = PDQ_CSR_READ(csrs, csr_host_data); if ((pdq_uint8_t *) ptr - (pdq_uint8_t *) log_entry == sizeof(*log_entry)) break; } return (ptr == (pdq_uint32_t *) log_entry) ? PDQ_FALSE : PDQ_TRUE; } static pdq_chip_rev_t pdq_read_chiprev( const pdq_csrs_t * const csrs) { pdq_uint32_t data; PDQ_CSR_WRITE(csrs, csr_port_data_a, PDQ_SUB_CMD_PDQ_REV_GET); pdq_do_port_control(csrs, PDQ_PCTL_SUB_CMD); data = PDQ_CSR_READ(csrs, csr_host_data); return (pdq_chip_rev_t) data; } static const struct { size_t cmd_len; size_t rsp_len; const char *cmd_name; } pdq_cmd_info[] = { #define YES(cmd, rsp, name) { sizeof(cmd), sizeof(rsp), name } #define NO(cmd, rsp, name) { 0, 0, name } YES(pdq_cmd_generic_t, /* 0 - PDQC_START */ pdq_response_generic_t, "Start"), YES(pdq_cmd_filter_set_t, /* 1 - PDQC_FILTER_SET */ pdq_response_generic_t, "Filter Set"), YES(pdq_cmd_generic_t, /* 2 - PDQC_FILTER_GET */ pdq_response_filter_get_t, "Filter Get"), YES(pdq_cmd_chars_set_t, /* 3 - PDQC_CHARS_SET */ pdq_response_generic_t, "Chars Set"), YES(pdq_cmd_generic_t, /* 4 - PDQC_STATUS_CHARS_GET */ pdq_response_status_chars_get_t, "Status Chars Get"), NO(pdq_cmd_generic_t, /* 5 - PDQC_COUNTERS_GET */ pdq_response_counters_get_t, "Counters Get"), NO(pdq_cmd_counters_set_t, /* 6 - PDQC_COUNTERS_SET */ pdq_response_generic_t, "Counters Set"), YES(pdq_cmd_addr_filter_set_t, /* 7 - PDQC_ADDR_FILTER_SET */ pdq_response_generic_t, "Addr Filter Set"), YES(pdq_cmd_generic_t, /* 8 - PDQC_ADDR_FILTER_GET */ pdq_response_addr_filter_get_t, "Addr Filter Get"), NO(pdq_cmd_generic_t, /* 9 - PDQC_ERROR_LOG_CLEAR */ pdq_response_generic_t, "Error Log Clear"), NO(pdq_cmd_generic_t, /* 10 - PDQC_ERROR_LOG_SET */ pdq_response_generic_t, "Error Log Set"), NO(pdq_cmd_generic_t, /* 11 - PDQC_FDDI_MIB_GET */ pdq_response_generic_t, "FDDI MIB Get"), NO(pdq_cmd_generic_t, /* 12 - PDQC_DEC_EXT_MIB_GET */ pdq_response_generic_t, "DEC Ext MIB Get"), NO(pdq_cmd_generic_t, /* 13 - PDQC_DEC_SPECIFIC_GET */ pdq_response_generic_t, "DEC Specific Get"), NO(pdq_cmd_generic_t, /* 14 - PDQC_SNMP_SET */ pdq_response_generic_t, "SNMP Set"), NO(XXX, XXX, "N/A"), /* 15 - XXX */ NO(pdq_cmd_generic_t, /* 16 - PDQC_SMT_MIB_GET */ pdq_response_generic_t, "SMT MIB Get"), NO(pdq_cmd_generic_t, /* 17 - PDQC_SMT_MIB_SET */ pdq_response_generic_t, "SMT MIB Set"), }; static void pdq_queue_commands( pdq_t *pdq) { const pdq_csrs_t * const csrs = &pdq->pdq_csrs; pdq_command_info_t * const ci = &pdq->pdq_command_info; pdq_descriptor_block_t * const dbp = pdq->pdq_dbp; pdq_cmd_code_t op; pdq_uint32_t cmdlen, rsplen, mask; /* * If there are commands or responses active or there aren't * any pending commands, then don't queue any more. */ if (ci->ci_command_active || ci->ci_pending_commands == 0) return; /* * Determine which command needs to be queued. */ op = PDQC_SMT_MIB_SET; for (mask = 1 << ((int) op); (mask & ci->ci_pending_commands) == 0; mask >>= 1) op = (pdq_cmd_code_t) ((int) op - 1); /* * Obtain the sizes needed for the command and response. * Round up to PDQ_CMD_RX_ALIGNMENT so the receive buffer is * always properly aligned. */ cmdlen = PDQ_ROUNDUP(pdq_cmd_info[op].cmd_len, PDQ_CMD_RX_ALIGNMENT); rsplen = PDQ_ROUNDUP(pdq_cmd_info[op].rsp_len, PDQ_CMD_RX_ALIGNMENT); if (cmdlen < rsplen) cmdlen = rsplen; /* * Since only one command at a time will be queued, there will always * be enough space. */ /* * Obtain and fill in the descriptor for the command (descriptor is * pre-initialized) */ dbp->pdqdb_command_requests[ci->ci_request_producer].txd_seg_len = cmdlen; PDQ_ADVANCE(ci->ci_request_producer, 1, PDQ_RING_MASK(dbp->pdqdb_command_requests)); /* * Obtain and fill in the descriptor for the response (descriptor is * pre-initialized) */ dbp->pdqdb_command_responses[ci->ci_response_producer].rxd_seg_len_hi = cmdlen / 16; PDQ_ADVANCE(ci->ci_response_producer, 1, PDQ_RING_MASK(dbp->pdqdb_command_responses)); /* * Clear the command area, set the opcode, and the command from the pending * mask. */ PDQ_OS_MEMZERO(ci->ci_bufstart, cmdlen); *(pdq_cmd_code_t *) ci->ci_bufstart = op; ci->ci_pending_commands &= ~mask; /* * Fill in the command area, if needed. */ switch (op) { case PDQC_FILTER_SET: { pdq_cmd_filter_set_t *filter_set = (pdq_cmd_filter_set_t *) ci->ci_bufstart; unsigned idx = 0; filter_set->filter_set_items[idx].item_code = PDQI_IND_GROUP_PROM; filter_set->filter_set_items[idx].filter_state = (pdq->pdq_flags & PDQ_PROMISC ? PDQ_FILTER_PASS : PDQ_FILTER_BLOCK); idx++; filter_set->filter_set_items[idx].item_code = PDQI_GROUP_PROM; filter_set->filter_set_items[idx].filter_state = (pdq->pdq_flags & PDQ_ALLMULTI ? PDQ_FILTER_PASS : PDQ_FILTER_BLOCK); idx++; filter_set->filter_set_items[idx].item_code = PDQI_SMT_PROM; filter_set->filter_set_items[idx].filter_state = ((pdq->pdq_flags & (PDQ_PROMISC|PDQ_PASS_SMT)) == (PDQ_PROMISC|PDQ_PASS_SMT) ? PDQ_FILTER_PASS : PDQ_FILTER_BLOCK); idx++; filter_set->filter_set_items[idx].item_code = PDQI_SMT_USER; filter_set->filter_set_items[idx].filter_state = (pdq->pdq_flags & PDQ_PASS_SMT ? PDQ_FILTER_PASS : PDQ_FILTER_BLOCK); idx++; filter_set->filter_set_items[idx].item_code = PDQI_EOL; break; } case PDQC_ADDR_FILTER_SET: { pdq_cmd_addr_filter_set_t *addr_filter_set = (pdq_cmd_addr_filter_set_t *) ci->ci_bufstart; pdq_lanaddr_t *addr = addr_filter_set->addr_filter_set_addresses; addr->lanaddr_bytes[0] = 0xFF; addr->lanaddr_bytes[1] = 0xFF; addr->lanaddr_bytes[2] = 0xFF; addr->lanaddr_bytes[3] = 0xFF; addr->lanaddr_bytes[4] = 0xFF; addr->lanaddr_bytes[5] = 0xFF; addr++; pdq_os_addr_fill(pdq, addr, 61); break; } default: break; } /* * At this point the command is done. All that needs to be done is to * produce it to the PDQ. */ PDQ_PRINTF(("PDQ Queue Command Request: %s queued\n", pdq_cmd_info[op].cmd_name)); ci->ci_command_active++; PDQ_CSR_WRITE(csrs, csr_cmd_response_producer, ci->ci_response_producer | (ci->ci_response_completion << 8)); PDQ_CSR_WRITE(csrs, csr_cmd_request_producer, ci->ci_request_producer | (ci->ci_request_completion << 8)); } static void pdq_process_command_responses( pdq_t * const pdq) { const pdq_csrs_t * const csrs = &pdq->pdq_csrs; pdq_command_info_t * const ci = &pdq->pdq_command_info; volatile const pdq_consumer_block_t * const cbp = pdq->pdq_cbp; pdq_descriptor_block_t * const dbp = pdq->pdq_dbp; const pdq_response_generic_t *rspgen; /* * We have to process the command and response in tandem so * just wait for the response to be consumed. If it has been * consumed then the command must have been as well. */ if (cbp->pdqcb_command_response == ci->ci_response_completion) return; PDQ_ASSERT(cbp->pdqcb_command_request != ci->ci_request_completion); rspgen = (const pdq_response_generic_t *) ci->ci_bufstart; PDQ_ASSERT(rspgen->generic_status == PDQR_SUCCESS); PDQ_PRINTF(("PDQ Process Command Response: %s completed (status=%d)\n", pdq_cmd_info[rspgen->generic_op].cmd_name, rspgen->generic_status)); if (rspgen->generic_op == PDQC_STATUS_CHARS_GET && (pdq->pdq_flags & PDQ_PRINTCHARS)) { pdq->pdq_flags &= ~PDQ_PRINTCHARS; pdq_print_fddi_chars(pdq, (const pdq_response_status_chars_get_t *) rspgen); } PDQ_ADVANCE(ci->ci_request_completion, 1, PDQ_RING_MASK(dbp->pdqdb_command_requests)); PDQ_ADVANCE(ci->ci_response_completion, 1, PDQ_RING_MASK(dbp->pdqdb_command_responses)); ci->ci_command_active = 0; if (ci->ci_pending_commands != 0) { pdq_queue_commands(pdq); } else { PDQ_CSR_WRITE(csrs, csr_cmd_response_producer, ci->ci_response_producer | (ci->ci_response_completion << 8)); PDQ_CSR_WRITE(csrs, csr_cmd_request_producer, ci->ci_request_producer | (ci->ci_request_completion << 8)); } } /* * This following routine processes unsolicited events. * In addition, it also fills the unsolicited queue with * event buffers so it can be used to initialize the queue * as well. */ static void pdq_process_unsolicited_events( pdq_t *pdq) { const pdq_csrs_t * const csrs = &pdq->pdq_csrs; pdq_unsolicited_info_t *ui = &pdq->pdq_unsolicited_info; volatile const pdq_consumer_block_t *cbp = pdq->pdq_cbp; pdq_descriptor_block_t *dbp = pdq->pdq_dbp; const pdq_unsolicited_event_t *event; pdq_rxdesc_t *rxd; /* * Process each unsolicited event (if any). */ while (cbp->pdqcb_unsolicited_event != ui->ui_completion) { rxd = &dbp->pdqdb_unsolicited_events[ui->ui_completion]; event = &ui->ui_events[ui->ui_completion & (PDQ_NUM_UNSOLICITED_EVENTS-1)]; switch (event->event_type) { case PDQ_UNSOLICITED_EVENT: { printf(PDQ_OS_PREFIX "Unsolicited Event: %s: %s", PDQ_OS_PREFIX_ARGS, pdq_entities[event->event_entity], pdq_event_codes[event->event_entity][event->event_code.value]); if (event->event_entity == PDQ_ENTITY_PHY_PORT) printf("[%d]", event->event_index); printf("\n"); break; } case PDQ_UNSOLICITED_COUNTERS: { break; } } PDQ_ADVANCE(ui->ui_completion, 1, PDQ_RING_MASK(dbp->pdqdb_unsolicited_events)); ui->ui_free++; } /* * Now give back the event buffers back to the PDQ. */ PDQ_ADVANCE(ui->ui_producer, ui->ui_free, PDQ_RING_MASK(dbp->pdqdb_unsolicited_events)); ui->ui_free = 0; PDQ_CSR_WRITE(csrs, csr_unsolicited_producer, ui->ui_producer | (ui->ui_completion << 8)); } static void pdq_process_received_data( pdq_t *pdq, pdq_rx_info_t *rx, pdq_rxdesc_t *receives, pdq_uint32_t completion_goal, pdq_uint32_t ring_mask) { pdq_uint32_t completion = rx->rx_completion; pdq_uint32_t producer = rx->rx_producer; PDQ_OS_DATABUF_T **buffers = (PDQ_OS_DATABUF_T **) rx->rx_buffers; pdq_rxdesc_t *rxd; pdq_uint32_t idx; while (completion != completion_goal) { PDQ_OS_DATABUF_T *fpdu, *lpdu, *npdu; pdq_uint8_t *dataptr; pdq_uint32_t fc, datalen, pdulen, segcnt; pdq_rxstatus_t status; fpdu = lpdu = buffers[completion]; PDQ_ASSERT(fpdu != NULL); dataptr = PDQ_OS_DATABUF_PTR(fpdu); status = *(pdq_rxstatus_t *) dataptr; if ((status.rxs_status & 0x200000) == 0) { datalen = status.rxs_status & 0x1FFF; fc = dataptr[PDQ_RX_FC_OFFSET]; switch (fc & (PDQ_FDDIFC_C|PDQ_FDDIFC_L|PDQ_FDDIFC_F)) { case PDQ_FDDI_LLC_ASYNC: case PDQ_FDDI_LLC_SYNC: case PDQ_FDDI_IMP_ASYNC: case PDQ_FDDI_IMP_SYNC: { if (datalen > PDQ_FDDI_MAX || datalen < PDQ_FDDI_LLC_MIN) { PDQ_PRINTF(("discard: bad length %d\n", datalen)); goto discard_frame; } break; } case PDQ_FDDI_SMT: { if (datalen > PDQ_FDDI_MAX || datalen < PDQ_FDDI_SMT_MIN) goto discard_frame; break; } default: { PDQ_PRINTF(("discard: bad fc 0x%x\n", fc)); goto discard_frame; } } /* * Update the lengths of the data buffers now that we know * the real length. */ pdulen = datalen - 4 /* CRC */; segcnt = (pdulen + PDQ_RX_FC_OFFSET + PDQ_OS_DATABUF_SIZE - 1) / PDQ_OS_DATABUF_SIZE; PDQ_OS_DATABUF_ALLOC(npdu); if (npdu == NULL) { PDQ_PRINTF(("discard: no databuf #0\n")); goto discard_frame; } buffers[completion] = npdu; for (idx = 1; idx < segcnt; idx++) { PDQ_OS_DATABUF_ALLOC(npdu); if (npdu == NULL) { PDQ_OS_DATABUF_NEXT_SET(lpdu, NULL); PDQ_OS_DATABUF_FREE(fpdu); goto discard_frame; } PDQ_OS_DATABUF_NEXT_SET(lpdu, buffers[(completion + idx) & ring_mask]); lpdu = PDQ_OS_DATABUF_NEXT(lpdu); buffers[(completion + idx) & ring_mask] = npdu; } PDQ_OS_DATABUF_NEXT_SET(lpdu, NULL); for (idx = 0; idx < PDQ_RX_SEGCNT; idx++) { buffers[(producer + idx) & ring_mask] = buffers[(completion + idx) & ring_mask]; buffers[(completion + idx) & ring_mask] = NULL; } PDQ_OS_DATABUF_ADJ(fpdu, PDQ_RX_FC_OFFSET); if (segcnt == 1) { PDQ_OS_DATABUF_LEN_SET(fpdu, pdulen); } else { PDQ_OS_DATABUF_LEN_SET(lpdu, pdulen + PDQ_RX_FC_OFFSET - (segcnt - 1) * PDQ_OS_DATABUF_SIZE); } pdq_os_receive_pdu(pdq, fpdu, pdulen); rx->rx_free += PDQ_RX_SEGCNT; PDQ_ADVANCE(producer, PDQ_RX_SEGCNT, ring_mask); PDQ_ADVANCE(completion, PDQ_RX_SEGCNT, ring_mask); continue; } else { PDQ_PRINTF(("discard: bad pdu 0x%x(%d.%d.%d.%d.%d)\n", status.rxs_status, status.rxs_rcc_badpdu, status.rxs_rcc_badcrc, status.rxs_rcc_reason, status.rxs_fsc, status.rxs_fsb_e)); if (status.rxs_rcc_reason == 7) goto discard_frame; if (status.rxs_rcc_reason != 0) { /* hardware fault */ } if (status.rxs_rcc_badcrc) { printf(PDQ_OS_PREFIX " MAC CRC error (source=%x-%x-%x-%x-%x-%x)\n", PDQ_OS_PREFIX_ARGS, dataptr[PDQ_RX_FC_OFFSET+1], dataptr[PDQ_RX_FC_OFFSET+2], dataptr[PDQ_RX_FC_OFFSET+3], dataptr[PDQ_RX_FC_OFFSET+4], dataptr[PDQ_RX_FC_OFFSET+5], dataptr[PDQ_RX_FC_OFFSET+6]); /* rx->rx_badcrc++; */ } else if (status.rxs_fsc == 0 || status.rxs_fsb_e == 1) { /* rx->rx_frame_status_errors++; */ } else { /* hardware fault */ } } discard_frame: /* * Discarded frames go right back on the queue; therefore * ring entries were freed. */ for (idx = 0; idx < PDQ_RX_SEGCNT; idx++) { buffers[producer] = buffers[completion]; buffers[completion] = NULL; rxd = &receives[rx->rx_producer]; if (idx == 0) { rxd->rxd_sop = 1; rxd->rxd_seg_cnt = PDQ_RX_SEGCNT - 1; } else { rxd->rxd_sop = 0; rxd->rxd_seg_cnt = 0; } rxd->rxd_pa_hi = 0; rxd->rxd_seg_len_hi = PDQ_OS_DATABUF_SIZE / 16; rxd->rxd_pa_lo = PDQ_OS_VA_TO_PA(pdq, PDQ_OS_DATABUF_PTR(buffers[rx->rx_producer])); PDQ_ADVANCE(rx->rx_producer, 1, ring_mask); PDQ_ADVANCE(producer, 1, ring_mask); PDQ_ADVANCE(completion, 1, ring_mask); } } rx->rx_completion = completion; while (rx->rx_free > PDQ_RX_SEGCNT && rx->rx_free > rx->rx_target) { PDQ_OS_DATABUF_T *pdu; /* * Allocate the needed number of data buffers. * Try to obtain them from our free queue before * asking the system for more. */ for (idx = 0; idx < PDQ_RX_SEGCNT; idx++) { if ((pdu = buffers[(rx->rx_producer + idx) & ring_mask]) == NULL) { PDQ_OS_DATABUF_ALLOC(pdu); if (pdu == NULL) break; buffers[(rx->rx_producer + idx) & ring_mask] = pdu; } rxd = &receives[(rx->rx_producer + idx) & ring_mask]; if (idx == 0) { rxd->rxd_sop = 1; rxd->rxd_seg_cnt = PDQ_RX_SEGCNT - 1; } else { rxd->rxd_sop = 0; rxd->rxd_seg_cnt = 0; } rxd->rxd_pa_hi = 0; rxd->rxd_seg_len_hi = PDQ_OS_DATABUF_SIZE / 16; rxd->rxd_pa_lo = PDQ_OS_VA_TO_PA(pdq, PDQ_OS_DATABUF_PTR(pdu)); } if (idx < PDQ_RX_SEGCNT) { /* * We didn't get all databufs required to complete a new * receive buffer. Keep the ones we got and retry a bit * later for the rest. */ break; } PDQ_ADVANCE(rx->rx_producer, PDQ_RX_SEGCNT, ring_mask); rx->rx_free -= PDQ_RX_SEGCNT; } } pdq_boolean_t pdq_queue_transmit_data( pdq_t *pdq, PDQ_OS_DATABUF_T *pdu) { pdq_tx_info_t *tx = &pdq->pdq_tx_info; pdq_descriptor_block_t *dbp = pdq->pdq_dbp; pdq_uint32_t producer = tx->tx_producer; pdq_txdesc_t *eop = NULL; PDQ_OS_DATABUF_T *pdu0; pdq_uint32_t freecnt; if (tx->tx_free < 1) return PDQ_FALSE; dbp->pdqdb_transmits[producer] = tx->tx_hdrdesc; PDQ_ADVANCE(producer, 1, PDQ_RING_MASK(dbp->pdqdb_transmits)); for (freecnt = tx->tx_free - 1, pdu0 = pdu; pdu0 != NULL && freecnt > 0;) { pdq_uint32_t fraglen, datalen = PDQ_OS_DATABUF_LEN(pdu0); const pdq_uint8_t *dataptr = PDQ_OS_DATABUF_PTR(pdu0); /* * The first segment is limited to the space remaining in * page. All segments after that can be up to a full page * in size. */ fraglen = PDQ_OS_PAGESIZE - ((dataptr - (pdq_uint8_t *) NULL) & (PDQ_OS_PAGESIZE-1)); while (datalen > 0 && freecnt > 0) { pdq_uint32_t seglen = (fraglen < datalen ? fraglen : datalen); /* * Initialize the transmit descriptor */ eop = &dbp->pdqdb_transmits[producer]; eop->txd_seg_len = seglen; eop->txd_pa_lo = PDQ_OS_VA_TO_PA(pdq, dataptr); eop->txd_sop = eop->txd_eop = eop->txd_pa_hi = 0; datalen -= seglen; dataptr += seglen; fraglen = PDQ_OS_PAGESIZE; freecnt--; PDQ_ADVANCE(producer, 1, PDQ_RING_MASK(dbp->pdqdb_transmits)); } pdu0 = PDQ_OS_DATABUF_NEXT(pdu0); } if (pdu0 != NULL) { PDQ_ASSERT(freecnt == 0); /* * If we still have data to process then the ring was too full * to store the PDU. Return FALSE so the caller will requeue * the PDU for later. */ return PDQ_FALSE; } /* * Everything went fine. Finish it up. */ tx->tx_descriptor_count[tx->tx_producer] = tx->tx_free - freecnt; eop->txd_eop = 1; PDQ_OS_DATABUF_ENQUEUE(&tx->tx_txq, pdu); tx->tx_producer = producer; tx->tx_free = freecnt; PDQ_DO_TYPE2_PRODUCER(pdq); return PDQ_TRUE; } static void pdq_process_transmitted_data( pdq_t *pdq) { pdq_tx_info_t *tx = &pdq->pdq_tx_info; volatile const pdq_consumer_block_t *cbp = pdq->pdq_cbp; pdq_descriptor_block_t *dbp = pdq->pdq_dbp; pdq_uint32_t completion = tx->tx_completion; while (completion != cbp->pdqcb_transmits) { PDQ_OS_DATABUF_T *pdu; pdq_uint32_t descriptor_count = tx->tx_descriptor_count[completion]; PDQ_ASSERT(dbp->pdqdb_transmits[completion].txd_sop == 1); PDQ_ASSERT(dbp->pdqdb_transmits[(completion + descriptor_count - 1) & PDQ_RING_MASK(dbp->pdqdb_transmits)].txd_eop == 1); PDQ_OS_DATABUF_DEQUEUE(&tx->tx_txq, pdu); pdq_os_transmit_done(pdq, pdu); tx->tx_free += descriptor_count; PDQ_ADVANCE(completion, descriptor_count, PDQ_RING_MASK(dbp->pdqdb_transmits)); } if (tx->tx_completion != completion) { tx->tx_completion = completion; pdq_os_restart_transmitter(pdq); } PDQ_DO_TYPE2_PRODUCER(pdq); } void pdq_flush_transmitter( pdq_t *pdq) { volatile pdq_consumer_block_t *cbp = pdq->pdq_cbp; pdq_tx_info_t *tx = &pdq->pdq_tx_info; for (;;) { PDQ_OS_DATABUF_T *pdu; PDQ_OS_DATABUF_DEQUEUE(&tx->tx_txq, pdu); if (pdu == NULL) break; /* * Don't call transmit done since the packet never made it * out on the wire. */ PDQ_OS_DATABUF_FREE(pdu); } tx->tx_free = PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_transmits); tx->tx_completion = cbp->pdqcb_transmits = tx->tx_producer; PDQ_DO_TYPE2_PRODUCER(pdq); } void pdq_hwreset( pdq_t *pdq) { const pdq_csrs_t * const csrs = &pdq->pdq_csrs; pdq_state_t state; int cnt; state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); if (state == PDQS_DMA_UNAVAILABLE) return; PDQ_CSR_WRITE(csrs, csr_port_data_a, (state == PDQS_HALTED) ? 0 : PDQ_PRESET_SKIP_SELFTEST); PDQ_CSR_WRITE(csrs, csr_port_reset, 1); PDQ_OS_USEC_DELAY(100); PDQ_CSR_WRITE(csrs, csr_port_reset, 0); for (cnt = 45000;;cnt--) { PDQ_OS_USEC_DELAY(1000); state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); if (state == PDQS_DMA_UNAVAILABLE || cnt == 0) break; } PDQ_PRINTF(("PDQ Reset spun %d cycles\n", 45000 - cnt)); PDQ_OS_USEC_DELAY(10000); state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); PDQ_ASSERT(state == PDQS_DMA_UNAVAILABLE); PDQ_ASSERT(cnt > 0); } /* * The following routine brings the PDQ from whatever state it is * in to DMA_UNAVAILABLE (ie. like a RESET but without doing a RESET). */ pdq_state_t pdq_stop( pdq_t *pdq) { pdq_state_t state; const pdq_csrs_t * const csrs = &pdq->pdq_csrs; int cnt, pass = 0, idx; PDQ_OS_DATABUF_T **buffers; restart: state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); if (state != PDQS_DMA_UNAVAILABLE) { pdq_hwreset(pdq); state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); PDQ_ASSERT(state == PDQS_DMA_UNAVAILABLE); } #if 0 switch (state) { case PDQS_RING_MEMBER: case PDQS_LINK_UNAVAILABLE: case PDQS_LINK_AVAILABLE: { PDQ_CSR_WRITE(csrs, csr_port_data_a, PDQ_SUB_CMD_LINK_UNINIT); PDQ_CSR_WRITE(csrs, csr_port_data_b, 0); pdq_do_port_control(csrs, PDQ_PCTL_SUB_CMD); state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); PDQ_ASSERT(state == PDQS_DMA_AVAILABLE); /* FALLTHROUGH */ } case PDQS_DMA_AVAILABLE: { PDQ_CSR_WRITE(csrs, csr_port_data_a, 0); PDQ_CSR_WRITE(csrs, csr_port_data_b, 0); pdq_do_port_control(csrs, PDQ_PCTL_DMA_UNINIT); state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); PDQ_ASSERT(state == PDQS_DMA_UNAVAILABLE); /* FALLTHROUGH */ } case PDQS_DMA_UNAVAILABLE: { break; } } #endif /* * Now we should be in DMA_UNAVAILABLE. So bring the PDQ into * DMA_AVAILABLE. */ /* * Obtain the hardware address and firmware revisions * (MLA = my long address which is FDDI speak for hardware address) */ pdq_read_mla(&pdq->pdq_csrs, &pdq->pdq_hwaddr); pdq_read_fwrev(&pdq->pdq_csrs, &pdq->pdq_fwrev); pdq->pdq_chip_rev = pdq_read_chiprev(&pdq->pdq_csrs); if (pdq->pdq_type == PDQ_DEFPA) { /* * Disable interrupts and DMA. */ PDQ_CSR_WRITE(&pdq->pdq_pci_csrs, csr_pfi_mode_control, 0); PDQ_CSR_WRITE(&pdq->pdq_pci_csrs, csr_pfi_status, 0x10); } /* * Flush all the databuf queues. */ pdq_flush_databuf_queue(&pdq->pdq_tx_info.tx_txq); pdq->pdq_flags &= ~PDQ_TXOK; buffers = (PDQ_OS_DATABUF_T **) pdq->pdq_rx_info.rx_buffers; for (idx = 0; idx < PDQ_RING_SIZE(pdq->pdq_dbp->pdqdb_receives); idx++) { if (buffers[idx] != NULL) { PDQ_OS_DATABUF_FREE(buffers[idx]); buffers[idx] = NULL; } } pdq->pdq_rx_info.rx_free = PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_receives); buffers = (PDQ_OS_DATABUF_T **) pdq->pdq_host_smt_info.rx_buffers; for (idx = 0; idx < PDQ_RING_SIZE(pdq->pdq_dbp->pdqdb_host_smt); idx++) { if (buffers[idx] != NULL) { PDQ_OS_DATABUF_FREE(buffers[idx]); buffers[idx] = NULL; } } pdq->pdq_host_smt_info.rx_free = PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_host_smt); /* * Reset the consumer indexes to 0. */ pdq->pdq_cbp->pdqcb_receives = 0; pdq->pdq_cbp->pdqcb_transmits = 0; pdq->pdq_cbp->pdqcb_host_smt = 0; pdq->pdq_cbp->pdqcb_unsolicited_event = 0; pdq->pdq_cbp->pdqcb_command_response = 0; pdq->pdq_cbp->pdqcb_command_request = 0; /* * Reset the producer and completion indexes to 0. */ pdq->pdq_command_info.ci_request_producer = 0; pdq->pdq_command_info.ci_response_producer = 0; pdq->pdq_command_info.ci_request_completion = 0; pdq->pdq_command_info.ci_response_completion = 0; pdq->pdq_unsolicited_info.ui_producer = 0; pdq->pdq_unsolicited_info.ui_completion = 0; pdq->pdq_rx_info.rx_producer = 0; pdq->pdq_rx_info.rx_completion = 0; pdq->pdq_tx_info.tx_producer = 0; pdq->pdq_tx_info.tx_completion = 0; pdq->pdq_host_smt_info.rx_producer = 0; pdq->pdq_host_smt_info.rx_completion = 0; pdq->pdq_command_info.ci_command_active = 0; pdq->pdq_unsolicited_info.ui_free = PDQ_NUM_UNSOLICITED_EVENTS; pdq->pdq_tx_info.tx_free = PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_transmits); /* * Allow the DEFPA to do DMA. Then program the physical * addresses of the consumer and descriptor blocks. */ if (pdq->pdq_type == PDQ_DEFPA) { #ifdef PDQTEST PDQ_CSR_WRITE(&pdq->pdq_pci_csrs, csr_pfi_mode_control, PDQ_PFI_MODE_DMA_ENABLE); #else PDQ_CSR_WRITE(&pdq->pdq_pci_csrs, csr_pfi_mode_control, PDQ_PFI_MODE_DMA_ENABLE /*|PDQ_PFI_MODE_PFI_PCI_INTR*/|PDQ_PFI_MODE_PDQ_PCI_INTR); #endif } /* * Make sure the unsolicited queue has events ... */ pdq_process_unsolicited_events(pdq); if (pdq->pdq_type == PDQ_DEFEA && pdq->pdq_chip_rev == PDQ_CHIP_REV_E) PDQ_CSR_WRITE(csrs, csr_port_data_b, PDQ_DMA_BURST_16LW); else PDQ_CSR_WRITE(csrs, csr_port_data_b, PDQ_DMA_BURST_8LW); PDQ_CSR_WRITE(csrs, csr_port_data_a, PDQ_SUB_CMD_DMA_BURST_SIZE_SET); pdq_do_port_control(csrs, PDQ_PCTL_SUB_CMD); PDQ_CSR_WRITE(csrs, csr_port_data_b, 0); PDQ_CSR_WRITE(csrs, csr_port_data_a, PDQ_OS_VA_TO_PA(pdq, pdq->pdq_cbp)); pdq_do_port_control(csrs, PDQ_PCTL_CONSUMER_BLOCK); PDQ_CSR_WRITE(csrs, csr_port_data_b, 0); PDQ_CSR_WRITE(csrs, csr_port_data_a, PDQ_OS_VA_TO_PA(pdq, pdq->pdq_dbp) | PDQ_DMA_INIT_LW_BSWAP_DATA); pdq_do_port_control(csrs, PDQ_PCTL_DMA_INIT); for (cnt = 0; cnt < 1000; cnt++) { state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); if (state == PDQS_HALTED) { if (pass > 0) return PDQS_HALTED; pass = 1; goto restart; } if (state == PDQS_DMA_AVAILABLE) { PDQ_PRINTF(("Transition to DMA Available took %d spins\n", cnt)); break; } PDQ_OS_USEC_DELAY(1000); } PDQ_ASSERT(state == PDQS_DMA_AVAILABLE); PDQ_CSR_WRITE(csrs, csr_host_int_type_0, 0xFF); PDQ_CSR_WRITE(csrs, csr_host_int_enable, 0) /* PDQ_HOST_INT_STATE_CHANGE |PDQ_HOST_INT_FATAL_ERROR|PDQ_HOST_INT_CMD_RSP_ENABLE |PDQ_HOST_INT_UNSOL_ENABLE */; /* * Any other command but START should be valid. */ pdq->pdq_command_info.ci_pending_commands &= ~(PDQ_BITMASK(PDQC_START)); if (pdq->pdq_flags & PDQ_PRINTCHARS) pdq->pdq_command_info.ci_pending_commands |= PDQ_BITMASK(PDQC_STATUS_CHARS_GET); pdq_queue_commands(pdq); if (pdq->pdq_flags & PDQ_PRINTCHARS) { /* * Now wait (up to 100ms) for the command(s) to finish. */ for (cnt = 0; cnt < 1000; cnt++) { pdq_process_command_responses(pdq); if (pdq->pdq_command_info.ci_response_producer == pdq->pdq_command_info.ci_response_completion) break; PDQ_OS_USEC_DELAY(1000); } state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); } return state; } void pdq_run( pdq_t *pdq) { const pdq_csrs_t * const csrs = &pdq->pdq_csrs; pdq_state_t state; state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); PDQ_ASSERT(state != PDQS_DMA_UNAVAILABLE); PDQ_ASSERT(state != PDQS_RESET); PDQ_ASSERT(state != PDQS_HALTED); PDQ_ASSERT(state != PDQS_UPGRADE); PDQ_ASSERT(state != PDQS_RING_MEMBER); switch (state) { case PDQS_DMA_AVAILABLE: { /* * The PDQ after being reset screws up some of its state. * So we need to clear all the errors/interrupts so the real * ones will get through. */ PDQ_CSR_WRITE(csrs, csr_host_int_type_0, 0xFF); PDQ_CSR_WRITE(csrs, csr_host_int_enable, PDQ_HOST_INT_STATE_CHANGE|PDQ_HOST_INT_XMT_DATA_FLUSH |PDQ_HOST_INT_FATAL_ERROR|PDQ_HOST_INT_CMD_RSP_ENABLE|PDQ_HOST_INT_UNSOL_ENABLE |PDQ_HOST_INT_RX_ENABLE|PDQ_HOST_INT_TX_ENABLE|PDQ_HOST_INT_HOST_SMT_ENABLE); /* * Set the MAC and address filters and start up the PDQ. */ pdq_process_unsolicited_events(pdq); pdq_process_received_data(pdq, &pdq->pdq_rx_info, pdq->pdq_dbp->pdqdb_receives, pdq->pdq_cbp->pdqcb_receives, PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_receives)); PDQ_DO_TYPE2_PRODUCER(pdq); if (pdq->pdq_flags & PDQ_PASS_SMT) { pdq_process_received_data(pdq, &pdq->pdq_host_smt_info, pdq->pdq_dbp->pdqdb_host_smt, pdq->pdq_cbp->pdqcb_host_smt, PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_host_smt)); PDQ_CSR_WRITE(csrs, csr_host_smt_producer, pdq->pdq_host_smt_info.rx_producer | (pdq->pdq_host_smt_info.rx_completion << 8)); } pdq->pdq_command_info.ci_pending_commands = PDQ_BITMASK(PDQC_FILTER_SET) | PDQ_BITMASK(PDQC_ADDR_FILTER_SET) | PDQ_BITMASK(PDQC_START); if (pdq->pdq_flags & PDQ_PRINTCHARS) pdq->pdq_command_info.ci_pending_commands |= PDQ_BITMASK(PDQC_STATUS_CHARS_GET); pdq_queue_commands(pdq); break; } case PDQS_LINK_UNAVAILABLE: case PDQS_LINK_AVAILABLE: { pdq->pdq_command_info.ci_pending_commands = PDQ_BITMASK(PDQC_FILTER_SET) | PDQ_BITMASK(PDQC_ADDR_FILTER_SET); if (pdq->pdq_flags & PDQ_PRINTCHARS) pdq->pdq_command_info.ci_pending_commands |= PDQ_BITMASK(PDQC_STATUS_CHARS_GET); if (pdq->pdq_flags & PDQ_PASS_SMT) { pdq_process_received_data(pdq, &pdq->pdq_host_smt_info, pdq->pdq_dbp->pdqdb_host_smt, pdq->pdq_cbp->pdqcb_host_smt, PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_host_smt)); PDQ_CSR_WRITE(csrs, csr_host_smt_producer, pdq->pdq_host_smt_info.rx_producer | (pdq->pdq_host_smt_info.rx_completion << 8)); } pdq_process_unsolicited_events(pdq); pdq_queue_commands(pdq); break; } case PDQS_RING_MEMBER: { } default: break; } } int pdq_interrupt( pdq_t *pdq) { const pdq_csrs_t * const csrs = &pdq->pdq_csrs; pdq_uint32_t data; int progress = 0; if (pdq->pdq_type == PDQ_DEFPA) PDQ_CSR_WRITE(&pdq->pdq_pci_csrs, csr_pfi_status, 0x18); while ((data = PDQ_CSR_READ(csrs, csr_port_status)) & PDQ_PSTS_INTR_PENDING) { progress = 1; PDQ_PRINTF(("PDQ Interrupt: Status = 0x%08x\n", data)); if (data & PDQ_PSTS_RCV_DATA_PENDING) { pdq_process_received_data(pdq, &pdq->pdq_rx_info, pdq->pdq_dbp->pdqdb_receives, pdq->pdq_cbp->pdqcb_receives, PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_receives)); PDQ_DO_TYPE2_PRODUCER(pdq); } if (data & PDQ_PSTS_HOST_SMT_PENDING) { pdq_process_received_data(pdq, &pdq->pdq_host_smt_info, pdq->pdq_dbp->pdqdb_host_smt, pdq->pdq_cbp->pdqcb_host_smt, PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_host_smt)); PDQ_DO_HOST_SMT_PRODUCER(pdq); } if (data & PDQ_PSTS_XMT_DATA_PENDING) pdq_process_transmitted_data(pdq); if (data & PDQ_PSTS_UNSOL_PENDING) pdq_process_unsolicited_events(pdq); if (data & PDQ_PSTS_CMD_RSP_PENDING) pdq_process_command_responses(pdq); if (data & PDQ_PSTS_TYPE_0_PENDING) { data = PDQ_CSR_READ(csrs, csr_host_int_type_0); if (data & PDQ_HOST_INT_STATE_CHANGE) { pdq_state_t state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(csrs, csr_port_status)); printf(PDQ_OS_PREFIX "%s", PDQ_OS_PREFIX_ARGS, pdq_adapter_states[state]); if (state == PDQS_LINK_UNAVAILABLE) { pdq->pdq_flags &= ~PDQ_TXOK; } else if (state == PDQS_LINK_AVAILABLE) { pdq->pdq_flags |= PDQ_TXOK; pdq_os_restart_transmitter(pdq); } else if (state == PDQS_HALTED) { pdq_response_error_log_get_t log_entry; pdq_halt_code_t halt_code = PDQ_PSTS_HALT_ID(PDQ_CSR_READ(csrs, csr_port_status)); printf(": halt code = %d (%s)\n", halt_code, pdq_halt_codes[halt_code]); if (halt_code == PDQH_DMA_ERROR && pdq->pdq_type == PDQ_DEFPA) { PDQ_PRINTF(("\tPFI status = 0x%x, Host 0 Fatal Interrupt = 0x%x\n", PDQ_CSR_READ(&pdq->pdq_pci_csrs, csr_pfi_status), data & PDQ_HOST_INT_FATAL_ERROR)); } pdq_read_error_log(pdq, &log_entry); pdq_stop(pdq); if (pdq->pdq_flags & PDQ_RUNNING) pdq_run(pdq); return 1; } printf("\n"); PDQ_CSR_WRITE(csrs, csr_host_int_type_0, PDQ_HOST_INT_STATE_CHANGE); } if (data & PDQ_HOST_INT_FATAL_ERROR) { pdq_stop(pdq); if (pdq->pdq_flags & PDQ_RUNNING) pdq_run(pdq); return 1; } if (data & PDQ_HOST_INT_XMT_DATA_FLUSH) { printf(PDQ_OS_PREFIX "Flushing transmit queue\n", PDQ_OS_PREFIX_ARGS); pdq->pdq_flags &= ~PDQ_TXOK; pdq_flush_transmitter(pdq); pdq_do_port_control(csrs, PDQ_PCTL_XMT_DATA_FLUSH_DONE); PDQ_CSR_WRITE(csrs, csr_host_int_type_0, PDQ_HOST_INT_XMT_DATA_FLUSH); } } if (pdq->pdq_type == PDQ_DEFPA) PDQ_CSR_WRITE(&pdq->pdq_pci_csrs, csr_pfi_status, 0x18); } return progress; } pdq_t * pdq_initialize( pdq_bus_t bus, pdq_bus_memaddr_t csr_base, const char *name, int unit, void *ctx, pdq_type_t type) { pdq_t *pdq; pdq_state_t state; const pdq_uint32_t contig_bytes = (sizeof(pdq_descriptor_block_t) * 2) - PDQ_OS_PAGESIZE; pdq_uint8_t *p; int idx; PDQ_ASSERT(sizeof(pdq_descriptor_block_t) == 8192); PDQ_ASSERT(sizeof(pdq_consumer_block_t) == 64); PDQ_ASSERT(sizeof(pdq_response_filter_get_t) == PDQ_SIZE_RESPONSE_FILTER_GET); PDQ_ASSERT(sizeof(pdq_cmd_addr_filter_set_t) == PDQ_SIZE_CMD_ADDR_FILTER_SET); PDQ_ASSERT(sizeof(pdq_response_addr_filter_get_t) == PDQ_SIZE_RESPONSE_ADDR_FILTER_GET); PDQ_ASSERT(sizeof(pdq_response_status_chars_get_t) == PDQ_SIZE_RESPONSE_STATUS_CHARS_GET); PDQ_ASSERT(sizeof(pdq_response_fddi_mib_get_t) == PDQ_SIZE_RESPONSE_FDDI_MIB_GET); PDQ_ASSERT(sizeof(pdq_response_dec_ext_mib_get_t) == PDQ_SIZE_RESPONSE_DEC_EXT_MIB_GET); PDQ_ASSERT(sizeof(pdq_unsolicited_event_t) == 512); pdq = (pdq_t *) PDQ_OS_MEMALLOC(sizeof(pdq_t)); if (pdq == NULL) { PDQ_PRINTF(("malloc(%d) failed\n", sizeof(*pdq))); return NULL; } PDQ_OS_MEMZERO(pdq, sizeof(pdq_t)); pdq->pdq_type = type; pdq->pdq_unit = unit; pdq->pdq_os_ctx = (void *) ctx; pdq->pdq_os_name = name; pdq->pdq_flags = PDQ_PRINTCHARS; /* * Allocate the additional data structures required by * the PDQ driver. Allocate a contiguous region of memory * for the descriptor block. We need to allocated enough * to guarantee that we will a get 8KB block of memory aligned * on a 8KB boundary. This turns to require that we allocate * (N*2 - 1 page) pages of memory. On machine with less than * a 8KB page size, it mean we will allocate more memory than * we need. The extra will be used for the unsolicited event * buffers (though on machines with 8KB pages we will to allocate * them separately since there will be nothing left overs.) */ p = (pdq_uint8_t *) PDQ_OS_MEMALLOC_CONTIG(contig_bytes); if (p != NULL) { pdq_physaddr_t physaddr = PDQ_OS_VA_TO_PA(pdq, p); /* * Assert that we really got contiguous memory. This isn't really * needed on systems that actually have physical contiguous allocation * routines, but on those systems that don't ... */ for (idx = PDQ_OS_PAGESIZE; idx < 0x2000; idx += PDQ_OS_PAGESIZE) { if (PDQ_OS_VA_TO_PA(pdq, p + idx) - physaddr != idx) goto cleanup_and_return; } physaddr &= 0x1FFF; if (physaddr) { pdq->pdq_unsolicited_info.ui_events = (pdq_unsolicited_event_t *) p; pdq->pdq_dbp = (pdq_descriptor_block_t *) &p[0x2000 - physaddr]; } else { pdq->pdq_dbp = (pdq_descriptor_block_t *) p; pdq->pdq_unsolicited_info.ui_events = (pdq_unsolicited_event_t *) &p[0x2000]; } } if (contig_bytes == sizeof(pdq_descriptor_block_t)) { pdq->pdq_unsolicited_info.ui_events = (pdq_unsolicited_event_t *) PDQ_OS_MEMALLOC( PDQ_NUM_UNSOLICITED_EVENTS * sizeof(pdq_unsolicited_event_t)); } /* * Make sure everything got allocated. If not, free what did * get allocated and return. */ if (pdq->pdq_dbp == NULL || pdq->pdq_unsolicited_info.ui_events == NULL) { cleanup_and_return: if (p /* pdq->pdq_dbp */ != NULL) PDQ_OS_MEMFREE_CONTIG(p /* pdq->pdq_dbp */, contig_bytes); if (contig_bytes == sizeof(pdq_descriptor_block_t) && pdq->pdq_unsolicited_info.ui_events != NULL) PDQ_OS_MEMFREE(pdq->pdq_unsolicited_info.ui_events, PDQ_NUM_UNSOLICITED_EVENTS * sizeof(pdq_unsolicited_event_t)); PDQ_OS_MEMFREE(pdq, sizeof(pdq_t)); return NULL; } pdq->pdq_cbp = (volatile pdq_consumer_block_t *) &pdq->pdq_dbp->pdqdb_consumer; pdq->pdq_command_info.ci_bufstart = (pdq_uint8_t *) pdq->pdq_dbp->pdqdb_command_pool; pdq->pdq_rx_info.rx_buffers = (void *) pdq->pdq_dbp->pdqdb_receive_buffers; pdq->pdq_host_smt_info.rx_buffers = (void *) pdq->pdq_dbp->pdqdb_host_smt_buffers; PDQ_PRINTF(("\nPDQ Descriptor Block = " PDQ_OS_PTR_FMT "\n", pdq->pdq_dbp)); PDQ_PRINTF((" Receive Queue = " PDQ_OS_PTR_FMT "\n", pdq->pdq_dbp->pdqdb_receives)); PDQ_PRINTF((" Transmit Queue = " PDQ_OS_PTR_FMT "\n", pdq->pdq_dbp->pdqdb_transmits)); PDQ_PRINTF((" Host SMT Queue = " PDQ_OS_PTR_FMT "\n", pdq->pdq_dbp->pdqdb_host_smt)); PDQ_PRINTF((" Command Response Queue = " PDQ_OS_PTR_FMT "\n", pdq->pdq_dbp->pdqdb_command_responses)); PDQ_PRINTF((" Command Request Queue = " PDQ_OS_PTR_FMT "\n", pdq->pdq_dbp->pdqdb_command_requests)); PDQ_PRINTF(("PDQ Consumer Block = " PDQ_OS_PTR_FMT "\n", pdq->pdq_cbp)); /* * Zero out the descriptor block. Not really required but * it pays to be neat. This will also zero out the consumer * block, command pool, and buffer pointers for the receive * host_smt rings. */ PDQ_OS_MEMZERO(pdq->pdq_dbp, sizeof(*pdq->pdq_dbp)); /* * Initialize the CSR references. * the DEFAA (FutureBus+) skips a longword between registers */ pdq_init_csrs(&pdq->pdq_csrs, bus, csr_base, pdq->pdq_type == PDQ_DEFAA ? 2 : 1); if (pdq->pdq_type == PDQ_DEFPA) pdq_init_pci_csrs(&pdq->pdq_pci_csrs, bus, csr_base, 1); PDQ_PRINTF(("PDQ CSRs: BASE = " PDQ_OS_PTR_FMT "\n", pdq->pdq_csrs.csr_base)); PDQ_PRINTF((" Port Reset = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_port_reset, PDQ_CSR_READ(&pdq->pdq_csrs, csr_port_reset))); PDQ_PRINTF((" Host Data = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_host_data, PDQ_CSR_READ(&pdq->pdq_csrs, csr_host_data))); PDQ_PRINTF((" Port Control = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_port_control, PDQ_CSR_READ(&pdq->pdq_csrs, csr_port_control))); PDQ_PRINTF((" Port Data A = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_port_data_a, PDQ_CSR_READ(&pdq->pdq_csrs, csr_port_data_a))); PDQ_PRINTF((" Port Data B = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_port_data_b, PDQ_CSR_READ(&pdq->pdq_csrs, csr_port_data_b))); PDQ_PRINTF((" Port Status = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_port_status, PDQ_CSR_READ(&pdq->pdq_csrs, csr_port_status))); PDQ_PRINTF((" Host Int Type 0 = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_host_int_type_0, PDQ_CSR_READ(&pdq->pdq_csrs, csr_host_int_type_0))); PDQ_PRINTF((" Host Int Enable = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_host_int_enable, PDQ_CSR_READ(&pdq->pdq_csrs, csr_host_int_enable))); PDQ_PRINTF((" Type 2 Producer = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_type_2_producer, PDQ_CSR_READ(&pdq->pdq_csrs, csr_type_2_producer))); PDQ_PRINTF((" Command Response Producer = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_cmd_response_producer, PDQ_CSR_READ(&pdq->pdq_csrs, csr_cmd_response_producer))); PDQ_PRINTF((" Command Request Producer = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_cmd_request_producer, PDQ_CSR_READ(&pdq->pdq_csrs, csr_cmd_request_producer))); PDQ_PRINTF((" Host SMT Producer = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_host_smt_producer, PDQ_CSR_READ(&pdq->pdq_csrs, csr_host_smt_producer))); PDQ_PRINTF((" Unsolicited Producer = " PDQ_OS_PTR_FMT " [0x%08x]\n", pdq->pdq_csrs.csr_unsolicited_producer, PDQ_CSR_READ(&pdq->pdq_csrs, csr_unsolicited_producer))); /* * Initialize the command information block */ pdq->pdq_command_info.ci_pa_bufstart = PDQ_OS_VA_TO_PA(pdq, pdq->pdq_command_info.ci_bufstart); for (idx = 0; idx < nitems(pdq->pdq_dbp->pdqdb_command_requests); idx++) { pdq_txdesc_t *txd = &pdq->pdq_dbp->pdqdb_command_requests[idx]; txd->txd_pa_lo = pdq->pdq_command_info.ci_pa_bufstart; txd->txd_eop = txd->txd_sop = 1; txd->txd_pa_hi = 0; } for (idx = 0; idx < nitems(pdq->pdq_dbp->pdqdb_command_responses); idx++) { pdq_rxdesc_t *rxd = &pdq->pdq_dbp->pdqdb_command_responses[idx]; rxd->rxd_pa_lo = pdq->pdq_command_info.ci_pa_bufstart; rxd->rxd_sop = 1; rxd->rxd_seg_cnt = 0; rxd->rxd_seg_len_lo = 0; } /* * Initialize the unsolicited event information block */ pdq->pdq_unsolicited_info.ui_free = PDQ_NUM_UNSOLICITED_EVENTS; pdq->pdq_unsolicited_info.ui_pa_bufstart = PDQ_OS_VA_TO_PA(pdq, pdq->pdq_unsolicited_info.ui_events); for (idx = 0; idx < nitems(pdq->pdq_dbp->pdqdb_unsolicited_events); idx++) { pdq_rxdesc_t *rxd = &pdq->pdq_dbp->pdqdb_unsolicited_events[idx]; pdq_unsolicited_event_t *event = &pdq->pdq_unsolicited_info.ui_events[idx & (PDQ_NUM_UNSOLICITED_EVENTS-1)]; rxd->rxd_sop = 1; rxd->rxd_seg_cnt = 0; rxd->rxd_seg_len_hi = sizeof(pdq_unsolicited_event_t) / 16; rxd->rxd_pa_lo = pdq->pdq_unsolicited_info.ui_pa_bufstart + (const pdq_uint8_t *) event - (const pdq_uint8_t *) pdq->pdq_unsolicited_info.ui_events; rxd->rxd_pa_hi = 0; } /* * Initialize the receive information blocks (normal and SMT). */ pdq->pdq_rx_info.rx_free = PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_receives); pdq->pdq_rx_info.rx_target = pdq->pdq_rx_info.rx_free - PDQ_RX_SEGCNT * 8; pdq->pdq_host_smt_info.rx_free = PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_host_smt); pdq->pdq_host_smt_info.rx_target = pdq->pdq_host_smt_info.rx_free - PDQ_RX_SEGCNT * 3; /* * Initialize the transmit information block. */ pdq->pdq_tx_hdr[0] = PDQ_FDDI_PH0; pdq->pdq_tx_hdr[1] = PDQ_FDDI_PH1; pdq->pdq_tx_hdr[2] = PDQ_FDDI_PH2; pdq->pdq_tx_info.tx_free = PDQ_RING_MASK(pdq->pdq_dbp->pdqdb_transmits); pdq->pdq_tx_info.tx_hdrdesc.txd_seg_len = sizeof(pdq->pdq_tx_hdr); pdq->pdq_tx_info.tx_hdrdesc.txd_sop = 1; pdq->pdq_tx_info.tx_hdrdesc.txd_pa_lo = PDQ_OS_VA_TO_PA(pdq, pdq->pdq_tx_hdr); state = PDQ_PSTS_ADAPTER_STATE(PDQ_CSR_READ(&pdq->pdq_csrs, csr_port_status)); PDQ_PRINTF(("PDQ Adapter State = %s\n", pdq_adapter_states[state])); /* * Stop the PDQ if it is running and put it into a known state. */ state = pdq_stop(pdq); PDQ_PRINTF(("PDQ Adapter State = %s\n", pdq_adapter_states[state])); PDQ_ASSERT(state == PDQS_DMA_AVAILABLE); /* * If the adapter is not the state we expect, then the initialization * failed. Cleanup and exit. */ #if defined(PDQVERBOSE) if (state == PDQS_HALTED) { pdq_halt_code_t halt_code = PDQ_PSTS_HALT_ID(PDQ_CSR_READ(&pdq->pdq_csrs, csr_port_status)); printf("Halt code = %d (%s)\n", halt_code, pdq_halt_codes[halt_code]); if (halt_code == PDQH_DMA_ERROR && pdq->pdq_type == PDQ_DEFPA) PDQ_PRINTF(("PFI status = 0x%x, Host 0 Fatal Interrupt = 0x%x\n", PDQ_CSR_READ(&pdq->pdq_pci_csrs, csr_pfi_status), PDQ_CSR_READ(&pdq->pdq_csrs, csr_host_int_type_0) & PDQ_HOST_INT_FATAL_ERROR)); } #endif if (state == PDQS_RESET || state == PDQS_HALTED || state == PDQS_UPGRADE) goto cleanup_and_return; PDQ_PRINTF(("PDQ Hardware Address = %02x-%02x-%02x-%02x-%02x-%02x\n", pdq->pdq_hwaddr.lanaddr_bytes[0], pdq->pdq_hwaddr.lanaddr_bytes[1], pdq->pdq_hwaddr.lanaddr_bytes[2], pdq->pdq_hwaddr.lanaddr_bytes[3], pdq->pdq_hwaddr.lanaddr_bytes[4], pdq->pdq_hwaddr.lanaddr_bytes[5])); PDQ_PRINTF(("PDQ Firmware Revision = %c%c%c%c\n", pdq->pdq_fwrev.fwrev_bytes[0], pdq->pdq_fwrev.fwrev_bytes[1], pdq->pdq_fwrev.fwrev_bytes[2], pdq->pdq_fwrev.fwrev_bytes[3])); PDQ_PRINTF(("PDQ Chip Revision = ")); switch (pdq->pdq_chip_rev) { case PDQ_CHIP_REV_A_B_OR_C: PDQ_PRINTF(("Rev C or below")); break; case PDQ_CHIP_REV_D: PDQ_PRINTF(("Rev D")); break; case PDQ_CHIP_REV_E: PDQ_PRINTF(("Rev E")); break; default: PDQ_PRINTF(("Unknown Rev %d", (int) pdq->pdq_chip_rev)); } PDQ_PRINTF(("\n")); return pdq; }
514643.c
void main() { int x[-10]; // it'll not complite in C x = 2; // it'll also not compile, but independently (e.g. with: int x[1] = { 2 }; ) printid(x); // here it compiles and crashes }
968708.c
void togglefullscreen(const Arg *arg) { Client *c = selmon->sel; if (!c) return; #if FAKEFULLSCREEN_CLIENT_PATCH && !FAKEFULLSCREEN_PATCH if (c->fakefullscreen == 1) { // fake fullscreen --> fullscreen c->fakefullscreen = 2; setfullscreen(c, 1); } else setfullscreen(c, !c->isfullscreen); #else setfullscreen(c, !c->isfullscreen); #endif // FAKEFULLSCREEN_CLIENT_PATCH }
926984.c
/* * Copyright (c) 2011 Stefano Sabatini * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * eval audio source */ #include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/channel_layout.h" #include "libavutil/eval.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "avfilter.h" #include "audio.h" #include "internal.h" static const char * const var_names[] = { "ch", ///< the value of the current channel "n", ///< number of frame "nb_in_channels", "nb_out_channels", "t", ///< timestamp expressed in seconds "s", ///< sample rate NULL }; enum var_name { VAR_CH, VAR_N, VAR_NB_IN_CHANNELS, VAR_NB_OUT_CHANNELS, VAR_T, VAR_S, VAR_VARS_NB }; typedef struct { const AVClass *class; char *sample_rate_str; int sample_rate; int64_t chlayout; char *chlayout_str; int nb_channels; ///< number of output channels int nb_in_channels; ///< number of input channels int same_chlayout; ///< set output as input channel layout int64_t pts; AVExpr **expr; char *exprs; int nb_samples; ///< number of samples per requested frame int64_t duration; uint64_t n; double var_values[VAR_VARS_NB]; double *channel_values; int64_t out_channel_layout; } EvalContext; static double val(void *priv, double ch) { EvalContext *eval = priv; return eval->channel_values[FFMIN((int)ch, eval->nb_in_channels-1)]; } static double (* const aeval_func1[])(void *, double) = { val, NULL }; static const char * const aeval_func1_names[] = { "val", NULL }; #define OFFSET(x) offsetof(EvalContext, x) #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM static const AVOption aevalsrc_options[]= { { "exprs", "set the '|'-separated list of channels expressions", OFFSET(exprs), AV_OPT_TYPE_STRING, {.str = NULL}, .flags = FLAGS }, { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX, FLAGS }, { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX, FLAGS }, { "sample_rate", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX, FLAGS }, { "s", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX, FLAGS }, { "duration", "set audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS }, { "d", "set audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS }, { "channel_layout", "set channel layout", OFFSET(chlayout_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, { "c", "set channel layout", OFFSET(chlayout_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, { NULL } }; AVFILTER_DEFINE_CLASS(aevalsrc); static int parse_channel_expressions(AVFilterContext *ctx, int expected_nb_channels) { EvalContext *eval = ctx->priv; char *args1 = av_strdup(eval->exprs); char *expr, *last_expr, *buf; double (* const *func1)(void *, double) = NULL; const char * const *func1_names = NULL; int i, ret = 0; if (!args1) return AVERROR(ENOMEM); if (!eval->exprs) { av_log(ctx, AV_LOG_ERROR, "Channels expressions list is empty\n"); return AVERROR(EINVAL); } if (!strcmp(ctx->filter->name, "aeval")) { func1 = aeval_func1; func1_names = aeval_func1_names; } #define ADD_EXPRESSION(expr_) do { \ if (!av_dynarray2_add((void **)&eval->expr, &eval->nb_channels, \ sizeof(*eval->expr), NULL)) { \ ret = AVERROR(ENOMEM); \ goto end; \ } \ eval->expr[eval->nb_channels-1] = NULL; \ ret = av_expr_parse(&eval->expr[eval->nb_channels - 1], expr_, \ var_names, func1_names, func1, \ NULL, NULL, 0, ctx); \ if (ret < 0) \ goto end; \ } while (0) /* reset expressions */ for (i = 0; i < eval->nb_channels; i++) { av_expr_free(eval->expr[i]); eval->expr[i] = NULL; } av_freep(&eval->expr); eval->nb_channels = 0; buf = args1; while (expr = av_strtok(buf, "|", &buf)) { ADD_EXPRESSION(expr); last_expr = expr; } if (expected_nb_channels > eval->nb_channels) for (i = eval->nb_channels; i < expected_nb_channels; i++) ADD_EXPRESSION(last_expr); if (expected_nb_channels > 0 && eval->nb_channels != expected_nb_channels) { av_log(ctx, AV_LOG_ERROR, "Mismatch between the specified number of channel expressions '%d' " "and the number of expected output channels '%d' for the specified channel layout\n", eval->nb_channels, expected_nb_channels); ret = AVERROR(EINVAL); goto end; } end: av_free(args1); return ret; } static av_cold int init(AVFilterContext *ctx) { EvalContext *eval = ctx->priv; int ret = 0; if (eval->chlayout_str) { if (!strcmp(eval->chlayout_str, "same") && !strcmp(ctx->filter->name, "aeval")) { eval->same_chlayout = 1; } else { ret = ff_parse_channel_layout(&eval->chlayout, NULL, eval->chlayout_str, ctx); if (ret < 0) return ret; ret = parse_channel_expressions(ctx, av_get_channel_layout_nb_channels(eval->chlayout)); if (ret < 0) return ret; } } else { /* guess channel layout from nb expressions/channels */ if ((ret = parse_channel_expressions(ctx, -1)) < 0) return ret; eval->chlayout = av_get_default_channel_layout(eval->nb_channels); if (!eval->chlayout && eval->nb_channels <= 0) { av_log(ctx, AV_LOG_ERROR, "Invalid number of channels '%d' provided\n", eval->nb_channels); return AVERROR(EINVAL); } } if (eval->sample_rate_str) if ((ret = ff_parse_sample_rate(&eval->sample_rate, eval->sample_rate_str, ctx))) return ret; eval->n = 0; return ret; } static av_cold void uninit(AVFilterContext *ctx) { EvalContext *eval = ctx->priv; int i; for (i = 0; i < eval->nb_channels; i++) { av_expr_free(eval->expr[i]); eval->expr[i] = NULL; } av_freep(&eval->expr); } static int config_props(AVFilterLink *outlink) { EvalContext *eval = outlink->src->priv; char buf[128]; outlink->time_base = (AVRational){1, eval->sample_rate}; outlink->sample_rate = eval->sample_rate; eval->var_values[VAR_S] = eval->sample_rate; eval->var_values[VAR_NB_IN_CHANNELS] = NAN; eval->var_values[VAR_NB_OUT_CHANNELS] = outlink->channels; av_get_channel_layout_string(buf, sizeof(buf), 0, eval->chlayout); av_log(outlink->src, AV_LOG_VERBOSE, "sample_rate:%d chlayout:%s duration:%"PRId64"\n", eval->sample_rate, buf, eval->duration); return 0; } static int query_formats(AVFilterContext *ctx) { EvalContext *eval = ctx->priv; static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBLP, AV_SAMPLE_FMT_NONE }; int64_t chlayouts[] = { eval->chlayout ? eval->chlayout : FF_COUNT2LAYOUT(eval->nb_channels) , -1 }; int sample_rates[] = { eval->sample_rate, -1 }; ff_set_common_formats (ctx, ff_make_format_list(sample_fmts)); ff_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts)); ff_set_common_samplerates(ctx, ff_make_format_list(sample_rates)); return 0; } static int request_frame(AVFilterLink *outlink) { EvalContext *eval = outlink->src->priv; AVFrame *samplesref; int i, j; int64_t t = av_rescale(eval->n, AV_TIME_BASE, eval->sample_rate); if (eval->duration >= 0 && t >= eval->duration) return AVERROR_EOF; samplesref = ff_get_audio_buffer(outlink, eval->nb_samples); if (!samplesref) return AVERROR(ENOMEM); /* evaluate expression for each single sample and for each channel */ for (i = 0; i < eval->nb_samples; i++, eval->n++) { eval->var_values[VAR_N] = eval->n; eval->var_values[VAR_T] = eval->var_values[VAR_N] * (double)1/eval->sample_rate; for (j = 0; j < eval->nb_channels; j++) { *((double *) samplesref->extended_data[j] + i) = av_expr_eval(eval->expr[j], eval->var_values, NULL); } } samplesref->pts = eval->pts; samplesref->sample_rate = eval->sample_rate; eval->pts += eval->nb_samples; return ff_filter_frame(outlink, samplesref); } #if CONFIG_AEVALSRC_FILTER static const AVFilterPad aevalsrc_outputs[] = { { .name = "default", .type = AVMEDIA_TYPE_AUDIO, .config_props = config_props, .request_frame = request_frame, }, { NULL } }; AVFilter ff_asrc_aevalsrc = { .name = "aevalsrc", .description = NULL_IF_CONFIG_SMALL("Generate an audio signal generated by an expression."), .query_formats = query_formats, .init = init, .uninit = uninit, .priv_size = sizeof(EvalContext), .inputs = NULL, .outputs = aevalsrc_outputs, .priv_class = &aevalsrc_class, }; #endif /* CONFIG_AEVALSRC_FILTER */ #define OFFSET(x) offsetof(EvalContext, x) #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM static const AVOption aeval_options[]= { { "exprs", "set the '|'-separated list of channels expressions", OFFSET(exprs), AV_OPT_TYPE_STRING, {.str = NULL}, .flags = FLAGS }, { "channel_layout", "set channel layout", OFFSET(chlayout_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, { "c", "set channel layout", OFFSET(chlayout_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, { NULL } }; AVFILTER_DEFINE_CLASS(aeval); static int aeval_query_formats(AVFilterContext *ctx) { AVFilterFormats *formats = NULL; AVFilterChannelLayouts *layouts; AVFilterLink *inlink = ctx->inputs[0]; AVFilterLink *outlink = ctx->outputs[0]; EvalContext *eval = ctx->priv; static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBLP, AV_SAMPLE_FMT_NONE }; // inlink supports any channel layout layouts = ff_all_channel_counts(); ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts); if (eval->same_chlayout) { layouts = ff_all_channel_counts(); if (!layouts) return AVERROR(ENOMEM); ff_set_common_channel_layouts(ctx, layouts); } else { // outlink supports only requested output channel layout layouts = NULL; ff_add_channel_layout(&layouts, eval->out_channel_layout ? eval->out_channel_layout : FF_COUNT2LAYOUT(eval->nb_channels)); ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts); } formats = ff_make_format_list(sample_fmts); if (!formats) return AVERROR(ENOMEM); ff_set_common_formats(ctx, formats); formats = ff_all_samplerates(); if (!formats) return AVERROR(ENOMEM); ff_set_common_samplerates(ctx, formats); return 0; } static int aeval_config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; EvalContext *eval = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; int ret; if (eval->same_chlayout) { eval->chlayout = inlink->channel_layout; if ((ret = parse_channel_expressions(ctx, inlink->channels)) < 0) return ret; } eval->n = 0; eval->nb_in_channels = eval->var_values[VAR_NB_IN_CHANNELS] = inlink->channels; eval->var_values[VAR_NB_OUT_CHANNELS] = outlink->channels; eval->var_values[VAR_S] = inlink->sample_rate; eval->var_values[VAR_T] = NAN; eval->channel_values = av_realloc_f(eval->channel_values, inlink->channels, sizeof(*eval->channel_values)); if (!eval->channel_values) return AVERROR(ENOMEM); return 0; } #define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts)*av_q2d(tb)) static int filter_frame(AVFilterLink *inlink, AVFrame *in) { EvalContext *eval = inlink->dst->priv; AVFilterLink *outlink = inlink->dst->outputs[0]; int nb_samples = in->nb_samples; AVFrame *out; double t0; int i, j; /* do volume scaling in-place if input buffer is writable */ out = ff_get_audio_buffer(outlink, nb_samples); if (!out) return AVERROR(ENOMEM); av_frame_copy_props(out, in); t0 = TS2T(in->pts, inlink->time_base); /* evaluate expression for each single sample and for each channel */ for (i = 0; i < nb_samples; i++, eval->n++) { eval->var_values[VAR_N] = eval->n; eval->var_values[VAR_T] = t0 + i * (double)1/inlink->sample_rate; for (j = 0; j < inlink->channels; j++) eval->channel_values[j] = *((double *) in->extended_data[j] + i); for (j = 0; j < outlink->channels; j++) { eval->var_values[VAR_CH] = j; *((double *) out->extended_data[j] + i) = av_expr_eval(eval->expr[j], eval->var_values, eval); } } av_frame_free(&in); return ff_filter_frame(outlink, out); } #if CONFIG_AEVAL_FILTER static const AVFilterPad aeval_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_AUDIO, .filter_frame = filter_frame, }, { NULL } }; static const AVFilterPad aeval_outputs[] = { { .name = "default", .type = AVMEDIA_TYPE_AUDIO, .config_props = aeval_config_output, }, { NULL } }; AVFilter ff_af_aeval = { .name = "aeval", .description = NULL_IF_CONFIG_SMALL("Filter audio signal according to a specified expression."), .query_formats = aeval_query_formats, .init = init, .uninit = uninit, .priv_size = sizeof(EvalContext), .inputs = aeval_inputs, .outputs = aeval_outputs, .priv_class = &aeval_class, }; #endif /* CONFIG_AEVAL_FILTER */
612960.c
/********************************************************************** * Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell * * Distributed under the MIT software license, see the accompanying * * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ #if defined HAVE_CONFIG_H #include "libsecp256k1-config.h" #endif #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include "secp256k1.c" #include "include/secp256k1.h" #include "testrand_impl.h" #ifdef ENABLE_OPENSSL_TESTS #include "openssl/bn.h" #include "openssl/ec.h" #include "openssl/ecdsa.h" #include "openssl/obj_mac.h" #endif #include "contrib/lax_der_parsing.c" #include "contrib/lax_der_privatekey_parsing.c" #if !defined(VG_CHECK) # if defined(VALGRIND) # include <valgrind/memcheck.h> # define VG_UNDEF(x,y) VALGRIND_MAKE_MEM_UNDEFINED((x),(y)) # define VG_CHECK(x,y) VALGRIND_CHECK_MEM_IS_DEFINED((x),(y)) # else # define VG_UNDEF(x,y) # define VG_CHECK(x,y) # endif #endif static int count = 64; static secp256k1_context *ctx = NULL; static void counting_illegal_callback_fn(const char* str, void* data) { /* Dummy callback function that just counts. */ int32_t *p; (void)str; p = data; (*p)++; } static void uncounting_illegal_callback_fn(const char* str, void* data) { /* Dummy callback function that just counts (backwards). */ int32_t *p; (void)str; p = data; (*p)--; } void random_field_element_test(secp256k1_fe *fe) { do { unsigned char b32[32]; secp256k1_rand256_test(b32); if (secp256k1_fe_set_b32(fe, b32)) { break; } } while(1); } void random_field_element_magnitude(secp256k1_fe *fe) { secp256k1_fe zero; int n = secp256k1_rand_int(9); secp256k1_fe_normalize(fe); if (n == 0) { return; } secp256k1_fe_clear(&zero); secp256k1_fe_negate(&zero, &zero, 0); secp256k1_fe_mul_int(&zero, n - 1); secp256k1_fe_add(fe, &zero); VERIFY_CHECK(fe->magnitude == n); } void random_group_element_test(secp256k1_ge *ge) { secp256k1_fe fe; do { random_field_element_test(&fe); if (secp256k1_ge_set_xo_var(ge, &fe, secp256k1_rand_bits(1))) { secp256k1_fe_normalize(&ge->y); break; } } while(1); } void random_group_element_jacobian_test(secp256k1_gej *gej, const secp256k1_ge *ge) { secp256k1_fe z2, z3; do { random_field_element_test(&gej->z); if (!secp256k1_fe_is_zero(&gej->z)) { break; } } while(1); secp256k1_fe_sqr(&z2, &gej->z); secp256k1_fe_mul(&z3, &z2, &gej->z); secp256k1_fe_mul(&gej->x, &ge->x, &z2); secp256k1_fe_mul(&gej->y, &ge->y, &z3); gej->infinity = ge->infinity; } void random_scalar_order_test(secp256k1_scalar *num) { do { unsigned char b32[32]; int overflow = 0; secp256k1_rand256_test(b32); secp256k1_scalar_set_b32(num, b32, &overflow); if (overflow || secp256k1_scalar_is_zero(num)) { continue; } break; } while(1); } void random_scalar_order(secp256k1_scalar *num) { do { unsigned char b32[32]; int overflow = 0; secp256k1_rand256(b32); secp256k1_scalar_set_b32(num, b32, &overflow); if (overflow || secp256k1_scalar_is_zero(num)) { continue; } break; } while(1); } void run_context_tests(void) { secp256k1_pubkey pubkey; secp256k1_pubkey zero_pubkey; secp256k1_ecdsa_signature sig; unsigned char ctmp[32]; int32_t ecount; int32_t ecount2; secp256k1_context *none = secp256k1_context_create(SECP256K1_CONTEXT_NONE); secp256k1_context *sign = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); secp256k1_context *vrfy = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY); secp256k1_context *both = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); secp256k1_gej pubj; secp256k1_ge pub; secp256k1_scalar msg, key, nonce; secp256k1_scalar sigr, sigs; memset(&zero_pubkey, 0, sizeof(zero_pubkey)); ecount = 0; ecount2 = 10; secp256k1_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount); secp256k1_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount2); secp256k1_context_set_error_callback(sign, counting_illegal_callback_fn, NULL); CHECK(vrfy->error_callback.fn != sign->error_callback.fn); /*** clone and destroy all of them to make sure cloning was complete ***/ { secp256k1_context *ctx_tmp; ctx_tmp = none; none = secp256k1_context_clone(none); secp256k1_context_destroy(ctx_tmp); ctx_tmp = sign; sign = secp256k1_context_clone(sign); secp256k1_context_destroy(ctx_tmp); ctx_tmp = vrfy; vrfy = secp256k1_context_clone(vrfy); secp256k1_context_destroy(ctx_tmp); ctx_tmp = both; both = secp256k1_context_clone(both); secp256k1_context_destroy(ctx_tmp); } /* Verify that the error callback makes it across the clone. */ CHECK(vrfy->error_callback.fn != sign->error_callback.fn); /* And that it resets back to default. */ secp256k1_context_set_error_callback(sign, NULL, NULL); CHECK(vrfy->error_callback.fn == sign->error_callback.fn); /*** attempt to use them ***/ random_scalar_order_test(&msg); random_scalar_order_test(&key); secp256k1_ecmult_gen(&both->ecmult_gen_ctx, &pubj, &key); secp256k1_ge_set_gej(&pub, &pubj); /* Verify context-type checking illegal-argument errors. */ memset(ctmp, 1, 32); CHECK(secp256k1_ec_pubkey_create(vrfy, &pubkey, ctmp) == 0); CHECK(ecount == 1); VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_create(sign, &pubkey, ctmp) == 1); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ecdsa_sign(vrfy, &sig, ctmp, ctmp, NULL, NULL) == 0); CHECK(ecount == 2); VG_UNDEF(&sig, sizeof(sig)); CHECK(secp256k1_ecdsa_sign(sign, &sig, ctmp, ctmp, NULL, NULL) == 1); VG_CHECK(&sig, sizeof(sig)); CHECK(ecount2 == 10); CHECK(secp256k1_ecdsa_verify(sign, &sig, ctmp, &pubkey) == 0); CHECK(ecount2 == 11); CHECK(secp256k1_ecdsa_verify(vrfy, &sig, ctmp, &pubkey) == 1); CHECK(ecount == 2); CHECK(secp256k1_ec_pubkey_tweak_add(sign, &pubkey, ctmp) == 0); CHECK(ecount2 == 12); CHECK(secp256k1_ec_pubkey_tweak_add(vrfy, &pubkey, ctmp) == 1); CHECK(ecount == 2); CHECK(secp256k1_ec_pubkey_tweak_mul(sign, &pubkey, ctmp) == 0); CHECK(ecount2 == 13); CHECK(secp256k1_ec_pubkey_negate(vrfy, &pubkey) == 1); CHECK(ecount == 2); CHECK(secp256k1_ec_pubkey_negate(sign, &pubkey) == 1); CHECK(ecount == 2); CHECK(secp256k1_ec_pubkey_negate(sign, NULL) == 0); CHECK(ecount2 == 14); CHECK(secp256k1_ec_pubkey_negate(vrfy, &zero_pubkey) == 0); CHECK(ecount == 3); CHECK(secp256k1_ec_pubkey_tweak_mul(vrfy, &pubkey, ctmp) == 1); CHECK(ecount == 3); CHECK(secp256k1_context_randomize(vrfy, ctmp) == 0); CHECK(ecount == 4); CHECK(secp256k1_context_randomize(sign, NULL) == 1); CHECK(ecount2 == 14); secp256k1_context_set_illegal_callback(vrfy, NULL, NULL); secp256k1_context_set_illegal_callback(sign, NULL, NULL); /* This shouldn't leak memory, due to already-set tests. */ secp256k1_ecmult_gen_context_build(&sign->ecmult_gen_ctx, NULL); secp256k1_ecmult_context_build(&vrfy->ecmult_ctx, NULL); /* obtain a working nonce */ do { random_scalar_order_test(&nonce); } while(!secp256k1_ecdsa_sig_sign(&both->ecmult_gen_ctx, &sigr, &sigs, &key, &msg, &nonce, NULL)); /* try signing */ CHECK(secp256k1_ecdsa_sig_sign(&sign->ecmult_gen_ctx, &sigr, &sigs, &key, &msg, &nonce, NULL)); CHECK(secp256k1_ecdsa_sig_sign(&both->ecmult_gen_ctx, &sigr, &sigs, &key, &msg, &nonce, NULL)); /* try verifying */ CHECK(secp256k1_ecdsa_sig_verify(&vrfy->ecmult_ctx, &sigr, &sigs, &pub, &msg)); CHECK(secp256k1_ecdsa_sig_verify(&both->ecmult_ctx, &sigr, &sigs, &pub, &msg)); /* cleanup */ secp256k1_context_destroy(none); secp256k1_context_destroy(sign); secp256k1_context_destroy(vrfy); secp256k1_context_destroy(both); /* Defined as no-op. */ secp256k1_context_destroy(NULL); } /***** HASH TESTS *****/ void run_sha256_tests(void) { static const char *inputs[8] = { "", "abc", "message digest", "secure hash algorithm", "SHA256 is considered to be safe", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "For this sample, this 63-byte string will be used as input data", "This is exactly 64 bytes long, not counting the terminating byte" }; static const unsigned char outputs[8][32] = { {0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}, {0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad}, {0xf7, 0x84, 0x6f, 0x55, 0xcf, 0x23, 0xe1, 0x4e, 0xeb, 0xea, 0xb5, 0xb4, 0xe1, 0x55, 0x0c, 0xad, 0x5b, 0x50, 0x9e, 0x33, 0x48, 0xfb, 0xc4, 0xef, 0xa3, 0xa1, 0x41, 0x3d, 0x39, 0x3c, 0xb6, 0x50}, {0xf3, 0x0c, 0xeb, 0x2b, 0xb2, 0x82, 0x9e, 0x79, 0xe4, 0xca, 0x97, 0x53, 0xd3, 0x5a, 0x8e, 0xcc, 0x00, 0x26, 0x2d, 0x16, 0x4c, 0xc0, 0x77, 0x08, 0x02, 0x95, 0x38, 0x1c, 0xbd, 0x64, 0x3f, 0x0d}, {0x68, 0x19, 0xd9, 0x15, 0xc7, 0x3f, 0x4d, 0x1e, 0x77, 0xe4, 0xe1, 0xb5, 0x2d, 0x1f, 0xa0, 0xf9, 0xcf, 0x9b, 0xea, 0xea, 0xd3, 0x93, 0x9f, 0x15, 0x87, 0x4b, 0xd9, 0x88, 0xe2, 0xa2, 0x36, 0x30}, {0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, 0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39, 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67, 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1}, {0xf0, 0x8a, 0x78, 0xcb, 0xba, 0xee, 0x08, 0x2b, 0x05, 0x2a, 0xe0, 0x70, 0x8f, 0x32, 0xfa, 0x1e, 0x50, 0xc5, 0xc4, 0x21, 0xaa, 0x77, 0x2b, 0xa5, 0xdb, 0xb4, 0x06, 0xa2, 0xea, 0x6b, 0xe3, 0x42}, {0xab, 0x64, 0xef, 0xf7, 0xe8, 0x8e, 0x2e, 0x46, 0x16, 0x5e, 0x29, 0xf2, 0xbc, 0xe4, 0x18, 0x26, 0xbd, 0x4c, 0x7b, 0x35, 0x52, 0xf6, 0xb3, 0x82, 0xa9, 0xe7, 0xd3, 0xaf, 0x47, 0xc2, 0x45, 0xf8} }; int i; for (i = 0; i < 8; i++) { unsigned char out[32]; secp256k1_sha256_t hasher; secp256k1_sha256_initialize(&hasher); secp256k1_sha256_write(&hasher, (const unsigned char*)(inputs[i]), strlen(inputs[i])); secp256k1_sha256_finalize(&hasher, out); CHECK(memcmp(out, outputs[i], 32) == 0); if (strlen(inputs[i]) > 0) { int split = secp256k1_rand_int(strlen(inputs[i])); secp256k1_sha256_initialize(&hasher); secp256k1_sha256_write(&hasher, (const unsigned char*)(inputs[i]), split); secp256k1_sha256_write(&hasher, (const unsigned char*)(inputs[i] + split), strlen(inputs[i]) - split); secp256k1_sha256_finalize(&hasher, out); CHECK(memcmp(out, outputs[i], 32) == 0); } } } void run_hmac_sha256_tests(void) { static const char *keys[6] = { "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x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aa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" }; static const char *inputs[6] = { "\x48\x69\x20\x54\x68\x65\x72\x65", "\x77\x68\x61\x74\x20\x64\x6f\x20\x79\x61\x20\x77\x61\x6e\x74\x20\x66\x6f\x72\x20\x6e\x6f\x74\x68\x69\x6e\x67\x3f", "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd", "\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd", "\x54\x65\x73\x74\x20\x55\x73\x69\x6e\x67\x20\x4c\x61\x72\x67\x65\x72\x20\x54\x68\x61\x6e\x20\x42\x6c\x6f\x63\x6b\x2d\x53\x69\x7a\x65\x20\x4b\x65\x79\x20\x2d\x20\x48\x61\x73\x68\x20\x4b\x65\x79\x20\x46\x69\x72\x73\x74", "\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20\x74\x65\x73\x74\x20\x75\x73\x69\x6e\x67\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x6b\x65\x79\x20\x61\x6e\x64\x20\x61\x20\x6c\x61\x72\x67\x65\x72\x20\x74\x68\x61\x6e\x20\x62\x6c\x6f\x63\x6b\x2d\x73\x69\x7a\x65\x20\x64\x61\x74\x61\x2e\x20\x54\x68\x65\x20\x6b\x65\x79\x20\x6e\x65\x65\x64\x73\x20\x74\x6f\x20\x62\x65\x20\x68\x61\x73\x68\x65\x64\x20\x62\x65\x66\x6f\x72\x65\x20\x62\x65\x69\x6e\x67\x20\x75\x73\x65\x64\x20\x62\x79\x20\x74\x68\x65\x20\x48\x4d\x41\x43\x20\x61\x6c\x67\x6f\x72\x69\x74\x68\x6d\x2e" }; static const unsigned char outputs[6][32] = { {0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53, 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b, 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7, 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7}, {0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e, 0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7, 0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83, 0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec, 0x38, 0x43}, {0x77, 0x3e, 0xa9, 0x1e, 0x36, 0x80, 0x0e, 0x46, 0x85, 0x4d, 0xb8, 0xeb, 0xd0, 0x91, 0x81, 0xa7, 0x29, 0x59, 0x09, 0x8b, 0x3e, 0xf8, 0xc1, 0x22, 0xd9, 0x63, 0x55, 0x14, 0xce, 0xd5, 0x65, 0xfe}, {0x82, 0x55, 0x8a, 0x38, 0x9a, 0x44, 0x3c, 0x0e, 0xa4, 0xcc, 0x81, 0x98, 0x99, 0xf2, 0x08, 0x3a, 0x85, 0xf0, 0xfa, 0xa3, 0xe5, 0x78, 0xf8, 0x07, 0x7a, 0x2e, 0x3f, 0xf4, 0x67, 0x29, 0x66, 0x5b}, {0x60, 0xe4, 0x31, 0x59, 0x1e, 0xe0, 0xb6, 0x7f, 0x0d, 0x8a, 0x26, 0xaa, 0xcb, 0xf5, 0xb7, 0x7f, 0x8e, 0x0b, 0xc6, 0x21, 0x37, 0x28, 0xc5, 0x14, 0x05, 0x46, 0x04, 0x0f, 0x0e, 0xe3, 0x7f, 0x54}, {0x9b, 0x09, 0xff, 0xa7, 0x1b, 0x94, 0x2f, 0xcb, 0x27, 0x63, 0x5f, 0xbc, 0xd5, 0xb0, 0xe9, 0x44, 0xbf, 0xdc, 0x63, 0x64, 0x4f, 0x07, 0x13, 0x93, 0x8a, 0x7f, 0x51, 0x53, 0x5c, 0x3a, 0x35, 0xe2} }; int i; for (i = 0; i < 6; i++) { secp256k1_hmac_sha256_t hasher; unsigned char out[32]; secp256k1_hmac_sha256_initialize(&hasher, (const unsigned char*)(keys[i]), strlen(keys[i])); secp256k1_hmac_sha256_write(&hasher, (const unsigned char*)(inputs[i]), strlen(inputs[i])); secp256k1_hmac_sha256_finalize(&hasher, out); CHECK(memcmp(out, outputs[i], 32) == 0); if (strlen(inputs[i]) > 0) { int split = secp256k1_rand_int(strlen(inputs[i])); secp256k1_hmac_sha256_initialize(&hasher, (const unsigned char*)(keys[i]), strlen(keys[i])); secp256k1_hmac_sha256_write(&hasher, (const unsigned char*)(inputs[i]), split); secp256k1_hmac_sha256_write(&hasher, (const unsigned char*)(inputs[i] + split), strlen(inputs[i]) - split); secp256k1_hmac_sha256_finalize(&hasher, out); CHECK(memcmp(out, outputs[i], 32) == 0); } } } void run_rfc6979_hmac_sha256_tests(void) { static const unsigned char key1[65] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x00, 0x4b, 0xf5, 0x12, 0x2f, 0x34, 0x45, 0x54, 0xc5, 0x3b, 0xde, 0x2e, 0xbb, 0x8c, 0xd2, 0xb7, 0xe3, 0xd1, 0x60, 0x0a, 0xd6, 0x31, 0xc3, 0x85, 0xa5, 0xd7, 0xcc, 0xe2, 0x3c, 0x77, 0x85, 0x45, 0x9a, 0}; static const unsigned char out1[3][32] = { {0x4f, 0xe2, 0x95, 0x25, 0xb2, 0x08, 0x68, 0x09, 0x15, 0x9a, 0xcd, 0xf0, 0x50, 0x6e, 0xfb, 0x86, 0xb0, 0xec, 0x93, 0x2c, 0x7b, 0xa4, 0x42, 0x56, 0xab, 0x32, 0x1e, 0x42, 0x1e, 0x67, 0xe9, 0xfb}, {0x2b, 0xf0, 0xff, 0xf1, 0xd3, 0xc3, 0x78, 0xa2, 0x2d, 0xc5, 0xde, 0x1d, 0x85, 0x65, 0x22, 0x32, 0x5c, 0x65, 0xb5, 0x04, 0x49, 0x1a, 0x0c, 0xbd, 0x01, 0xcb, 0x8f, 0x3a, 0xa6, 0x7f, 0xfd, 0x4a}, {0xf5, 0x28, 0xb4, 0x10, 0xcb, 0x54, 0x1f, 0x77, 0x00, 0x0d, 0x7a, 0xfb, 0x6c, 0x5b, 0x53, 0xc5, 0xc4, 0x71, 0xea, 0xb4, 0x3e, 0x46, 0x6d, 0x9a, 0xc5, 0x19, 0x0c, 0x39, 0xc8, 0x2f, 0xd8, 0x2e} }; static const unsigned char key2[64] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}; static const unsigned char out2[3][32] = { {0x9c, 0x23, 0x6c, 0x16, 0x5b, 0x82, 0xae, 0x0c, 0xd5, 0x90, 0x65, 0x9e, 0x10, 0x0b, 0x6b, 0xab, 0x30, 0x36, 0xe7, 0xba, 0x8b, 0x06, 0x74, 0x9b, 0xaf, 0x69, 0x81, 0xe1, 0x6f, 0x1a, 0x2b, 0x95}, {0xdf, 0x47, 0x10, 0x61, 0x62, 0x5b, 0xc0, 0xea, 0x14, 0xb6, 0x82, 0xfe, 0xee, 0x2c, 0x9c, 0x02, 0xf2, 0x35, 0xda, 0x04, 0x20, 0x4c, 0x1d, 0x62, 0xa1, 0x53, 0x6c, 0x6e, 0x17, 0xae, 0xd7, 0xa9}, {0x75, 0x97, 0x88, 0x7c, 0xbd, 0x76, 0x32, 0x1f, 0x32, 0xe3, 0x04, 0x40, 0x67, 0x9a, 0x22, 0xcf, 0x7f, 0x8d, 0x9d, 0x2e, 0xac, 0x39, 0x0e, 0x58, 0x1f, 0xea, 0x09, 0x1c, 0xe2, 0x02, 0xba, 0x94} }; secp256k1_rfc6979_hmac_sha256_t rng; unsigned char out[32]; int i; secp256k1_rfc6979_hmac_sha256_initialize(&rng, key1, 64); for (i = 0; i < 3; i++) { secp256k1_rfc6979_hmac_sha256_generate(&rng, out, 32); CHECK(memcmp(out, out1[i], 32) == 0); } secp256k1_rfc6979_hmac_sha256_finalize(&rng); secp256k1_rfc6979_hmac_sha256_initialize(&rng, key1, 65); for (i = 0; i < 3; i++) { secp256k1_rfc6979_hmac_sha256_generate(&rng, out, 32); CHECK(memcmp(out, out1[i], 32) != 0); } secp256k1_rfc6979_hmac_sha256_finalize(&rng); secp256k1_rfc6979_hmac_sha256_initialize(&rng, key2, 64); for (i = 0; i < 3; i++) { secp256k1_rfc6979_hmac_sha256_generate(&rng, out, 32); CHECK(memcmp(out, out2[i], 32) == 0); } secp256k1_rfc6979_hmac_sha256_finalize(&rng); } /***** RANDOM TESTS *****/ void test_rand_bits(int rand32, int bits) { /* (1-1/2^B)^rounds[B] < 1/10^9, so rounds is the number of iterations to * get a false negative chance below once in a billion */ static const unsigned int rounds[7] = {1, 30, 73, 156, 322, 653, 1316}; /* We try multiplying the results with various odd numbers, which shouldn't * influence the uniform distribution modulo a power of 2. */ static const uint32_t mults[6] = {1, 3, 21, 289, 0x9999, 0x80402011}; /* We only select up to 6 bits from the output to analyse */ unsigned int usebits = bits > 6 ? 6 : bits; unsigned int maxshift = bits - usebits; /* For each of the maxshift+1 usebits-bit sequences inside a bits-bit number, track all observed outcomes, one per bit in a uint64_t. */ uint64_t x[6][27] = {{0}}; unsigned int i, shift, m; /* Multiply the output of all rand calls with the odd number m, which should not change the uniformity of its distribution. */ for (i = 0; i < rounds[usebits]; i++) { uint32_t r = (rand32 ? secp256k1_rand32() : secp256k1_rand_bits(bits)); CHECK((((uint64_t)r) >> bits) == 0); for (m = 0; m < sizeof(mults) / sizeof(mults[0]); m++) { uint32_t rm = r * mults[m]; for (shift = 0; shift <= maxshift; shift++) { x[m][shift] |= (((uint64_t)1) << ((rm >> shift) & ((1 << usebits) - 1))); } } } for (m = 0; m < sizeof(mults) / sizeof(mults[0]); m++) { for (shift = 0; shift <= maxshift; shift++) { /* Test that the lower usebits bits of x[shift] are 1 */ CHECK(((~x[m][shift]) << (64 - (1 << usebits))) == 0); } } } /* Subrange must be a whole divisor of range, and at most 64 */ void test_rand_int(uint32_t range, uint32_t subrange) { /* (1-1/subrange)^rounds < 1/10^9 */ int rounds = (subrange * 2073) / 100; int i; uint64_t x = 0; CHECK((range % subrange) == 0); for (i = 0; i < rounds; i++) { uint32_t r = secp256k1_rand_int(range); CHECK(r < range); r = r % subrange; x |= (((uint64_t)1) << r); } /* Test that the lower subrange bits of x are 1. */ CHECK(((~x) << (64 - subrange)) == 0); } void run_rand_bits(void) { size_t b; test_rand_bits(1, 32); for (b = 1; b <= 32; b++) { test_rand_bits(0, b); } } void run_rand_int(void) { static const uint32_t ms[] = {1, 3, 17, 1000, 13771, 999999, 33554432}; static const uint32_t ss[] = {1, 3, 6, 9, 13, 31, 64}; unsigned int m, s; for (m = 0; m < sizeof(ms) / sizeof(ms[0]); m++) { for (s = 0; s < sizeof(ss) / sizeof(ss[0]); s++) { test_rand_int(ms[m] * ss[s], ss[s]); } } } /***** NUM TESTS *****/ #ifndef USE_NUM_NONE void random_num_negate(secp256k1_num *num) { if (secp256k1_rand_bits(1)) { secp256k1_num_negate(num); } } void random_num_order_test(secp256k1_num *num) { secp256k1_scalar sc; random_scalar_order_test(&sc); secp256k1_scalar_get_num(num, &sc); } void random_num_order(secp256k1_num *num) { secp256k1_scalar sc; random_scalar_order(&sc); secp256k1_scalar_get_num(num, &sc); } void test_num_negate(void) { secp256k1_num n1; secp256k1_num n2; random_num_order_test(&n1); /* n1 = R */ random_num_negate(&n1); secp256k1_num_copy(&n2, &n1); /* n2 = R */ secp256k1_num_sub(&n1, &n2, &n1); /* n1 = n2-n1 = 0 */ CHECK(secp256k1_num_is_zero(&n1)); secp256k1_num_copy(&n1, &n2); /* n1 = R */ secp256k1_num_negate(&n1); /* n1 = -R */ CHECK(!secp256k1_num_is_zero(&n1)); secp256k1_num_add(&n1, &n2, &n1); /* n1 = n2+n1 = 0 */ CHECK(secp256k1_num_is_zero(&n1)); secp256k1_num_copy(&n1, &n2); /* n1 = R */ secp256k1_num_negate(&n1); /* n1 = -R */ CHECK(secp256k1_num_is_neg(&n1) != secp256k1_num_is_neg(&n2)); secp256k1_num_negate(&n1); /* n1 = R */ CHECK(secp256k1_num_eq(&n1, &n2)); } void test_num_add_sub(void) { int i; secp256k1_scalar s; secp256k1_num n1; secp256k1_num n2; secp256k1_num n1p2, n2p1, n1m2, n2m1; random_num_order_test(&n1); /* n1 = R1 */ if (secp256k1_rand_bits(1)) { random_num_negate(&n1); } random_num_order_test(&n2); /* n2 = R2 */ if (secp256k1_rand_bits(1)) { random_num_negate(&n2); } secp256k1_num_add(&n1p2, &n1, &n2); /* n1p2 = R1 + R2 */ secp256k1_num_add(&n2p1, &n2, &n1); /* n2p1 = R2 + R1 */ secp256k1_num_sub(&n1m2, &n1, &n2); /* n1m2 = R1 - R2 */ secp256k1_num_sub(&n2m1, &n2, &n1); /* n2m1 = R2 - R1 */ CHECK(secp256k1_num_eq(&n1p2, &n2p1)); CHECK(!secp256k1_num_eq(&n1p2, &n1m2)); secp256k1_num_negate(&n2m1); /* n2m1 = -R2 + R1 */ CHECK(secp256k1_num_eq(&n2m1, &n1m2)); CHECK(!secp256k1_num_eq(&n2m1, &n1)); secp256k1_num_add(&n2m1, &n2m1, &n2); /* n2m1 = -R2 + R1 + R2 = R1 */ CHECK(secp256k1_num_eq(&n2m1, &n1)); CHECK(!secp256k1_num_eq(&n2p1, &n1)); secp256k1_num_sub(&n2p1, &n2p1, &n2); /* n2p1 = R2 + R1 - R2 = R1 */ CHECK(secp256k1_num_eq(&n2p1, &n1)); /* check is_one */ secp256k1_scalar_set_int(&s, 1); secp256k1_scalar_get_num(&n1, &s); CHECK(secp256k1_num_is_one(&n1)); /* check that 2^n + 1 is never 1 */ secp256k1_scalar_get_num(&n2, &s); for (i = 0; i < 250; ++i) { secp256k1_num_add(&n1, &n1, &n1); /* n1 *= 2 */ secp256k1_num_add(&n1p2, &n1, &n2); /* n1p2 = n1 + 1 */ CHECK(!secp256k1_num_is_one(&n1p2)); } } void test_num_mod(void) { int i; secp256k1_scalar s; secp256k1_num order, n; /* check that 0 mod anything is 0 */ random_scalar_order_test(&s); secp256k1_scalar_get_num(&order, &s); secp256k1_scalar_set_int(&s, 0); secp256k1_scalar_get_num(&n, &s); secp256k1_num_mod(&n, &order); CHECK(secp256k1_num_is_zero(&n)); /* check that anything mod 1 is 0 */ secp256k1_scalar_set_int(&s, 1); secp256k1_scalar_get_num(&order, &s); secp256k1_scalar_get_num(&n, &s); secp256k1_num_mod(&n, &order); CHECK(secp256k1_num_is_zero(&n)); /* check that increasing the number past 2^256 does not break this */ random_scalar_order_test(&s); secp256k1_scalar_get_num(&n, &s); /* multiply by 2^8, which'll test this case with high probability */ for (i = 0; i < 8; ++i) { secp256k1_num_add(&n, &n, &n); } secp256k1_num_mod(&n, &order); CHECK(secp256k1_num_is_zero(&n)); } void test_num_jacobi(void) { secp256k1_scalar sqr; secp256k1_scalar small; secp256k1_scalar five; /* five is not a quadratic residue */ secp256k1_num order, n; int i; /* squares mod 5 are 1, 4 */ const int jacobi5[10] = { 0, 1, -1, -1, 1, 0, 1, -1, -1, 1 }; /* check some small values with 5 as the order */ secp256k1_scalar_set_int(&five, 5); secp256k1_scalar_get_num(&order, &five); for (i = 0; i < 10; ++i) { secp256k1_scalar_set_int(&small, i); secp256k1_scalar_get_num(&n, &small); CHECK(secp256k1_num_jacobi(&n, &order) == jacobi5[i]); } /** test large values with 5 as group order */ secp256k1_scalar_get_num(&order, &five); /* we first need a scalar which is not a multiple of 5 */ do { secp256k1_num fiven; random_scalar_order_test(&sqr); secp256k1_scalar_get_num(&fiven, &five); secp256k1_scalar_get_num(&n, &sqr); secp256k1_num_mod(&n, &fiven); } while (secp256k1_num_is_zero(&n)); /* next force it to be a residue. 2 is a nonresidue mod 5 so we can * just multiply by two, i.e. add the number to itself */ if (secp256k1_num_jacobi(&n, &order) == -1) { secp256k1_num_add(&n, &n, &n); } /* test residue */ CHECK(secp256k1_num_jacobi(&n, &order) == 1); /* test nonresidue */ secp256k1_num_add(&n, &n, &n); CHECK(secp256k1_num_jacobi(&n, &order) == -1); /** test with secp group order as order */ secp256k1_scalar_order_get_num(&order); random_scalar_order_test(&sqr); secp256k1_scalar_sqr(&sqr, &sqr); /* test residue */ secp256k1_scalar_get_num(&n, &sqr); CHECK(secp256k1_num_jacobi(&n, &order) == 1); /* test nonresidue */ secp256k1_scalar_mul(&sqr, &sqr, &five); secp256k1_scalar_get_num(&n, &sqr); CHECK(secp256k1_num_jacobi(&n, &order) == -1); /* test multiple of the order*/ CHECK(secp256k1_num_jacobi(&order, &order) == 0); /* check one less than the order */ secp256k1_scalar_set_int(&small, 1); secp256k1_scalar_get_num(&n, &small); secp256k1_num_sub(&n, &order, &n); CHECK(secp256k1_num_jacobi(&n, &order) == 1); /* sage confirms this is 1 */ } void run_num_smalltests(void) { int i; for (i = 0; i < 100*count; i++) { test_num_negate(); test_num_add_sub(); test_num_mod(); test_num_jacobi(); } } #endif /***** SCALAR TESTS *****/ void scalar_test(void) { secp256k1_scalar s; secp256k1_scalar s1; secp256k1_scalar s2; #ifndef USE_NUM_NONE secp256k1_num snum, s1num, s2num; secp256k1_num order, half_order; #endif unsigned char c[32]; /* Set 's' to a random scalar, with value 'snum'. */ random_scalar_order_test(&s); /* Set 's1' to a random scalar, with value 's1num'. */ random_scalar_order_test(&s1); /* Set 's2' to a random scalar, with value 'snum2', and byte array representation 'c'. */ random_scalar_order_test(&s2); secp256k1_scalar_get_b32(c, &s2); #ifndef USE_NUM_NONE secp256k1_scalar_get_num(&snum, &s); secp256k1_scalar_get_num(&s1num, &s1); secp256k1_scalar_get_num(&s2num, &s2); secp256k1_scalar_order_get_num(&order); half_order = order; secp256k1_num_shift(&half_order, 1); #endif { int i; /* Test that fetching groups of 4 bits from a scalar and recursing n(i)=16*n(i-1)+p(i) reconstructs it. */ secp256k1_scalar n; secp256k1_scalar_set_int(&n, 0); for (i = 0; i < 256; i += 4) { secp256k1_scalar t; int j; secp256k1_scalar_set_int(&t, secp256k1_scalar_get_bits(&s, 256 - 4 - i, 4)); for (j = 0; j < 4; j++) { secp256k1_scalar_add(&n, &n, &n); } secp256k1_scalar_add(&n, &n, &t); } CHECK(secp256k1_scalar_eq(&n, &s)); } { /* Test that fetching groups of randomly-sized bits from a scalar and recursing n(i)=b*n(i-1)+p(i) reconstructs it. */ secp256k1_scalar n; int i = 0; secp256k1_scalar_set_int(&n, 0); while (i < 256) { secp256k1_scalar t; int j; int now = secp256k1_rand_int(15) + 1; if (now + i > 256) { now = 256 - i; } secp256k1_scalar_set_int(&t, secp256k1_scalar_get_bits_var(&s, 256 - now - i, now)); for (j = 0; j < now; j++) { secp256k1_scalar_add(&n, &n, &n); } secp256k1_scalar_add(&n, &n, &t); i += now; } CHECK(secp256k1_scalar_eq(&n, &s)); } #ifndef USE_NUM_NONE { /* Test that adding the scalars together is equal to adding their numbers together modulo the order. */ secp256k1_num rnum; secp256k1_num r2num; secp256k1_scalar r; secp256k1_num_add(&rnum, &snum, &s2num); secp256k1_num_mod(&rnum, &order); secp256k1_scalar_add(&r, &s, &s2); secp256k1_scalar_get_num(&r2num, &r); CHECK(secp256k1_num_eq(&rnum, &r2num)); } { /* Test that multiplying the scalars is equal to multiplying their numbers modulo the order. */ secp256k1_scalar r; secp256k1_num r2num; secp256k1_num rnum; secp256k1_num_mul(&rnum, &snum, &s2num); secp256k1_num_mod(&rnum, &order); secp256k1_scalar_mul(&r, &s, &s2); secp256k1_scalar_get_num(&r2num, &r); CHECK(secp256k1_num_eq(&rnum, &r2num)); /* The result can only be zero if at least one of the factors was zero. */ CHECK(secp256k1_scalar_is_zero(&r) == (secp256k1_scalar_is_zero(&s) || secp256k1_scalar_is_zero(&s2))); /* The results can only be equal to one of the factors if that factor was zero, or the other factor was one. */ CHECK(secp256k1_num_eq(&rnum, &snum) == (secp256k1_scalar_is_zero(&s) || secp256k1_scalar_is_one(&s2))); CHECK(secp256k1_num_eq(&rnum, &s2num) == (secp256k1_scalar_is_zero(&s2) || secp256k1_scalar_is_one(&s))); } { secp256k1_scalar neg; secp256k1_num negnum; secp256k1_num negnum2; /* Check that comparison with zero matches comparison with zero on the number. */ CHECK(secp256k1_num_is_zero(&snum) == secp256k1_scalar_is_zero(&s)); /* Check that comparison with the half order is equal to testing for high scalar. */ CHECK(secp256k1_scalar_is_high(&s) == (secp256k1_num_cmp(&snum, &half_order) > 0)); secp256k1_scalar_negate(&neg, &s); secp256k1_num_sub(&negnum, &order, &snum); secp256k1_num_mod(&negnum, &order); /* Check that comparison with the half order is equal to testing for high scalar after negation. */ CHECK(secp256k1_scalar_is_high(&neg) == (secp256k1_num_cmp(&negnum, &half_order) > 0)); /* Negating should change the high property, unless the value was already zero. */ CHECK((secp256k1_scalar_is_high(&s) == secp256k1_scalar_is_high(&neg)) == secp256k1_scalar_is_zero(&s)); secp256k1_scalar_get_num(&negnum2, &neg); /* Negating a scalar should be equal to (order - n) mod order on the number. */ CHECK(secp256k1_num_eq(&negnum, &negnum2)); secp256k1_scalar_add(&neg, &neg, &s); /* Adding a number to its negation should result in zero. */ CHECK(secp256k1_scalar_is_zero(&neg)); secp256k1_scalar_negate(&neg, &neg); /* Negating zero should still result in zero. */ CHECK(secp256k1_scalar_is_zero(&neg)); } { /* Test secp256k1_scalar_mul_shift_var. */ secp256k1_scalar r; secp256k1_num one; secp256k1_num rnum; secp256k1_num rnum2; unsigned char cone[1] = {0x01}; unsigned int shift = 256 + secp256k1_rand_int(257); secp256k1_scalar_mul_shift_var(&r, &s1, &s2, shift); secp256k1_num_mul(&rnum, &s1num, &s2num); secp256k1_num_shift(&rnum, shift - 1); secp256k1_num_set_bin(&one, cone, 1); secp256k1_num_add(&rnum, &rnum, &one); secp256k1_num_shift(&rnum, 1); secp256k1_scalar_get_num(&rnum2, &r); CHECK(secp256k1_num_eq(&rnum, &rnum2)); } { /* test secp256k1_scalar_shr_int */ secp256k1_scalar r; int i; random_scalar_order_test(&r); for (i = 0; i < 100; ++i) { int low; int shift = 1 + secp256k1_rand_int(15); int expected = r.d[0] % (1 << shift); low = secp256k1_scalar_shr_int(&r, shift); CHECK(expected == low); } } #endif { /* Test that scalar inverses are equal to the inverse of their number modulo the order. */ if (!secp256k1_scalar_is_zero(&s)) { secp256k1_scalar inv; #ifndef USE_NUM_NONE secp256k1_num invnum; secp256k1_num invnum2; #endif secp256k1_scalar_inverse(&inv, &s); #ifndef USE_NUM_NONE secp256k1_num_mod_inverse(&invnum, &snum, &order); secp256k1_scalar_get_num(&invnum2, &inv); CHECK(secp256k1_num_eq(&invnum, &invnum2)); #endif secp256k1_scalar_mul(&inv, &inv, &s); /* Multiplying a scalar with its inverse must result in one. */ CHECK(secp256k1_scalar_is_one(&inv)); secp256k1_scalar_inverse(&inv, &inv); /* Inverting one must result in one. */ CHECK(secp256k1_scalar_is_one(&inv)); #ifndef USE_NUM_NONE secp256k1_scalar_get_num(&invnum, &inv); CHECK(secp256k1_num_is_one(&invnum)); #endif } } { /* Test commutativity of add. */ secp256k1_scalar r1, r2; secp256k1_scalar_add(&r1, &s1, &s2); secp256k1_scalar_add(&r2, &s2, &s1); CHECK(secp256k1_scalar_eq(&r1, &r2)); } { secp256k1_scalar r1, r2; secp256k1_scalar b; int i; /* Test add_bit. */ int bit = secp256k1_rand_bits(8); secp256k1_scalar_set_int(&b, 1); CHECK(secp256k1_scalar_is_one(&b)); for (i = 0; i < bit; i++) { secp256k1_scalar_add(&b, &b, &b); } r1 = s1; r2 = s1; if (!secp256k1_scalar_add(&r1, &r1, &b)) { /* No overflow happened. */ secp256k1_scalar_cadd_bit(&r2, bit, 1); CHECK(secp256k1_scalar_eq(&r1, &r2)); /* cadd is a noop when flag is zero */ secp256k1_scalar_cadd_bit(&r2, bit, 0); CHECK(secp256k1_scalar_eq(&r1, &r2)); } } { /* Test commutativity of mul. */ secp256k1_scalar r1, r2; secp256k1_scalar_mul(&r1, &s1, &s2); secp256k1_scalar_mul(&r2, &s2, &s1); CHECK(secp256k1_scalar_eq(&r1, &r2)); } { /* Test associativity of add. */ secp256k1_scalar r1, r2; secp256k1_scalar_add(&r1, &s1, &s2); secp256k1_scalar_add(&r1, &r1, &s); secp256k1_scalar_add(&r2, &s2, &s); secp256k1_scalar_add(&r2, &s1, &r2); CHECK(secp256k1_scalar_eq(&r1, &r2)); } { /* Test associativity of mul. */ secp256k1_scalar r1, r2; secp256k1_scalar_mul(&r1, &s1, &s2); secp256k1_scalar_mul(&r1, &r1, &s); secp256k1_scalar_mul(&r2, &s2, &s); secp256k1_scalar_mul(&r2, &s1, &r2); CHECK(secp256k1_scalar_eq(&r1, &r2)); } { /* Test distributitivity of mul over add. */ secp256k1_scalar r1, r2, t; secp256k1_scalar_add(&r1, &s1, &s2); secp256k1_scalar_mul(&r1, &r1, &s); secp256k1_scalar_mul(&r2, &s1, &s); secp256k1_scalar_mul(&t, &s2, &s); secp256k1_scalar_add(&r2, &r2, &t); CHECK(secp256k1_scalar_eq(&r1, &r2)); } { /* Test square. */ secp256k1_scalar r1, r2; secp256k1_scalar_sqr(&r1, &s1); secp256k1_scalar_mul(&r2, &s1, &s1); CHECK(secp256k1_scalar_eq(&r1, &r2)); } { /* Test multiplicative identity. */ secp256k1_scalar r1, v1; secp256k1_scalar_set_int(&v1,1); secp256k1_scalar_mul(&r1, &s1, &v1); CHECK(secp256k1_scalar_eq(&r1, &s1)); } { /* Test additive identity. */ secp256k1_scalar r1, v0; secp256k1_scalar_set_int(&v0,0); secp256k1_scalar_add(&r1, &s1, &v0); CHECK(secp256k1_scalar_eq(&r1, &s1)); } { /* Test zero product property. */ secp256k1_scalar r1, v0; secp256k1_scalar_set_int(&v0,0); secp256k1_scalar_mul(&r1, &s1, &v0); CHECK(secp256k1_scalar_eq(&r1, &v0)); } } void run_scalar_tests(void) { int i; for (i = 0; i < 128 * count; i++) { scalar_test(); } { /* (-1)+1 should be zero. */ secp256k1_scalar s, o; secp256k1_scalar_set_int(&s, 1); CHECK(secp256k1_scalar_is_one(&s)); secp256k1_scalar_negate(&o, &s); secp256k1_scalar_add(&o, &o, &s); CHECK(secp256k1_scalar_is_zero(&o)); secp256k1_scalar_negate(&o, &o); CHECK(secp256k1_scalar_is_zero(&o)); } #ifndef USE_NUM_NONE { /* A scalar with value of the curve order should be 0. */ secp256k1_num order; secp256k1_scalar zero; unsigned char bin[32]; int overflow = 0; secp256k1_scalar_order_get_num(&order); secp256k1_num_get_bin(bin, 32, &order); secp256k1_scalar_set_b32(&zero, bin, &overflow); CHECK(overflow == 1); CHECK(secp256k1_scalar_is_zero(&zero)); } #endif { /* Does check_overflow check catch all ones? */ static const secp256k1_scalar overflowed = SECP256K1_SCALAR_CONST( 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL ); CHECK(secp256k1_scalar_check_overflow(&overflowed)); } { /* Static test vectors. * These were reduced from ~10^12 random vectors based on comparison-decision * and edge-case coverage on 32-bit and 64-bit implementations. * The responses were generated with Sage 5.9. */ secp256k1_scalar x; secp256k1_scalar y; secp256k1_scalar z; secp256k1_scalar zz; secp256k1_scalar one; secp256k1_scalar r1; secp256k1_scalar r2; #if defined(USE_SCALAR_INV_NUM) secp256k1_scalar zzv; #endif int overflow; unsigned char chal[33][2][32] = { {{0xff, 0xff, 0x03, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xc0, 0xff, 0xff, 0xff}, {0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff}}, {{0xef, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x80, 0xff}}, {{0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x00}, {0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff}}, {{0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x1e, 0xf8, 0xff, 0xff, 0xff, 0xfd, 0xff}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x03, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xf3, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}}, {{0x80, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x80, 0xff, 0xff, 0x3f, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xff}}, {{0xff, 0xff, 0xff, 0xff, 0x00, 0x0f, 0xfc, 0x9f, 0xff, 0xff, 0xff, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0x0f, 0xfc, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}, {0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0xf8, 0xff, 0x0f, 0xc0, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x80, 0xff, 0xff, 0xff}}, {{0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xef, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xf0}, {0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}, {{0x00, 0xf8, 0xff, 0x03, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc0, 0xff, 0x0f, 0xfc, 0xff}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x3f, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}, {{0x8f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, {{0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x00, 0x00, 0x80, 0xff, 0x7f}, {0xff, 0xcf, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xbf, 0xff, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00}}, {{0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0x01, 0xfc, 0xff, 0x01, 0x00, 0xfe, 0xff}, {0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00}}, {{0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf0, 0xff, 0xff, 0xe0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x00}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x7e, 0x00, 0x00}}, {{0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0xfe, 0x07, 0x00}, {0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60}}, {{0xff, 0x01, 0x00, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x80, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0xff, 0xff, 0x1f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00}}, {{0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff}}, {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xcf, 0xff, 0x1f, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00}, {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x7f, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff}}, {{0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}, {0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xf8, 0xff, 0xff, 0x1f, 0x00, 0xfe}}, {{0xff, 0xff, 0xff, 0x3f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x03, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x01, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}}, {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x40}}, {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, {{0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}, {{0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff}}, {{0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}, {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x40}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}, {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x07, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, {0xff, 0x01, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}, {{0xff, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x80, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff}, {0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xc0, 0xf1, 0x7f, 0x00}}, {{0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x00}, {0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x01, 0xff, 0xff}}, {{0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0x03, 0xe0, 0x01, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}, {0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xf0, 0x07, 0x00, 0x3c, 0x80, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xe0, 0xff, 0x00, 0x00, 0x00}}, {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80}, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x7f, 0xfe, 0xff, 0x1f, 0x00, 0xfe, 0xff, 0x03, 0x00, 0x00, 0xfe, 0xff}}, {{0xff, 0xff, 0x81, 0xff, 0xff, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x83, 0xff, 0xff, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xf0}, {0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff}}, {{0x82, 0xc9, 0xfa, 0xb0, 0x68, 0x04, 0xa0, 0x00, 0x82, 0xc9, 0xfa, 0xb0, 0x68, 0x04, 0xa0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0x03, 0xfb, 0xfa, 0x8a, 0x7d, 0xdf, 0x13, 0x86, 0xe2, 0x03}, {0x82, 0xc9, 0xfa, 0xb0, 0x68, 0x04, 0xa0, 0x00, 0x82, 0xc9, 0xfa, 0xb0, 0x68, 0x04, 0xa0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0x03, 0xfb, 0xfa, 0x8a, 0x7d, 0xdf, 0x13, 0x86, 0xe2, 0x03}} }; unsigned char res[33][2][32] = { {{0x0c, 0x3b, 0x0a, 0xca, 0x8d, 0x1a, 0x2f, 0xb9, 0x8a, 0x7b, 0x53, 0x5a, 0x1f, 0xc5, 0x22, 0xa1, 0x07, 0x2a, 0x48, 0xea, 0x02, 0xeb, 0xb3, 0xd6, 0x20, 0x1e, 0x86, 0xd0, 0x95, 0xf6, 0x92, 0x35}, {0xdc, 0x90, 0x7a, 0x07, 0x2e, 0x1e, 0x44, 0x6d, 0xf8, 0x15, 0x24, 0x5b, 0x5a, 0x96, 0x37, 0x9c, 0x37, 0x7b, 0x0d, 0xac, 0x1b, 0x65, 0x58, 0x49, 0x43, 0xb7, 0x31, 0xbb, 0xa7, 0xf4, 0x97, 0x15}}, {{0xf1, 0xf7, 0x3a, 0x50, 0xe6, 0x10, 0xba, 0x22, 0x43, 0x4d, 0x1f, 0x1f, 0x7c, 0x27, 0xca, 0x9c, 0xb8, 0xb6, 0xa0, 0xfc, 0xd8, 0xc0, 0x05, 0x2f, 0xf7, 0x08, 0xe1, 0x76, 0xdd, 0xd0, 0x80, 0xc8}, {0xe3, 0x80, 0x80, 0xb8, 0xdb, 0xe3, 0xa9, 0x77, 0x00, 0xb0, 0xf5, 0x2e, 0x27, 0xe2, 0x68, 0xc4, 0x88, 0xe8, 0x04, 0xc1, 0x12, 0xbf, 0x78, 0x59, 0xe6, 0xa9, 0x7c, 0xe1, 0x81, 0xdd, 0xb9, 0xd5}}, {{0x96, 0xe2, 0xee, 0x01, 0xa6, 0x80, 0x31, 0xef, 0x5c, 0xd0, 0x19, 0xb4, 0x7d, 0x5f, 0x79, 0xab, 0xa1, 0x97, 0xd3, 0x7e, 0x33, 0xbb, 0x86, 0x55, 0x60, 0x20, 0x10, 0x0d, 0x94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x0e}, {0x43, 0xf4, 0x44, 0xe8, 0xcc, 0xc8, 0xd4, 0x54, 0x33, 0x37, 0x50, 0xf2, 0x87, 0x42, 0x2e, 0x00, 0x49, 0x60, 0x62, 0x02, 0xfd, 0x1a, 0x7c, 0xdb, 0x29, 0x6c, 0x6d, 0x54, 0x53, 0x08, 0xd1, 0xc8}}, {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}, {{0x27, 0x59, 0xc7, 0x35, 0x60, 0x71, 0xa6, 0xf1, 0x79, 0xa5, 0xfd, 0x79, 0x16, 0xf3, 0x41, 0xf0, 0x57, 0xb4, 0x02, 0x97, 0x32, 0xe7, 0xde, 0x59, 0xe2, 0x2d, 0x9b, 0x11, 0xea, 0x2c, 0x35, 0x92}, {0x27, 0x59, 0xc7, 0x35, 0x60, 0x71, 0xa6, 0xf1, 0x79, 0xa5, 0xfd, 0x79, 0x16, 0xf3, 0x41, 0xf0, 0x57, 0xb4, 0x02, 0x97, 0x32, 0xe7, 0xde, 0x59, 0xe2, 0x2d, 0x9b, 0x11, 0xea, 0x2c, 0x35, 0x92}}, {{0x28, 0x56, 0xac, 0x0e, 0x4f, 0x98, 0x09, 0xf0, 0x49, 0xfa, 0x7f, 0x84, 0xac, 0x7e, 0x50, 0x5b, 0x17, 0x43, 0x14, 0x89, 0x9c, 0x53, 0xa8, 0x94, 0x30, 0xf2, 0x11, 0x4d, 0x92, 0x14, 0x27, 0xe8}, {0x39, 0x7a, 0x84, 0x56, 0x79, 0x9d, 0xec, 0x26, 0x2c, 0x53, 0xc1, 0x94, 0xc9, 0x8d, 0x9e, 0x9d, 0x32, 0x1f, 0xdd, 0x84, 0x04, 0xe8, 0xe2, 0x0a, 0x6b, 0xbe, 0xbb, 0x42, 0x40, 0x67, 0x30, 0x6c}}, {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x45, 0x51, 0x23, 0x19, 0x50, 0xb7, 0x5f, 0xc4, 0x40, 0x2d, 0xa1, 0x73, 0x2f, 0xc9, 0xbe, 0xbd}, {0x27, 0x59, 0xc7, 0x35, 0x60, 0x71, 0xa6, 0xf1, 0x79, 0xa5, 0xfd, 0x79, 0x16, 0xf3, 0x41, 0xf0, 0x57, 0xb4, 0x02, 0x97, 0x32, 0xe7, 0xde, 0x59, 0xe2, 0x2d, 0x9b, 0x11, 0xea, 0x2c, 0x35, 0x92}}, {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0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 0xff, 0x1f, 0xb6, 0x83, 0x43, 0xd3, 0xa0, 0x2d, 0x70, 0x7a, 0x64, 0x05, 0x4c, 0xa7, 0xc1, 0xa5, 0x21, 0x51}, {0xe4, 0xf1, 0x23, 0x84, 0xe1, 0xb5, 0x9d, 0xf2, 0xb8, 0x73, 0x8b, 0x45, 0x2b, 0x35, 0x46, 0x38, 0x10, 0x2b, 0x50, 0xf8, 0x8b, 0x35, 0xcd, 0x34, 0xc8, 0x0e, 0xf6, 0xdb, 0x09, 0x35, 0xf0, 0xda}}, {{0xdb, 0x21, 0x5c, 0x8d, 0x83, 0x1d, 0xb3, 0x34, 0xc7, 0x0e, 0x43, 0xa1, 0x58, 0x79, 0x67, 0x13, 0x1e, 0x86, 0x5d, 0x89, 0x63, 0xe6, 0x0a, 0x46, 0x5c, 0x02, 0x97, 0x1b, 0x62, 0x43, 0x86, 0xf5}, {0xdb, 0x21, 0x5c, 0x8d, 0x83, 0x1d, 0xb3, 0x34, 0xc7, 0x0e, 0x43, 0xa1, 0x58, 0x79, 0x67, 0x13, 0x1e, 0x86, 0x5d, 0x89, 0x63, 0xe6, 0x0a, 0x46, 0x5c, 0x02, 0x97, 0x1b, 0x62, 0x43, 0x86, 0xf5}} }; secp256k1_scalar_set_int(&one, 1); for (i = 0; i < 33; i++) { secp256k1_scalar_set_b32(&x, chal[i][0], &overflow); CHECK(!overflow); secp256k1_scalar_set_b32(&y, chal[i][1], &overflow); CHECK(!overflow); secp256k1_scalar_set_b32(&r1, res[i][0], &overflow); CHECK(!overflow); secp256k1_scalar_set_b32(&r2, res[i][1], &overflow); CHECK(!overflow); secp256k1_scalar_mul(&z, &x, &y); CHECK(!secp256k1_scalar_check_overflow(&z)); CHECK(secp256k1_scalar_eq(&r1, &z)); if (!secp256k1_scalar_is_zero(&y)) { secp256k1_scalar_inverse(&zz, &y); CHECK(!secp256k1_scalar_check_overflow(&zz)); #if defined(USE_SCALAR_INV_NUM) secp256k1_scalar_inverse_var(&zzv, &y); CHECK(secp256k1_scalar_eq(&zzv, &zz)); #endif secp256k1_scalar_mul(&z, &z, &zz); CHECK(!secp256k1_scalar_check_overflow(&z)); CHECK(secp256k1_scalar_eq(&x, &z)); secp256k1_scalar_mul(&zz, &zz, &y); CHECK(!secp256k1_scalar_check_overflow(&zz)); CHECK(secp256k1_scalar_eq(&one, &zz)); } secp256k1_scalar_mul(&z, &x, &x); CHECK(!secp256k1_scalar_check_overflow(&z)); secp256k1_scalar_sqr(&zz, &x); CHECK(!secp256k1_scalar_check_overflow(&zz)); CHECK(secp256k1_scalar_eq(&zz, &z)); CHECK(secp256k1_scalar_eq(&r2, &zz)); } } } /***** FIELD TESTS *****/ void random_fe(secp256k1_fe *x) { unsigned char bin[32]; do { secp256k1_rand256(bin); if (secp256k1_fe_set_b32(x, bin)) { return; } } while(1); } void random_fe_test(secp256k1_fe *x) { unsigned char bin[32]; do { secp256k1_rand256_test(bin); if (secp256k1_fe_set_b32(x, bin)) { return; } } while(1); } void random_fe_non_zero(secp256k1_fe *nz) { int tries = 10; while (--tries >= 0) { random_fe(nz); secp256k1_fe_normalize(nz); if (!secp256k1_fe_is_zero(nz)) { break; } } /* Infinitesimal probability of spurious failure here */ CHECK(tries >= 0); } void random_fe_non_square(secp256k1_fe *ns) { secp256k1_fe r; random_fe_non_zero(ns); if (secp256k1_fe_sqrt(&r, ns)) { secp256k1_fe_negate(ns, ns, 1); } } int check_fe_equal(const secp256k1_fe *a, const secp256k1_fe *b) { secp256k1_fe an = *a; secp256k1_fe bn = *b; secp256k1_fe_normalize_weak(&an); secp256k1_fe_normalize_var(&bn); return secp256k1_fe_equal_var(&an, &bn); } int check_fe_inverse(const secp256k1_fe *a, const secp256k1_fe *ai) { secp256k1_fe x; secp256k1_fe one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1); secp256k1_fe_mul(&x, a, ai); return check_fe_equal(&x, &one); } void run_field_convert(void) { static const unsigned char b32[32] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40 }; static const secp256k1_fe_storage fes = SECP256K1_FE_STORAGE_CONST( 0x00010203UL, 0x04050607UL, 0x11121314UL, 0x15161718UL, 0x22232425UL, 0x26272829UL, 0x33343536UL, 0x37383940UL ); static const secp256k1_fe fe = SECP256K1_FE_CONST( 0x00010203UL, 0x04050607UL, 0x11121314UL, 0x15161718UL, 0x22232425UL, 0x26272829UL, 0x33343536UL, 0x37383940UL ); secp256k1_fe fe2; unsigned char b322[32]; secp256k1_fe_storage fes2; /* Check conversions to fe. */ CHECK(secp256k1_fe_set_b32(&fe2, b32)); CHECK(secp256k1_fe_equal_var(&fe, &fe2)); secp256k1_fe_from_storage(&fe2, &fes); CHECK(secp256k1_fe_equal_var(&fe, &fe2)); /* Check conversion from fe. */ secp256k1_fe_get_b32(b322, &fe); CHECK(memcmp(b322, b32, 32) == 0); secp256k1_fe_to_storage(&fes2, &fe); CHECK(memcmp(&fes2, &fes, sizeof(fes)) == 0); } int fe_memcmp(const secp256k1_fe *a, const secp256k1_fe *b) { secp256k1_fe t = *b; #ifdef VERIFY t.magnitude = a->magnitude; t.normalized = a->normalized; #endif return memcmp(a, &t, sizeof(secp256k1_fe)); } void run_field_misc(void) { secp256k1_fe x; secp256k1_fe y; secp256k1_fe z; secp256k1_fe q; secp256k1_fe fe5 = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 5); int i, j; for (i = 0; i < 5*count; i++) { secp256k1_fe_storage xs, ys, zs; random_fe(&x); random_fe_non_zero(&y); /* Test the fe equality and comparison operations. */ CHECK(secp256k1_fe_cmp_var(&x, &x) == 0); CHECK(secp256k1_fe_equal_var(&x, &x)); z = x; secp256k1_fe_add(&z,&y); /* Test fe conditional move; z is not normalized here. */ q = x; secp256k1_fe_cmov(&x, &z, 0); VERIFY_CHECK(!x.normalized && x.magnitude == z.magnitude); secp256k1_fe_cmov(&x, &x, 1); CHECK(fe_memcmp(&x, &z) != 0); CHECK(fe_memcmp(&x, &q) == 0); secp256k1_fe_cmov(&q, &z, 1); VERIFY_CHECK(!q.normalized && q.magnitude == z.magnitude); CHECK(fe_memcmp(&q, &z) == 0); secp256k1_fe_normalize_var(&x); secp256k1_fe_normalize_var(&z); CHECK(!secp256k1_fe_equal_var(&x, &z)); secp256k1_fe_normalize_var(&q); secp256k1_fe_cmov(&q, &z, (i&1)); VERIFY_CHECK(q.normalized && q.magnitude == 1); for (j = 0; j < 6; j++) { secp256k1_fe_negate(&z, &z, j+1); secp256k1_fe_normalize_var(&q); secp256k1_fe_cmov(&q, &z, (j&1)); VERIFY_CHECK(!q.normalized && q.magnitude == (j+2)); } secp256k1_fe_normalize_var(&z); /* Test storage conversion and conditional moves. */ secp256k1_fe_to_storage(&xs, &x); secp256k1_fe_to_storage(&ys, &y); secp256k1_fe_to_storage(&zs, &z); secp256k1_fe_storage_cmov(&zs, &xs, 0); secp256k1_fe_storage_cmov(&zs, &zs, 1); CHECK(memcmp(&xs, &zs, sizeof(xs)) != 0); secp256k1_fe_storage_cmov(&ys, &xs, 1); CHECK(memcmp(&xs, &ys, sizeof(xs)) == 0); secp256k1_fe_from_storage(&x, &xs); secp256k1_fe_from_storage(&y, &ys); secp256k1_fe_from_storage(&z, &zs); /* Test that mul_int, mul, and add agree. */ secp256k1_fe_add(&y, &x); secp256k1_fe_add(&y, &x); z = x; secp256k1_fe_mul_int(&z, 3); CHECK(check_fe_equal(&y, &z)); secp256k1_fe_add(&y, &x); secp256k1_fe_add(&z, &x); CHECK(check_fe_equal(&z, &y)); z = x; secp256k1_fe_mul_int(&z, 5); secp256k1_fe_mul(&q, &x, &fe5); CHECK(check_fe_equal(&z, &q)); secp256k1_fe_negate(&x, &x, 1); secp256k1_fe_add(&z, &x); secp256k1_fe_add(&q, &x); CHECK(check_fe_equal(&y, &z)); CHECK(check_fe_equal(&q, &y)); } } void run_field_inv(void) { secp256k1_fe x, xi, xii; int i; for (i = 0; i < 10*count; i++) { random_fe_non_zero(&x); secp256k1_fe_inv(&xi, &x); CHECK(check_fe_inverse(&x, &xi)); secp256k1_fe_inv(&xii, &xi); CHECK(check_fe_equal(&x, &xii)); } } void run_field_inv_var(void) { secp256k1_fe x, xi, xii; int i; for (i = 0; i < 10*count; i++) { random_fe_non_zero(&x); secp256k1_fe_inv_var(&xi, &x); CHECK(check_fe_inverse(&x, &xi)); secp256k1_fe_inv_var(&xii, &xi); CHECK(check_fe_equal(&x, &xii)); } } void run_field_inv_all_var(void) { secp256k1_fe x[16], xi[16], xii[16]; int i; /* Check it's safe to call for 0 elements */ secp256k1_fe_inv_all_var(xi, x, 0); for (i = 0; i < count; i++) { size_t j; size_t len = secp256k1_rand_int(15) + 1; for (j = 0; j < len; j++) { random_fe_non_zero(&x[j]); } secp256k1_fe_inv_all_var(xi, x, len); for (j = 0; j < len; j++) { CHECK(check_fe_inverse(&x[j], &xi[j])); } secp256k1_fe_inv_all_var(xii, xi, len); for (j = 0; j < len; j++) { CHECK(check_fe_equal(&x[j], &xii[j])); } } } void run_sqr(void) { secp256k1_fe x, s; { int i; secp256k1_fe_set_int(&x, 1); secp256k1_fe_negate(&x, &x, 1); for (i = 1; i <= 512; ++i) { secp256k1_fe_mul_int(&x, 2); secp256k1_fe_normalize(&x); secp256k1_fe_sqr(&s, &x); } } } void test_sqrt(const secp256k1_fe *a, const secp256k1_fe *k) { secp256k1_fe r1, r2; int v = secp256k1_fe_sqrt(&r1, a); CHECK((v == 0) == (k == NULL)); if (k != NULL) { /* Check that the returned root is +/- the given known answer */ secp256k1_fe_negate(&r2, &r1, 1); secp256k1_fe_add(&r1, k); secp256k1_fe_add(&r2, k); secp256k1_fe_normalize(&r1); secp256k1_fe_normalize(&r2); CHECK(secp256k1_fe_is_zero(&r1) || secp256k1_fe_is_zero(&r2)); } } void run_sqrt(void) { secp256k1_fe ns, x, s, t; int i; /* Check sqrt(0) is 0 */ secp256k1_fe_set_int(&x, 0); secp256k1_fe_sqr(&s, &x); test_sqrt(&s, &x); /* Check sqrt of small squares (and their negatives) */ for (i = 1; i <= 100; i++) { secp256k1_fe_set_int(&x, i); secp256k1_fe_sqr(&s, &x); test_sqrt(&s, &x); secp256k1_fe_negate(&t, &s, 1); test_sqrt(&t, NULL); } /* Consistency checks for large random values */ for (i = 0; i < 10; i++) { int j; random_fe_non_square(&ns); for (j = 0; j < count; j++) { random_fe(&x); secp256k1_fe_sqr(&s, &x); test_sqrt(&s, &x); secp256k1_fe_negate(&t, &s, 1); test_sqrt(&t, NULL); secp256k1_fe_mul(&t, &s, &ns); test_sqrt(&t, NULL); } } } /***** GROUP TESTS *****/ void ge_equals_ge(const secp256k1_ge *a, const secp256k1_ge *b) { CHECK(a->infinity == b->infinity); if (a->infinity) { return; } CHECK(secp256k1_fe_equal_var(&a->x, &b->x)); CHECK(secp256k1_fe_equal_var(&a->y, &b->y)); } /* This compares jacobian points including their Z, not just their geometric meaning. */ int gej_xyz_equals_gej(const secp256k1_gej *a, const secp256k1_gej *b) { secp256k1_gej a2; secp256k1_gej b2; int ret = 1; ret &= a->infinity == b->infinity; if (ret && !a->infinity) { a2 = *a; b2 = *b; secp256k1_fe_normalize(&a2.x); secp256k1_fe_normalize(&a2.y); secp256k1_fe_normalize(&a2.z); secp256k1_fe_normalize(&b2.x); secp256k1_fe_normalize(&b2.y); secp256k1_fe_normalize(&b2.z); ret &= secp256k1_fe_cmp_var(&a2.x, &b2.x) == 0; ret &= secp256k1_fe_cmp_var(&a2.y, &b2.y) == 0; ret &= secp256k1_fe_cmp_var(&a2.z, &b2.z) == 0; } return ret; } void ge_equals_gej(const secp256k1_ge *a, const secp256k1_gej *b) { secp256k1_fe z2s; secp256k1_fe u1, u2, s1, s2; CHECK(a->infinity == b->infinity); if (a->infinity) { return; } /* Check a.x * b.z^2 == b.x && a.y * b.z^3 == b.y, to avoid inverses. */ secp256k1_fe_sqr(&z2s, &b->z); secp256k1_fe_mul(&u1, &a->x, &z2s); u2 = b->x; secp256k1_fe_normalize_weak(&u2); secp256k1_fe_mul(&s1, &a->y, &z2s); secp256k1_fe_mul(&s1, &s1, &b->z); s2 = b->y; secp256k1_fe_normalize_weak(&s2); CHECK(secp256k1_fe_equal_var(&u1, &u2)); CHECK(secp256k1_fe_equal_var(&s1, &s2)); } void test_ge(void) { int i, i1; #ifdef USE_ENDOMORPHISM int runs = 6; #else int runs = 4; #endif /* Points: (infinity, p1, p1, -p1, -p1, p2, p2, -p2, -p2, p3, p3, -p3, -p3, p4, p4, -p4, -p4). * The second in each pair of identical points uses a random Z coordinate in the Jacobian form. * All magnitudes are randomized. * All 17*17 combinations of points are added to each other, using all applicable methods. * * When the endomorphism code is compiled in, p5 = lambda*p1 and p6 = lambda^2*p1 are added as well. */ secp256k1_ge *ge = (secp256k1_ge *)checked_malloc(&ctx->error_callback, sizeof(secp256k1_ge) * (1 + 4 * runs)); secp256k1_gej *gej = (secp256k1_gej *)checked_malloc(&ctx->error_callback, sizeof(secp256k1_gej) * (1 + 4 * runs)); secp256k1_fe *zinv = (secp256k1_fe *)checked_malloc(&ctx->error_callback, sizeof(secp256k1_fe) * (1 + 4 * runs)); secp256k1_fe zf; secp256k1_fe zfi2, zfi3; secp256k1_gej_set_infinity(&gej[0]); secp256k1_ge_clear(&ge[0]); secp256k1_ge_set_gej_var(&ge[0], &gej[0]); for (i = 0; i < runs; i++) { int j; secp256k1_ge g; random_group_element_test(&g); #ifdef USE_ENDOMORPHISM if (i >= runs - 2) { secp256k1_ge_mul_lambda(&g, &ge[1]); } if (i >= runs - 1) { secp256k1_ge_mul_lambda(&g, &g); } #endif ge[1 + 4 * i] = g; ge[2 + 4 * i] = g; secp256k1_ge_neg(&ge[3 + 4 * i], &g); secp256k1_ge_neg(&ge[4 + 4 * i], &g); secp256k1_gej_set_ge(&gej[1 + 4 * i], &ge[1 + 4 * i]); random_group_element_jacobian_test(&gej[2 + 4 * i], &ge[2 + 4 * i]); secp256k1_gej_set_ge(&gej[3 + 4 * i], &ge[3 + 4 * i]); random_group_element_jacobian_test(&gej[4 + 4 * i], &ge[4 + 4 * i]); for (j = 0; j < 4; j++) { random_field_element_magnitude(&ge[1 + j + 4 * i].x); random_field_element_magnitude(&ge[1 + j + 4 * i].y); random_field_element_magnitude(&gej[1 + j + 4 * i].x); random_field_element_magnitude(&gej[1 + j + 4 * i].y); random_field_element_magnitude(&gej[1 + j + 4 * i].z); } } /* Compute z inverses. */ { secp256k1_fe *zs = checked_malloc(&ctx->error_callback, sizeof(secp256k1_fe) * (1 + 4 * runs)); for (i = 0; i < 4 * runs + 1; i++) { if (i == 0) { /* The point at infinity does not have a meaningful z inverse. Any should do. */ do { random_field_element_test(&zs[i]); } while(secp256k1_fe_is_zero(&zs[i])); } else { zs[i] = gej[i].z; } } secp256k1_fe_inv_all_var(zinv, zs, 4 * runs + 1); free(zs); } /* Generate random zf, and zfi2 = 1/zf^2, zfi3 = 1/zf^3 */ do { random_field_element_test(&zf); } while(secp256k1_fe_is_zero(&zf)); random_field_element_magnitude(&zf); secp256k1_fe_inv_var(&zfi3, &zf); secp256k1_fe_sqr(&zfi2, &zfi3); secp256k1_fe_mul(&zfi3, &zfi3, &zfi2); for (i1 = 0; i1 < 1 + 4 * runs; i1++) { int i2; for (i2 = 0; i2 < 1 + 4 * runs; i2++) { /* Compute reference result using gej + gej (var). */ secp256k1_gej refj, resj; secp256k1_ge ref; secp256k1_fe zr; secp256k1_gej_add_var(&refj, &gej[i1], &gej[i2], secp256k1_gej_is_infinity(&gej[i1]) ? NULL : &zr); /* Check Z ratio. */ if (!secp256k1_gej_is_infinity(&gej[i1]) && !secp256k1_gej_is_infinity(&refj)) { secp256k1_fe zrz; secp256k1_fe_mul(&zrz, &zr, &gej[i1].z); CHECK(secp256k1_fe_equal_var(&zrz, &refj.z)); } secp256k1_ge_set_gej_var(&ref, &refj); /* Test gej + ge with Z ratio result (var). */ secp256k1_gej_add_ge_var(&resj, &gej[i1], &ge[i2], secp256k1_gej_is_infinity(&gej[i1]) ? NULL : &zr); ge_equals_gej(&ref, &resj); if (!secp256k1_gej_is_infinity(&gej[i1]) && !secp256k1_gej_is_infinity(&resj)) { secp256k1_fe zrz; secp256k1_fe_mul(&zrz, &zr, &gej[i1].z); CHECK(secp256k1_fe_equal_var(&zrz, &resj.z)); } /* Test gej + ge (var, with additional Z factor). */ { secp256k1_ge ge2_zfi = ge[i2]; /* the second term with x and y rescaled for z = 1/zf */ secp256k1_fe_mul(&ge2_zfi.x, &ge2_zfi.x, &zfi2); secp256k1_fe_mul(&ge2_zfi.y, &ge2_zfi.y, &zfi3); random_field_element_magnitude(&ge2_zfi.x); random_field_element_magnitude(&ge2_zfi.y); secp256k1_gej_add_zinv_var(&resj, &gej[i1], &ge2_zfi, &zf); ge_equals_gej(&ref, &resj); } /* Test gej + ge (const). */ if (i2 != 0) { /* secp256k1_gej_add_ge does not support its second argument being infinity. */ secp256k1_gej_add_ge(&resj, &gej[i1], &ge[i2]); ge_equals_gej(&ref, &resj); } /* Test doubling (var). */ if ((i1 == 0 && i2 == 0) || ((i1 + 3)/4 == (i2 + 3)/4 && ((i1 + 3)%4)/2 == ((i2 + 3)%4)/2)) { secp256k1_fe zr2; /* Normal doubling with Z ratio result. */ secp256k1_gej_double_var(&resj, &gej[i1], &zr2); ge_equals_gej(&ref, &resj); /* Check Z ratio. */ secp256k1_fe_mul(&zr2, &zr2, &gej[i1].z); CHECK(secp256k1_fe_equal_var(&zr2, &resj.z)); /* Normal doubling. */ secp256k1_gej_double_var(&resj, &gej[i2], NULL); ge_equals_gej(&ref, &resj); } /* Test adding opposites. */ if ((i1 == 0 && i2 == 0) || ((i1 + 3)/4 == (i2 + 3)/4 && ((i1 + 3)%4)/2 != ((i2 + 3)%4)/2)) { CHECK(secp256k1_ge_is_infinity(&ref)); } /* Test adding infinity. */ if (i1 == 0) { CHECK(secp256k1_ge_is_infinity(&ge[i1])); CHECK(secp256k1_gej_is_infinity(&gej[i1])); ge_equals_gej(&ref, &gej[i2]); } if (i2 == 0) { CHECK(secp256k1_ge_is_infinity(&ge[i2])); CHECK(secp256k1_gej_is_infinity(&gej[i2])); ge_equals_gej(&ref, &gej[i1]); } } } /* Test adding all points together in random order equals infinity. */ { secp256k1_gej sum = SECP256K1_GEJ_CONST_INFINITY; secp256k1_gej *gej_shuffled = (secp256k1_gej *)checked_malloc(&ctx->error_callback, (4 * runs + 1) * sizeof(secp256k1_gej)); for (i = 0; i < 4 * runs + 1; i++) { gej_shuffled[i] = gej[i]; } for (i = 0; i < 4 * runs + 1; i++) { int swap = i + secp256k1_rand_int(4 * runs + 1 - i); if (swap != i) { secp256k1_gej t = gej_shuffled[i]; gej_shuffled[i] = gej_shuffled[swap]; gej_shuffled[swap] = t; } } for (i = 0; i < 4 * runs + 1; i++) { secp256k1_gej_add_var(&sum, &sum, &gej_shuffled[i], NULL); } CHECK(secp256k1_gej_is_infinity(&sum)); free(gej_shuffled); } /* Test batch gej -> ge conversion with and without known z ratios. */ { secp256k1_fe *zr = (secp256k1_fe *)checked_malloc(&ctx->error_callback, (4 * runs + 1) * sizeof(secp256k1_fe)); secp256k1_ge *ge_set_table = (secp256k1_ge *)checked_malloc(&ctx->error_callback, (4 * runs + 1) * sizeof(secp256k1_ge)); secp256k1_ge *ge_set_all = (secp256k1_ge *)checked_malloc(&ctx->error_callback, (4 * runs + 1) * sizeof(secp256k1_ge)); for (i = 0; i < 4 * runs + 1; i++) { /* Compute gej[i + 1].z / gez[i].z (with gej[n].z taken to be 1). */ if (i < 4 * runs) { secp256k1_fe_mul(&zr[i + 1], &zinv[i], &gej[i + 1].z); } } secp256k1_ge_set_table_gej_var(ge_set_table, gej, zr, 4 * runs + 1); secp256k1_ge_set_all_gej_var(ge_set_all, gej, 4 * runs + 1, &ctx->error_callback); for (i = 0; i < 4 * runs + 1; i++) { secp256k1_fe s; random_fe_non_zero(&s); secp256k1_gej_rescale(&gej[i], &s); ge_equals_gej(&ge_set_table[i], &gej[i]); ge_equals_gej(&ge_set_all[i], &gej[i]); } free(ge_set_table); free(ge_set_all); free(zr); } free(ge); free(gej); free(zinv); } void test_add_neg_y_diff_x(void) { /* The point of this test is to check that we can add two points * whose y-coordinates are negatives of each other but whose x * coordinates differ. If the x-coordinates were the same, these * points would be negatives of each other and their sum is * infinity. This is cool because it "covers up" any degeneracy * in the addition algorithm that would cause the xy coordinates * of the sum to be wrong (since infinity has no xy coordinates). * HOWEVER, if the x-coordinates are different, infinity is the * wrong answer, and such degeneracies are exposed. This is the * root of https://github.com/livecoin-core/secp256k1/issues/257 * which this test is a regression test for. * * These points were generated in sage as * # secp256k1 params * F = FiniteField (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F) * C = EllipticCurve ([F (0), F (7)]) * G = C.lift_x(0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798) * N = FiniteField(G.order()) * * # endomorphism values (lambda is 1^{1/3} in N, beta is 1^{1/3} in F) * x = polygen(N) * lam = (1 - x^3).roots()[1][0] * * # random "bad pair" * P = C.random_element() * Q = -int(lam) * P * print " P: %x %x" % P.xy() * print " Q: %x %x" % Q.xy() * print "P + Q: %x %x" % (P + Q).xy() */ secp256k1_gej aj = SECP256K1_GEJ_CONST( 0x8d24cd95, 0x0a355af1, 0x3c543505, 0x44238d30, 0x0643d79f, 0x05a59614, 0x2f8ec030, 0xd58977cb, 0x001e337a, 0x38093dcd, 0x6c0f386d, 0x0b1293a8, 0x4d72c879, 0xd7681924, 0x44e6d2f3, 0x9190117d ); secp256k1_gej bj = SECP256K1_GEJ_CONST( 0xc7b74206, 0x1f788cd9, 0xabd0937d, 0x164a0d86, 0x95f6ff75, 0xf19a4ce9, 0xd013bd7b, 0xbf92d2a7, 0xffe1cc85, 0xc7f6c232, 0x93f0c792, 0xf4ed6c57, 0xb28d3786, 0x2897e6db, 0xbb192d0b, 0x6e6feab2 ); secp256k1_gej sumj = SECP256K1_GEJ_CONST( 0x671a63c0, 0x3efdad4c, 0x389a7798, 0x24356027, 0xb3d69010, 0x278625c3, 0x5c86d390, 0x184a8f7a, 0x5f6409c2, 0x2ce01f2b, 0x511fd375, 0x25071d08, 0xda651801, 0x70e95caf, 0x8f0d893c, 0xbed8fbbe ); secp256k1_ge b; secp256k1_gej resj; secp256k1_ge res; secp256k1_ge_set_gej(&b, &bj); secp256k1_gej_add_var(&resj, &aj, &bj, NULL); secp256k1_ge_set_gej(&res, &resj); ge_equals_gej(&res, &sumj); secp256k1_gej_add_ge(&resj, &aj, &b); secp256k1_ge_set_gej(&res, &resj); ge_equals_gej(&res, &sumj); secp256k1_gej_add_ge_var(&resj, &aj, &b, NULL); secp256k1_ge_set_gej(&res, &resj); ge_equals_gej(&res, &sumj); } void run_ge(void) { int i; for (i = 0; i < count * 32; i++) { test_ge(); } test_add_neg_y_diff_x(); } void test_ec_combine(void) { secp256k1_scalar sum = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); secp256k1_pubkey data[6]; const secp256k1_pubkey* d[6]; secp256k1_pubkey sd; secp256k1_pubkey sd2; secp256k1_gej Qj; secp256k1_ge Q; int i; for (i = 1; i <= 6; i++) { secp256k1_scalar s; random_scalar_order_test(&s); secp256k1_scalar_add(&sum, &sum, &s); secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &Qj, &s); secp256k1_ge_set_gej(&Q, &Qj); secp256k1_pubkey_save(&data[i - 1], &Q); d[i - 1] = &data[i - 1]; secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &Qj, &sum); secp256k1_ge_set_gej(&Q, &Qj); secp256k1_pubkey_save(&sd, &Q); CHECK(secp256k1_ec_pubkey_combine(ctx, &sd2, d, i) == 1); CHECK(memcmp(&sd, &sd2, sizeof(sd)) == 0); } } void run_ec_combine(void) { int i; for (i = 0; i < count * 8; i++) { test_ec_combine(); } } void test_group_decompress(const secp256k1_fe* x) { /* The input itself, normalized. */ secp256k1_fe fex = *x; secp256k1_fe fez; /* Results of set_xquad_var, set_xo_var(..., 0), set_xo_var(..., 1). */ secp256k1_ge ge_quad, ge_even, ge_odd; secp256k1_gej gej_quad; /* Return values of the above calls. */ int res_quad, res_even, res_odd; secp256k1_fe_normalize_var(&fex); res_quad = secp256k1_ge_set_xquad(&ge_quad, &fex); res_even = secp256k1_ge_set_xo_var(&ge_even, &fex, 0); res_odd = secp256k1_ge_set_xo_var(&ge_odd, &fex, 1); CHECK(res_quad == res_even); CHECK(res_quad == res_odd); if (res_quad) { secp256k1_fe_normalize_var(&ge_quad.x); secp256k1_fe_normalize_var(&ge_odd.x); secp256k1_fe_normalize_var(&ge_even.x); secp256k1_fe_normalize_var(&ge_quad.y); secp256k1_fe_normalize_var(&ge_odd.y); secp256k1_fe_normalize_var(&ge_even.y); /* No infinity allowed. */ CHECK(!ge_quad.infinity); CHECK(!ge_even.infinity); CHECK(!ge_odd.infinity); /* Check that the x coordinates check out. */ CHECK(secp256k1_fe_equal_var(&ge_quad.x, x)); CHECK(secp256k1_fe_equal_var(&ge_even.x, x)); CHECK(secp256k1_fe_equal_var(&ge_odd.x, x)); /* Check that the Y coordinate result in ge_quad is a square. */ CHECK(secp256k1_fe_is_quad_var(&ge_quad.y)); /* Check odd/even Y in ge_odd, ge_even. */ CHECK(secp256k1_fe_is_odd(&ge_odd.y)); CHECK(!secp256k1_fe_is_odd(&ge_even.y)); /* Check secp256k1_gej_has_quad_y_var. */ secp256k1_gej_set_ge(&gej_quad, &ge_quad); CHECK(secp256k1_gej_has_quad_y_var(&gej_quad)); do { random_fe_test(&fez); } while (secp256k1_fe_is_zero(&fez)); secp256k1_gej_rescale(&gej_quad, &fez); CHECK(secp256k1_gej_has_quad_y_var(&gej_quad)); secp256k1_gej_neg(&gej_quad, &gej_quad); CHECK(!secp256k1_gej_has_quad_y_var(&gej_quad)); do { random_fe_test(&fez); } while (secp256k1_fe_is_zero(&fez)); secp256k1_gej_rescale(&gej_quad, &fez); CHECK(!secp256k1_gej_has_quad_y_var(&gej_quad)); secp256k1_gej_neg(&gej_quad, &gej_quad); CHECK(secp256k1_gej_has_quad_y_var(&gej_quad)); } } void run_group_decompress(void) { int i; for (i = 0; i < count * 4; i++) { secp256k1_fe fe; random_fe_test(&fe); test_group_decompress(&fe); } } /***** ECMULT TESTS *****/ void run_ecmult_chain(void) { /* random starting point A (on the curve) */ secp256k1_gej a = SECP256K1_GEJ_CONST( 0x8b30bbe9, 0xae2a9906, 0x96b22f67, 0x0709dff3, 0x727fd8bc, 0x04d3362c, 0x6c7bf458, 0xe2846004, 0xa357ae91, 0x5c4a6528, 0x1309edf2, 0x0504740f, 0x0eb33439, 0x90216b4f, 0x81063cb6, 0x5f2f7e0f ); /* two random initial factors xn and gn */ secp256k1_scalar xn = SECP256K1_SCALAR_CONST( 0x84cc5452, 0xf7fde1ed, 0xb4d38a8c, 0xe9b1b84c, 0xcef31f14, 0x6e569be9, 0x705d357a, 0x42985407 ); secp256k1_scalar gn = SECP256K1_SCALAR_CONST( 0xa1e58d22, 0x553dcd42, 0xb2398062, 0x5d4c57a9, 0x6e9323d4, 0x2b3152e5, 0xca2c3990, 0xedc7c9de ); /* two small multipliers to be applied to xn and gn in every iteration: */ static const secp256k1_scalar xf = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0x1337); static const secp256k1_scalar gf = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0x7113); /* accumulators with the resulting coefficients to A and G */ secp256k1_scalar ae = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1); secp256k1_scalar ge = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); /* actual points */ secp256k1_gej x; secp256k1_gej x2; int i; /* the point being computed */ x = a; for (i = 0; i < 200*count; i++) { /* in each iteration, compute X = xn*X + gn*G; */ secp256k1_ecmult(&ctx->ecmult_ctx, &x, &x, &xn, &gn); /* also compute ae and ge: the actual accumulated factors for A and G */ /* if X was (ae*A+ge*G), xn*X + gn*G results in (xn*ae*A + (xn*ge+gn)*G) */ secp256k1_scalar_mul(&ae, &ae, &xn); secp256k1_scalar_mul(&ge, &ge, &xn); secp256k1_scalar_add(&ge, &ge, &gn); /* modify xn and gn */ secp256k1_scalar_mul(&xn, &xn, &xf); secp256k1_scalar_mul(&gn, &gn, &gf); /* verify */ if (i == 19999) { /* expected result after 19999 iterations */ secp256k1_gej rp = SECP256K1_GEJ_CONST( 0xD6E96687, 0xF9B10D09, 0x2A6F3543, 0x9D86CEBE, 0xA4535D0D, 0x409F5358, 0x6440BD74, 0xB933E830, 0xB95CBCA2, 0xC77DA786, 0x539BE8FD, 0x53354D2D, 0x3B4F566A, 0xE6580454, 0x07ED6015, 0xEE1B2A88 ); secp256k1_gej_neg(&rp, &rp); secp256k1_gej_add_var(&rp, &rp, &x, NULL); CHECK(secp256k1_gej_is_infinity(&rp)); } } /* redo the computation, but directly with the resulting ae and ge coefficients: */ secp256k1_ecmult(&ctx->ecmult_ctx, &x2, &a, &ae, &ge); secp256k1_gej_neg(&x2, &x2); secp256k1_gej_add_var(&x2, &x2, &x, NULL); CHECK(secp256k1_gej_is_infinity(&x2)); } void test_point_times_order(const secp256k1_gej *point) { /* X * (point + G) + (order-X) * (pointer + G) = 0 */ secp256k1_scalar x; secp256k1_scalar nx; secp256k1_scalar zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); secp256k1_scalar one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1); secp256k1_gej res1, res2; secp256k1_ge res3; unsigned char pub[65]; size_t psize = 65; random_scalar_order_test(&x); secp256k1_scalar_negate(&nx, &x); secp256k1_ecmult(&ctx->ecmult_ctx, &res1, point, &x, &x); /* calc res1 = x * point + x * G; */ secp256k1_ecmult(&ctx->ecmult_ctx, &res2, point, &nx, &nx); /* calc res2 = (order - x) * point + (order - x) * G; */ secp256k1_gej_add_var(&res1, &res1, &res2, NULL); CHECK(secp256k1_gej_is_infinity(&res1)); CHECK(secp256k1_gej_is_valid_var(&res1) == 0); secp256k1_ge_set_gej(&res3, &res1); CHECK(secp256k1_ge_is_infinity(&res3)); CHECK(secp256k1_ge_is_valid_var(&res3) == 0); CHECK(secp256k1_eckey_pubkey_serialize(&res3, pub, &psize, 0) == 0); psize = 65; CHECK(secp256k1_eckey_pubkey_serialize(&res3, pub, &psize, 1) == 0); /* check zero/one edge cases */ secp256k1_ecmult(&ctx->ecmult_ctx, &res1, point, &zero, &zero); secp256k1_ge_set_gej(&res3, &res1); CHECK(secp256k1_ge_is_infinity(&res3)); secp256k1_ecmult(&ctx->ecmult_ctx, &res1, point, &one, &zero); secp256k1_ge_set_gej(&res3, &res1); ge_equals_gej(&res3, point); secp256k1_ecmult(&ctx->ecmult_ctx, &res1, point, &zero, &one); secp256k1_ge_set_gej(&res3, &res1); ge_equals_ge(&res3, &secp256k1_ge_const_g); } void run_point_times_order(void) { int i; secp256k1_fe x = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 2); static const secp256k1_fe xr = SECP256K1_FE_CONST( 0x7603CB59, 0xB0EF6C63, 0xFE608479, 0x2A0C378C, 0xDB3233A8, 0x0F8A9A09, 0xA877DEAD, 0x31B38C45 ); for (i = 0; i < 500; i++) { secp256k1_ge p; if (secp256k1_ge_set_xo_var(&p, &x, 1)) { secp256k1_gej j; CHECK(secp256k1_ge_is_valid_var(&p)); secp256k1_gej_set_ge(&j, &p); CHECK(secp256k1_gej_is_valid_var(&j)); test_point_times_order(&j); } secp256k1_fe_sqr(&x, &x); } secp256k1_fe_normalize_var(&x); CHECK(secp256k1_fe_equal_var(&x, &xr)); } void ecmult_const_random_mult(void) { /* random starting point A (on the curve) */ secp256k1_ge a = SECP256K1_GE_CONST( 0x6d986544, 0x57ff52b8, 0xcf1b8126, 0x5b802a5b, 0xa97f9263, 0xb1e88044, 0x93351325, 0x91bc450a, 0x535c59f7, 0x325e5d2b, 0xc391fbe8, 0x3c12787c, 0x337e4a98, 0xe82a9011, 0x0123ba37, 0xdd769c7d ); /* random initial factor xn */ secp256k1_scalar xn = SECP256K1_SCALAR_CONST( 0x649d4f77, 0xc4242df7, 0x7f2079c9, 0x14530327, 0xa31b876a, 0xd2d8ce2a, 0x2236d5c6, 0xd7b2029b ); /* expected xn * A (from sage) */ secp256k1_ge expected_b = SECP256K1_GE_CONST( 0x23773684, 0x4d209dc7, 0x098a786f, 0x20d06fcd, 0x070a38bf, 0xc11ac651, 0x03004319, 0x1e2a8786, 0xed8c3b8e, 0xc06dd57b, 0xd06ea66e, 0x45492b0f, 0xb84e4e1b, 0xfb77e21f, 0x96baae2a, 0x63dec956 ); secp256k1_gej b; secp256k1_ecmult_const(&b, &a, &xn); CHECK(secp256k1_ge_is_valid_var(&a)); ge_equals_gej(&expected_b, &b); } void ecmult_const_commutativity(void) { secp256k1_scalar a; secp256k1_scalar b; secp256k1_gej res1; secp256k1_gej res2; secp256k1_ge mid1; secp256k1_ge mid2; random_scalar_order_test(&a); random_scalar_order_test(&b); secp256k1_ecmult_const(&res1, &secp256k1_ge_const_g, &a); secp256k1_ecmult_const(&res2, &secp256k1_ge_const_g, &b); secp256k1_ge_set_gej(&mid1, &res1); secp256k1_ge_set_gej(&mid2, &res2); secp256k1_ecmult_const(&res1, &mid1, &b); secp256k1_ecmult_const(&res2, &mid2, &a); secp256k1_ge_set_gej(&mid1, &res1); secp256k1_ge_set_gej(&mid2, &res2); ge_equals_ge(&mid1, &mid2); } void ecmult_const_mult_zero_one(void) { secp256k1_scalar zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0); secp256k1_scalar one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1); secp256k1_scalar negone; secp256k1_gej res1; secp256k1_ge res2; secp256k1_ge point; secp256k1_scalar_negate(&negone, &one); random_group_element_test(&point); secp256k1_ecmult_const(&res1, &point, &zero); secp256k1_ge_set_gej(&res2, &res1); CHECK(secp256k1_ge_is_infinity(&res2)); secp256k1_ecmult_const(&res1, &point, &one); secp256k1_ge_set_gej(&res2, &res1); ge_equals_ge(&res2, &point); secp256k1_ecmult_const(&res1, &point, &negone); secp256k1_gej_neg(&res1, &res1); secp256k1_ge_set_gej(&res2, &res1); ge_equals_ge(&res2, &point); } void ecmult_const_chain_multiply(void) { /* Check known result (randomly generated test problem from sage) */ const secp256k1_scalar scalar = SECP256K1_SCALAR_CONST( 0x4968d524, 0x2abf9b7a, 0x466abbcf, 0x34b11b6d, 0xcd83d307, 0x827bed62, 0x05fad0ce, 0x18fae63b ); const secp256k1_gej expected_point = SECP256K1_GEJ_CONST( 0x5494c15d, 0x32099706, 0xc2395f94, 0x348745fd, 0x757ce30e, 0x4e8c90fb, 0xa2bad184, 0xf883c69f, 0x5d195d20, 0xe191bf7f, 0x1be3e55f, 0x56a80196, 0x6071ad01, 0xf1462f66, 0xc997fa94, 0xdb858435 ); secp256k1_gej point; secp256k1_ge res; int i; secp256k1_gej_set_ge(&point, &secp256k1_ge_const_g); for (i = 0; i < 100; ++i) { secp256k1_ge tmp; secp256k1_ge_set_gej(&tmp, &point); secp256k1_ecmult_const(&point, &tmp, &scalar); } secp256k1_ge_set_gej(&res, &point); ge_equals_gej(&res, &expected_point); } void run_ecmult_const_tests(void) { ecmult_const_mult_zero_one(); ecmult_const_random_mult(); ecmult_const_commutativity(); ecmult_const_chain_multiply(); } void test_wnaf(const secp256k1_scalar *number, int w) { secp256k1_scalar x, two, t; int wnaf[256]; int zeroes = -1; int i; int bits; secp256k1_scalar_set_int(&x, 0); secp256k1_scalar_set_int(&two, 2); bits = secp256k1_ecmult_wnaf(wnaf, 256, number, w); CHECK(bits <= 256); for (i = bits-1; i >= 0; i--) { int v = wnaf[i]; secp256k1_scalar_mul(&x, &x, &two); if (v) { CHECK(zeroes == -1 || zeroes >= w-1); /* check that distance between non-zero elements is at least w-1 */ zeroes=0; CHECK((v & 1) == 1); /* check non-zero elements are odd */ CHECK(v <= (1 << (w-1)) - 1); /* check range below */ CHECK(v >= -(1 << (w-1)) - 1); /* check range above */ } else { CHECK(zeroes != -1); /* check that no unnecessary zero padding exists */ zeroes++; } if (v >= 0) { secp256k1_scalar_set_int(&t, v); } else { secp256k1_scalar_set_int(&t, -v); secp256k1_scalar_negate(&t, &t); } secp256k1_scalar_add(&x, &x, &t); } CHECK(secp256k1_scalar_eq(&x, number)); /* check that wnaf represents number */ } void test_constant_wnaf_negate(const secp256k1_scalar *number) { secp256k1_scalar neg1 = *number; secp256k1_scalar neg2 = *number; int sign1 = 1; int sign2 = 1; if (!secp256k1_scalar_get_bits(&neg1, 0, 1)) { secp256k1_scalar_negate(&neg1, &neg1); sign1 = -1; } sign2 = secp256k1_scalar_cond_negate(&neg2, secp256k1_scalar_is_even(&neg2)); CHECK(sign1 == sign2); CHECK(secp256k1_scalar_eq(&neg1, &neg2)); } void test_constant_wnaf(const secp256k1_scalar *number, int w) { secp256k1_scalar x, shift; int wnaf[256] = {0}; int i; int skew; secp256k1_scalar num = *number; secp256k1_scalar_set_int(&x, 0); secp256k1_scalar_set_int(&shift, 1 << w); /* With USE_ENDOMORPHISM on we only consider 128-bit numbers */ #ifdef USE_ENDOMORPHISM for (i = 0; i < 16; ++i) { secp256k1_scalar_shr_int(&num, 8); } #endif skew = secp256k1_wnaf_const(wnaf, num, w); for (i = WNAF_SIZE(w); i >= 0; --i) { secp256k1_scalar t; int v = wnaf[i]; CHECK(v != 0); /* check nonzero */ CHECK(v & 1); /* check parity */ CHECK(v > -(1 << w)); /* check range above */ CHECK(v < (1 << w)); /* check range below */ secp256k1_scalar_mul(&x, &x, &shift); if (v >= 0) { secp256k1_scalar_set_int(&t, v); } else { secp256k1_scalar_set_int(&t, -v); secp256k1_scalar_negate(&t, &t); } secp256k1_scalar_add(&x, &x, &t); } /* Skew num because when encoding numbers as odd we use an offset */ secp256k1_scalar_cadd_bit(&num, skew == 2, 1); CHECK(secp256k1_scalar_eq(&x, &num)); } void run_wnaf(void) { int i; secp256k1_scalar n = {{0}}; /* Sanity check: 1 and 2 are the smallest odd and even numbers and should * have easier-to-diagnose failure modes */ n.d[0] = 1; test_constant_wnaf(&n, 4); n.d[0] = 2; test_constant_wnaf(&n, 4); /* Random tests */ for (i = 0; i < count; i++) { random_scalar_order(&n); test_wnaf(&n, 4+(i%10)); test_constant_wnaf_negate(&n); test_constant_wnaf(&n, 4 + (i % 10)); } secp256k1_scalar_set_int(&n, 0); CHECK(secp256k1_scalar_cond_negate(&n, 1) == -1); CHECK(secp256k1_scalar_is_zero(&n)); CHECK(secp256k1_scalar_cond_negate(&n, 0) == 1); CHECK(secp256k1_scalar_is_zero(&n)); } void test_ecmult_constants(void) { /* Test ecmult_gen() for [0..36) and [order-36..0). */ secp256k1_scalar x; secp256k1_gej r; secp256k1_ge ng; int i; int j; secp256k1_ge_neg(&ng, &secp256k1_ge_const_g); for (i = 0; i < 36; i++ ) { secp256k1_scalar_set_int(&x, i); secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &r, &x); for (j = 0; j < i; j++) { if (j == i - 1) { ge_equals_gej(&secp256k1_ge_const_g, &r); } secp256k1_gej_add_ge(&r, &r, &ng); } CHECK(secp256k1_gej_is_infinity(&r)); } for (i = 1; i <= 36; i++ ) { secp256k1_scalar_set_int(&x, i); secp256k1_scalar_negate(&x, &x); secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &r, &x); for (j = 0; j < i; j++) { if (j == i - 1) { ge_equals_gej(&ng, &r); } secp256k1_gej_add_ge(&r, &r, &secp256k1_ge_const_g); } CHECK(secp256k1_gej_is_infinity(&r)); } } void run_ecmult_constants(void) { test_ecmult_constants(); } void test_ecmult_gen_blind(void) { /* Test ecmult_gen() blinding and confirm that the blinding changes, the affine points match, and the z's don't match. */ secp256k1_scalar key; secp256k1_scalar b; unsigned char seed32[32]; secp256k1_gej pgej; secp256k1_gej pgej2; secp256k1_gej i; secp256k1_ge pge; random_scalar_order_test(&key); secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &pgej, &key); secp256k1_rand256(seed32); b = ctx->ecmult_gen_ctx.blind; i = ctx->ecmult_gen_ctx.initial; secp256k1_ecmult_gen_blind(&ctx->ecmult_gen_ctx, seed32); CHECK(!secp256k1_scalar_eq(&b, &ctx->ecmult_gen_ctx.blind)); secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &pgej2, &key); CHECK(!gej_xyz_equals_gej(&pgej, &pgej2)); CHECK(!gej_xyz_equals_gej(&i, &ctx->ecmult_gen_ctx.initial)); secp256k1_ge_set_gej(&pge, &pgej); ge_equals_gej(&pge, &pgej2); } void test_ecmult_gen_blind_reset(void) { /* Test ecmult_gen() blinding reset and confirm that the blinding is consistent. */ secp256k1_scalar b; secp256k1_gej initial; secp256k1_ecmult_gen_blind(&ctx->ecmult_gen_ctx, 0); b = ctx->ecmult_gen_ctx.blind; initial = ctx->ecmult_gen_ctx.initial; secp256k1_ecmult_gen_blind(&ctx->ecmult_gen_ctx, 0); CHECK(secp256k1_scalar_eq(&b, &ctx->ecmult_gen_ctx.blind)); CHECK(gej_xyz_equals_gej(&initial, &ctx->ecmult_gen_ctx.initial)); } void run_ecmult_gen_blind(void) { int i; test_ecmult_gen_blind_reset(); for (i = 0; i < 10; i++) { test_ecmult_gen_blind(); } } #ifdef USE_ENDOMORPHISM /***** ENDOMORPHISH TESTS *****/ void test_scalar_split(void) { secp256k1_scalar full; secp256k1_scalar s1, slam; const unsigned char zero[32] = {0}; unsigned char tmp[32]; random_scalar_order_test(&full); secp256k1_scalar_split_lambda(&s1, &slam, &full); /* check that both are <= 128 bits in size */ if (secp256k1_scalar_is_high(&s1)) { secp256k1_scalar_negate(&s1, &s1); } if (secp256k1_scalar_is_high(&slam)) { secp256k1_scalar_negate(&slam, &slam); } secp256k1_scalar_get_b32(tmp, &s1); CHECK(memcmp(zero, tmp, 16) == 0); secp256k1_scalar_get_b32(tmp, &slam); CHECK(memcmp(zero, tmp, 16) == 0); } void run_endomorphism_tests(void) { test_scalar_split(); } #endif void ec_pubkey_parse_pointtest(const unsigned char *input, int xvalid, int yvalid) { unsigned char pubkeyc[65]; secp256k1_pubkey pubkey; secp256k1_ge ge; size_t pubkeyclen; int32_t ecount; ecount = 0; secp256k1_context_set_illegal_callback(ctx, counting_illegal_callback_fn, &ecount); for (pubkeyclen = 3; pubkeyclen <= 65; pubkeyclen++) { /* Smaller sizes are tested exhaustively elsewhere. */ int32_t i; memcpy(&pubkeyc[1], input, 64); VG_UNDEF(&pubkeyc[pubkeyclen], 65 - pubkeyclen); for (i = 0; i < 256; i++) { /* Try all type bytes. */ int xpass; int ypass; int ysign; pubkeyc[0] = i; /* What sign does this point have? */ ysign = (input[63] & 1) + 2; /* For the current type (i) do we expect parsing to work? Handled all of compressed/uncompressed/hybrid. */ xpass = xvalid && (pubkeyclen == 33) && ((i & 254) == 2); /* Do we expect a parse and re-serialize as uncompressed to give a matching y? */ ypass = xvalid && yvalid && ((i & 4) == ((pubkeyclen == 65) << 2)) && ((i == 4) || ((i & 251) == ysign)) && ((pubkeyclen == 33) || (pubkeyclen == 65)); if (xpass || ypass) { /* These cases must parse. */ unsigned char pubkeyo[65]; size_t outl; memset(&pubkey, 0, sizeof(pubkey)); VG_UNDEF(&pubkey, sizeof(pubkey)); ecount = 0; CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeyc, pubkeyclen) == 1); VG_CHECK(&pubkey, sizeof(pubkey)); outl = 65; VG_UNDEF(pubkeyo, 65); CHECK(secp256k1_ec_pubkey_serialize(ctx, pubkeyo, &outl, &pubkey, SECP256K1_EC_COMPRESSED) == 1); VG_CHECK(pubkeyo, outl); CHECK(outl == 33); CHECK(memcmp(&pubkeyo[1], &pubkeyc[1], 32) == 0); CHECK((pubkeyclen != 33) || (pubkeyo[0] == pubkeyc[0])); if (ypass) { /* This test isn't always done because we decode with alternative signs, so the y won't match. */ CHECK(pubkeyo[0] == ysign); CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 1); memset(&pubkey, 0, sizeof(pubkey)); VG_UNDEF(&pubkey, sizeof(pubkey)); secp256k1_pubkey_save(&pubkey, &ge); VG_CHECK(&pubkey, sizeof(pubkey)); outl = 65; VG_UNDEF(pubkeyo, 65); CHECK(secp256k1_ec_pubkey_serialize(ctx, pubkeyo, &outl, &pubkey, SECP256K1_EC_UNCOMPRESSED) == 1); VG_CHECK(pubkeyo, outl); CHECK(outl == 65); CHECK(pubkeyo[0] == 4); CHECK(memcmp(&pubkeyo[1], input, 64) == 0); } CHECK(ecount == 0); } else { /* These cases must fail to parse. */ memset(&pubkey, 0xfe, sizeof(pubkey)); ecount = 0; VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeyc, pubkeyclen) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(ecount == 0); CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 0); CHECK(ecount == 1); } } } secp256k1_context_set_illegal_callback(ctx, NULL, NULL); } void run_ec_pubkey_parse_test(void) { #define SECP256K1_EC_PARSE_TEST_NVALID (12) const unsigned char valid[SECP256K1_EC_PARSE_TEST_NVALID][64] = { { /* Point with leading and trailing zeros in x and y serialization. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0xef, 0xa1, 0x7b, 0x77, 0x61, 0xe1, 0xe4, 0x27, 0x06, 0x98, 0x9f, 0xb4, 0x83, 0xb8, 0xd2, 0xd4, 0x9b, 0xf7, 0x8f, 0xae, 0x98, 0x03, 0xf0, 0x99, 0xb8, 0x34, 0xed, 0xeb, 0x00 }, { /* Point with x equal to a 3rd root of unity.*/ 0x7a, 0xe9, 0x6a, 0x2b, 0x65, 0x7c, 0x07, 0x10, 0x6e, 0x64, 0x47, 0x9e, 0xac, 0x34, 0x34, 0xe9, 0x9c, 0xf0, 0x49, 0x75, 0x12, 0xf5, 0x89, 0x95, 0xc1, 0x39, 0x6c, 0x28, 0x71, 0x95, 0x01, 0xee, 0x42, 0x18, 0xf2, 0x0a, 0xe6, 0xc6, 0x46, 0xb3, 0x63, 0xdb, 0x68, 0x60, 0x58, 0x22, 0xfb, 0x14, 0x26, 0x4c, 0xa8, 0xd2, 0x58, 0x7f, 0xdd, 0x6f, 0xbc, 0x75, 0x0d, 0x58, 0x7e, 0x76, 0xa7, 0xee, }, { /* Point with largest x. (1/2) */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2c, 0x0e, 0x99, 0x4b, 0x14, 0xea, 0x72, 0xf8, 0xc3, 0xeb, 0x95, 0xc7, 0x1e, 0xf6, 0x92, 0x57, 0x5e, 0x77, 0x50, 0x58, 0x33, 0x2d, 0x7e, 0x52, 0xd0, 0x99, 0x5c, 0xf8, 0x03, 0x88, 0x71, 0xb6, 0x7d, }, { /* Point with largest x. (2/2) */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2c, 0xf1, 0x66, 0xb4, 0xeb, 0x15, 0x8d, 0x07, 0x3c, 0x14, 0x6a, 0x38, 0xe1, 0x09, 0x6d, 0xa8, 0xa1, 0x88, 0xaf, 0xa7, 0xcc, 0xd2, 0x81, 0xad, 0x2f, 0x66, 0xa3, 0x07, 0xfb, 0x77, 0x8e, 0x45, 0xb2, }, { /* Point with smallest x. (1/2) */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x42, 0x18, 0xf2, 0x0a, 0xe6, 0xc6, 0x46, 0xb3, 0x63, 0xdb, 0x68, 0x60, 0x58, 0x22, 0xfb, 0x14, 0x26, 0x4c, 0xa8, 0xd2, 0x58, 0x7f, 0xdd, 0x6f, 0xbc, 0x75, 0x0d, 0x58, 0x7e, 0x76, 0xa7, 0xee, }, { /* Point with smallest x. (2/2) */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xbd, 0xe7, 0x0d, 0xf5, 0x19, 0x39, 0xb9, 0x4c, 0x9c, 0x24, 0x97, 0x9f, 0xa7, 0xdd, 0x04, 0xeb, 0xd9, 0xb3, 0x57, 0x2d, 0xa7, 0x80, 0x22, 0x90, 0x43, 0x8a, 0xf2, 0xa6, 0x81, 0x89, 0x54, 0x41, }, { /* Point with largest y. (1/3) */ 0x1f, 0xe1, 0xe5, 0xef, 0x3f, 0xce, 0xb5, 0xc1, 0x35, 0xab, 0x77, 0x41, 0x33, 0x3c, 0xe5, 0xa6, 0xe8, 0x0d, 0x68, 0x16, 0x76, 0x53, 0xf6, 0xb2, 0xb2, 0x4b, 0xcb, 0xcf, 0xaa, 0xaf, 0xf5, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2e, }, { /* Point with largest y. (2/3) */ 0xcb, 0xb0, 0xde, 0xab, 0x12, 0x57, 0x54, 0xf1, 0xfd, 0xb2, 0x03, 0x8b, 0x04, 0x34, 0xed, 0x9c, 0xb3, 0xfb, 0x53, 0xab, 0x73, 0x53, 0x91, 0x12, 0x99, 0x94, 0xa5, 0x35, 0xd9, 0x25, 0xf6, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2e, }, { /* Point with largest y. (3/3) */ 0x14, 0x6d, 0x3b, 0x65, 0xad, 0xd9, 0xf5, 0x4c, 0xcc, 0xa2, 0x85, 0x33, 0xc8, 0x8e, 0x2c, 0xbc, 0x63, 0xf7, 0x44, 0x3e, 0x16, 0x58, 0x78, 0x3a, 0xb4, 0x1f, 0x8e, 0xf9, 0x7c, 0x2a, 0x10, 0xb5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2e, }, { /* Point with smallest y. (1/3) */ 0x1f, 0xe1, 0xe5, 0xef, 0x3f, 0xce, 0xb5, 0xc1, 0x35, 0xab, 0x77, 0x41, 0x33, 0x3c, 0xe5, 0xa6, 0xe8, 0x0d, 0x68, 0x16, 0x76, 0x53, 0xf6, 0xb2, 0xb2, 0x4b, 0xcb, 0xcf, 0xaa, 0xaf, 0xf5, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, { /* Point with smallest y. (2/3) */ 0xcb, 0xb0, 0xde, 0xab, 0x12, 0x57, 0x54, 0xf1, 0xfd, 0xb2, 0x03, 0x8b, 0x04, 0x34, 0xed, 0x9c, 0xb3, 0xfb, 0x53, 0xab, 0x73, 0x53, 0x91, 0x12, 0x99, 0x94, 0xa5, 0x35, 0xd9, 0x25, 0xf6, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, { /* Point with smallest y. (3/3) */ 0x14, 0x6d, 0x3b, 0x65, 0xad, 0xd9, 0xf5, 0x4c, 0xcc, 0xa2, 0x85, 0x33, 0xc8, 0x8e, 0x2c, 0xbc, 0x63, 0xf7, 0x44, 0x3e, 0x16, 0x58, 0x78, 0x3a, 0xb4, 0x1f, 0x8e, 0xf9, 0x7c, 0x2a, 0x10, 0xb5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; #define SECP256K1_EC_PARSE_TEST_NXVALID (4) const unsigned char onlyxvalid[SECP256K1_EC_PARSE_TEST_NXVALID][64] = { { /* Valid if y overflow ignored (y = 1 mod p). (1/3) */ 0x1f, 0xe1, 0xe5, 0xef, 0x3f, 0xce, 0xb5, 0xc1, 0x35, 0xab, 0x77, 0x41, 0x33, 0x3c, 0xe5, 0xa6, 0xe8, 0x0d, 0x68, 0x16, 0x76, 0x53, 0xf6, 0xb2, 0xb2, 0x4b, 0xcb, 0xcf, 0xaa, 0xaf, 0xf5, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x30, }, { /* Valid if y overflow ignored (y = 1 mod p). (2/3) */ 0xcb, 0xb0, 0xde, 0xab, 0x12, 0x57, 0x54, 0xf1, 0xfd, 0xb2, 0x03, 0x8b, 0x04, 0x34, 0xed, 0x9c, 0xb3, 0xfb, 0x53, 0xab, 0x73, 0x53, 0x91, 0x12, 0x99, 0x94, 0xa5, 0x35, 0xd9, 0x25, 0xf6, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x30, }, { /* Valid if y overflow ignored (y = 1 mod p). (3/3)*/ 0x14, 0x6d, 0x3b, 0x65, 0xad, 0xd9, 0xf5, 0x4c, 0xcc, 0xa2, 0x85, 0x33, 0xc8, 0x8e, 0x2c, 0xbc, 0x63, 0xf7, 0x44, 0x3e, 0x16, 0x58, 0x78, 0x3a, 0xb4, 0x1f, 0x8e, 0xf9, 0x7c, 0x2a, 0x10, 0xb5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x30, }, { /* x on curve, y is from y^2 = x^3 + 8. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 } }; #define SECP256K1_EC_PARSE_TEST_NINVALID (7) const unsigned char invalid[SECP256K1_EC_PARSE_TEST_NINVALID][64] = { { /* x is third root of -8, y is -1 * (x^3+7); also on the curve for y^2 = x^3 + 9. */ 0x0a, 0x2d, 0x2b, 0xa9, 0x35, 0x07, 0xf1, 0xdf, 0x23, 0x37, 0x70, 0xc2, 0xa7, 0x97, 0x96, 0x2c, 0xc6, 0x1f, 0x6d, 0x15, 0xda, 0x14, 0xec, 0xd4, 0x7d, 0x8d, 0x27, 0xae, 0x1c, 0xd5, 0xf8, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, { /* Valid if x overflow ignored (x = 1 mod p). */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x30, 0x42, 0x18, 0xf2, 0x0a, 0xe6, 0xc6, 0x46, 0xb3, 0x63, 0xdb, 0x68, 0x60, 0x58, 0x22, 0xfb, 0x14, 0x26, 0x4c, 0xa8, 0xd2, 0x58, 0x7f, 0xdd, 0x6f, 0xbc, 0x75, 0x0d, 0x58, 0x7e, 0x76, 0xa7, 0xee, }, { /* Valid if x overflow ignored (x = 1 mod p). */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x30, 0xbd, 0xe7, 0x0d, 0xf5, 0x19, 0x39, 0xb9, 0x4c, 0x9c, 0x24, 0x97, 0x9f, 0xa7, 0xdd, 0x04, 0xeb, 0xd9, 0xb3, 0x57, 0x2d, 0xa7, 0x80, 0x22, 0x90, 0x43, 0x8a, 0xf2, 0xa6, 0x81, 0x89, 0x54, 0x41, }, { /* x is -1, y is the result of the sqrt ladder; also on the curve for y^2 = x^3 - 5. */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2e, 0xf4, 0x84, 0x14, 0x5c, 0xb0, 0x14, 0x9b, 0x82, 0x5d, 0xff, 0x41, 0x2f, 0xa0, 0x52, 0xa8, 0x3f, 0xcb, 0x72, 0xdb, 0x61, 0xd5, 0x6f, 0x37, 0x70, 0xce, 0x06, 0x6b, 0x73, 0x49, 0xa2, 0xaa, 0x28, }, { /* x is -1, y is the result of the sqrt ladder; also on the curve for y^2 = x^3 - 5. */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2e, 0x0b, 0x7b, 0xeb, 0xa3, 0x4f, 0xeb, 0x64, 0x7d, 0xa2, 0x00, 0xbe, 0xd0, 0x5f, 0xad, 0x57, 0xc0, 0x34, 0x8d, 0x24, 0x9e, 0x2a, 0x90, 0xc8, 0x8f, 0x31, 0xf9, 0x94, 0x8b, 0xb6, 0x5d, 0x52, 0x07, }, { /* x is zero, y is the result of the sqrt ladder; also on the curve for y^2 = x^3 - 7. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x53, 0x7e, 0xef, 0xdf, 0xc1, 0x60, 0x6a, 0x07, 0x27, 0xcd, 0x69, 0xb4, 0xa7, 0x33, 0x3d, 0x38, 0xed, 0x44, 0xe3, 0x93, 0x2a, 0x71, 0x79, 0xee, 0xcb, 0x4b, 0x6f, 0xba, 0x93, 0x60, 0xdc, }, { /* x is zero, y is the result of the sqrt ladder; also on the curve for y^2 = x^3 - 7. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xac, 0x81, 0x10, 0x20, 0x3e, 0x9f, 0x95, 0xf8, 0xd8, 0x32, 0x96, 0x4b, 0x58, 0xcc, 0xc2, 0xc7, 0x12, 0xbb, 0x1c, 0x6c, 0xd5, 0x8e, 0x86, 0x11, 0x34, 0xb4, 0x8f, 0x45, 0x6c, 0x9b, 0x53 } }; const unsigned char pubkeyc[66] = { /* Serialization of G. */ 0x04, 0x79, 0xBE, 0x66, 0x7E, 0xF9, 0xDC, 0xBB, 0xAC, 0x55, 0xA0, 0x62, 0x95, 0xCE, 0x87, 0x0B, 0x07, 0x02, 0x9B, 0xFC, 0xDB, 0x2D, 0xCE, 0x28, 0xD9, 0x59, 0xF2, 0x81, 0x5B, 0x16, 0xF8, 0x17, 0x98, 0x48, 0x3A, 0xDA, 0x77, 0x26, 0xA3, 0xC4, 0x65, 0x5D, 0xA4, 0xFB, 0xFC, 0x0E, 0x11, 0x08, 0xA8, 0xFD, 0x17, 0xB4, 0x48, 0xA6, 0x85, 0x54, 0x19, 0x9C, 0x47, 0xD0, 0x8F, 0xFB, 0x10, 0xD4, 0xB8, 0x00 }; unsigned char sout[65]; unsigned char shortkey[2]; secp256k1_ge ge; secp256k1_pubkey pubkey; size_t len; int32_t i; int32_t ecount; int32_t ecount2; ecount = 0; /* Nothing should be reading this far into pubkeyc. */ VG_UNDEF(&pubkeyc[65], 1); secp256k1_context_set_illegal_callback(ctx, counting_illegal_callback_fn, &ecount); /* Zero length claimed, fail, zeroize, no illegal arg error. */ memset(&pubkey, 0xfe, sizeof(pubkey)); ecount = 0; VG_UNDEF(shortkey, 2); VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, shortkey, 0) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(ecount == 0); CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 0); CHECK(ecount == 1); /* Length one claimed, fail, zeroize, no illegal arg error. */ for (i = 0; i < 256 ; i++) { memset(&pubkey, 0xfe, sizeof(pubkey)); ecount = 0; shortkey[0] = i; VG_UNDEF(&shortkey[1], 1); VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, shortkey, 1) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(ecount == 0); CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 0); CHECK(ecount == 1); } /* Length two claimed, fail, zeroize, no illegal arg error. */ for (i = 0; i < 65536 ; i++) { memset(&pubkey, 0xfe, sizeof(pubkey)); ecount = 0; shortkey[0] = i & 255; shortkey[1] = i >> 8; VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, shortkey, 2) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(ecount == 0); CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 0); CHECK(ecount == 1); } memset(&pubkey, 0xfe, sizeof(pubkey)); ecount = 0; VG_UNDEF(&pubkey, sizeof(pubkey)); /* 33 bytes claimed on otherwise valid input starting with 0x04, fail, zeroize output, no illegal arg error. */ CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeyc, 33) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(ecount == 0); CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 0); CHECK(ecount == 1); /* NULL pubkey, illegal arg error. Pubkey isn't rewritten before this step, since it's NULL into the parser. */ CHECK(secp256k1_ec_pubkey_parse(ctx, NULL, pubkeyc, 65) == 0); CHECK(ecount == 2); /* NULL input string. Illegal arg and zeroize output. */ memset(&pubkey, 0xfe, sizeof(pubkey)); ecount = 0; VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, NULL, 65) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(ecount == 1); CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 0); CHECK(ecount == 2); /* 64 bytes claimed on input starting with 0x04, fail, zeroize output, no illegal arg error. */ memset(&pubkey, 0xfe, sizeof(pubkey)); ecount = 0; VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeyc, 64) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(ecount == 0); CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 0); CHECK(ecount == 1); /* 66 bytes claimed, fail, zeroize output, no illegal arg error. */ memset(&pubkey, 0xfe, sizeof(pubkey)); ecount = 0; VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeyc, 66) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(ecount == 0); CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 0); CHECK(ecount == 1); /* Valid parse. */ memset(&pubkey, 0, sizeof(pubkey)); ecount = 0; VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeyc, 65) == 1); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(ecount == 0); VG_UNDEF(&ge, sizeof(ge)); CHECK(secp256k1_pubkey_load(ctx, &ge, &pubkey) == 1); VG_CHECK(&ge.x, sizeof(ge.x)); VG_CHECK(&ge.y, sizeof(ge.y)); VG_CHECK(&ge.infinity, sizeof(ge.infinity)); ge_equals_ge(&secp256k1_ge_const_g, &ge); CHECK(ecount == 0); /* secp256k1_ec_pubkey_serialize illegal args. */ ecount = 0; len = 65; CHECK(secp256k1_ec_pubkey_serialize(ctx, NULL, &len, &pubkey, SECP256K1_EC_UNCOMPRESSED) == 0); CHECK(ecount == 1); CHECK(len == 0); CHECK(secp256k1_ec_pubkey_serialize(ctx, sout, NULL, &pubkey, SECP256K1_EC_UNCOMPRESSED) == 0); CHECK(ecount == 2); len = 65; VG_UNDEF(sout, 65); CHECK(secp256k1_ec_pubkey_serialize(ctx, sout, &len, NULL, SECP256K1_EC_UNCOMPRESSED) == 0); VG_CHECK(sout, 65); CHECK(ecount == 3); CHECK(len == 0); len = 65; CHECK(secp256k1_ec_pubkey_serialize(ctx, sout, &len, &pubkey, ~0) == 0); CHECK(ecount == 4); CHECK(len == 0); len = 65; VG_UNDEF(sout, 65); CHECK(secp256k1_ec_pubkey_serialize(ctx, sout, &len, &pubkey, SECP256K1_EC_UNCOMPRESSED) == 1); VG_CHECK(sout, 65); CHECK(ecount == 4); CHECK(len == 65); /* Multiple illegal args. Should still set arg error only once. */ ecount = 0; ecount2 = 11; CHECK(secp256k1_ec_pubkey_parse(ctx, NULL, NULL, 65) == 0); CHECK(ecount == 1); /* Does the illegal arg callback actually change the behavior? */ secp256k1_context_set_illegal_callback(ctx, uncounting_illegal_callback_fn, &ecount2); CHECK(secp256k1_ec_pubkey_parse(ctx, NULL, NULL, 65) == 0); CHECK(ecount == 1); CHECK(ecount2 == 10); secp256k1_context_set_illegal_callback(ctx, NULL, NULL); /* Try a bunch of prefabbed points with all possible encodings. */ for (i = 0; i < SECP256K1_EC_PARSE_TEST_NVALID; i++) { ec_pubkey_parse_pointtest(valid[i], 1, 1); } for (i = 0; i < SECP256K1_EC_PARSE_TEST_NXVALID; i++) { ec_pubkey_parse_pointtest(onlyxvalid[i], 1, 0); } for (i = 0; i < SECP256K1_EC_PARSE_TEST_NINVALID; i++) { ec_pubkey_parse_pointtest(invalid[i], 0, 0); } } void run_eckey_edge_case_test(void) { const unsigned char orderc[32] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41 }; const unsigned char zeros[sizeof(secp256k1_pubkey)] = {0x00}; unsigned char ctmp[33]; unsigned char ctmp2[33]; secp256k1_pubkey pubkey; secp256k1_pubkey pubkey2; secp256k1_pubkey pubkey_one; secp256k1_pubkey pubkey_negone; const secp256k1_pubkey *pubkeys[3]; size_t len; int32_t ecount; /* Group order is too large, reject. */ CHECK(secp256k1_ec_seckey_verify(ctx, orderc) == 0); VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey, orderc) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) == 0); /* Maximum value is too large, reject. */ memset(ctmp, 255, 32); CHECK(secp256k1_ec_seckey_verify(ctx, ctmp) == 0); memset(&pubkey, 1, sizeof(pubkey)); VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey, ctmp) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) == 0); /* Zero is too small, reject. */ memset(ctmp, 0, 32); CHECK(secp256k1_ec_seckey_verify(ctx, ctmp) == 0); memset(&pubkey, 1, sizeof(pubkey)); VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey, ctmp) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) == 0); /* One must be accepted. */ ctmp[31] = 0x01; CHECK(secp256k1_ec_seckey_verify(ctx, ctmp) == 1); memset(&pubkey, 0, sizeof(pubkey)); VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey, ctmp) == 1); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) > 0); pubkey_one = pubkey; /* Group order + 1 is too large, reject. */ memcpy(ctmp, orderc, 32); ctmp[31] = 0x42; CHECK(secp256k1_ec_seckey_verify(ctx, ctmp) == 0); memset(&pubkey, 1, sizeof(pubkey)); VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey, ctmp) == 0); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) == 0); /* -1 must be accepted. */ ctmp[31] = 0x40; CHECK(secp256k1_ec_seckey_verify(ctx, ctmp) == 1); memset(&pubkey, 0, sizeof(pubkey)); VG_UNDEF(&pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey, ctmp) == 1); VG_CHECK(&pubkey, sizeof(pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) > 0); pubkey_negone = pubkey; /* Tweak of zero leaves the value changed. */ memset(ctmp2, 0, 32); CHECK(secp256k1_ec_privkey_tweak_add(ctx, ctmp, ctmp2) == 1); CHECK(memcmp(orderc, ctmp, 31) == 0 && ctmp[31] == 0x40); memcpy(&pubkey2, &pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_tweak_add(ctx, &pubkey, ctmp2) == 1); CHECK(memcmp(&pubkey, &pubkey2, sizeof(pubkey)) == 0); /* Multiply tweak of zero zeroizes the output. */ CHECK(secp256k1_ec_privkey_tweak_mul(ctx, ctmp, ctmp2) == 0); CHECK(memcmp(zeros, ctmp, 32) == 0); CHECK(secp256k1_ec_pubkey_tweak_mul(ctx, &pubkey, ctmp2) == 0); CHECK(memcmp(&pubkey, zeros, sizeof(pubkey)) == 0); memcpy(&pubkey, &pubkey2, sizeof(pubkey)); /* Overflowing key tweak zeroizes. */ memcpy(ctmp, orderc, 32); ctmp[31] = 0x40; CHECK(secp256k1_ec_privkey_tweak_add(ctx, ctmp, orderc) == 0); CHECK(memcmp(zeros, ctmp, 32) == 0); memcpy(ctmp, orderc, 32); ctmp[31] = 0x40; CHECK(secp256k1_ec_privkey_tweak_mul(ctx, ctmp, orderc) == 0); CHECK(memcmp(zeros, ctmp, 32) == 0); memcpy(ctmp, orderc, 32); ctmp[31] = 0x40; CHECK(secp256k1_ec_pubkey_tweak_add(ctx, &pubkey, orderc) == 0); CHECK(memcmp(&pubkey, zeros, sizeof(pubkey)) == 0); memcpy(&pubkey, &pubkey2, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_tweak_mul(ctx, &pubkey, orderc) == 0); CHECK(memcmp(&pubkey, zeros, sizeof(pubkey)) == 0); memcpy(&pubkey, &pubkey2, sizeof(pubkey)); /* Private key tweaks results in a key of zero. */ ctmp2[31] = 1; CHECK(secp256k1_ec_privkey_tweak_add(ctx, ctmp2, ctmp) == 0); CHECK(memcmp(zeros, ctmp2, 32) == 0); ctmp2[31] = 1; CHECK(secp256k1_ec_pubkey_tweak_add(ctx, &pubkey, ctmp2) == 0); CHECK(memcmp(&pubkey, zeros, sizeof(pubkey)) == 0); memcpy(&pubkey, &pubkey2, sizeof(pubkey)); /* Tweak computation wraps and results in a key of 1. */ ctmp2[31] = 2; CHECK(secp256k1_ec_privkey_tweak_add(ctx, ctmp2, ctmp) == 1); CHECK(memcmp(ctmp2, zeros, 31) == 0 && ctmp2[31] == 1); ctmp2[31] = 2; CHECK(secp256k1_ec_pubkey_tweak_add(ctx, &pubkey, ctmp2) == 1); ctmp2[31] = 1; CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey2, ctmp2) == 1); CHECK(memcmp(&pubkey, &pubkey2, sizeof(pubkey)) == 0); /* Tweak mul * 2 = 1+1. */ CHECK(secp256k1_ec_pubkey_tweak_add(ctx, &pubkey, ctmp2) == 1); ctmp2[31] = 2; CHECK(secp256k1_ec_pubkey_tweak_mul(ctx, &pubkey2, ctmp2) == 1); CHECK(memcmp(&pubkey, &pubkey2, sizeof(pubkey)) == 0); /* Test argument errors. */ ecount = 0; secp256k1_context_set_illegal_callback(ctx, counting_illegal_callback_fn, &ecount); CHECK(ecount == 0); /* Zeroize pubkey on parse error. */ memset(&pubkey, 0, 32); CHECK(secp256k1_ec_pubkey_tweak_add(ctx, &pubkey, ctmp2) == 0); CHECK(ecount == 1); CHECK(memcmp(&pubkey, zeros, sizeof(pubkey)) == 0); memcpy(&pubkey, &pubkey2, sizeof(pubkey)); memset(&pubkey2, 0, 32); CHECK(secp256k1_ec_pubkey_tweak_mul(ctx, &pubkey2, ctmp2) == 0); CHECK(ecount == 2); CHECK(memcmp(&pubkey2, zeros, sizeof(pubkey2)) == 0); /* Plain argument errors. */ ecount = 0; CHECK(secp256k1_ec_seckey_verify(ctx, ctmp) == 1); CHECK(ecount == 0); CHECK(secp256k1_ec_seckey_verify(ctx, NULL) == 0); CHECK(ecount == 1); ecount = 0; memset(ctmp2, 0, 32); ctmp2[31] = 4; CHECK(secp256k1_ec_pubkey_tweak_add(ctx, NULL, ctmp2) == 0); CHECK(ecount == 1); CHECK(secp256k1_ec_pubkey_tweak_add(ctx, &pubkey, NULL) == 0); CHECK(ecount == 2); ecount = 0; memset(ctmp2, 0, 32); ctmp2[31] = 4; CHECK(secp256k1_ec_pubkey_tweak_mul(ctx, NULL, ctmp2) == 0); CHECK(ecount == 1); CHECK(secp256k1_ec_pubkey_tweak_mul(ctx, &pubkey, NULL) == 0); CHECK(ecount == 2); ecount = 0; memset(ctmp2, 0, 32); CHECK(secp256k1_ec_privkey_tweak_add(ctx, NULL, ctmp2) == 0); CHECK(ecount == 1); CHECK(secp256k1_ec_privkey_tweak_add(ctx, ctmp, NULL) == 0); CHECK(ecount == 2); ecount = 0; memset(ctmp2, 0, 32); ctmp2[31] = 1; CHECK(secp256k1_ec_privkey_tweak_mul(ctx, NULL, ctmp2) == 0); CHECK(ecount == 1); CHECK(secp256k1_ec_privkey_tweak_mul(ctx, ctmp, NULL) == 0); CHECK(ecount == 2); ecount = 0; CHECK(secp256k1_ec_pubkey_create(ctx, NULL, ctmp) == 0); CHECK(ecount == 1); memset(&pubkey, 1, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey, NULL) == 0); CHECK(ecount == 2); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) == 0); /* secp256k1_ec_pubkey_combine tests. */ ecount = 0; pubkeys[0] = &pubkey_one; VG_UNDEF(&pubkeys[0], sizeof(secp256k1_pubkey *)); VG_UNDEF(&pubkeys[1], sizeof(secp256k1_pubkey *)); VG_UNDEF(&pubkeys[2], sizeof(secp256k1_pubkey *)); memset(&pubkey, 255, sizeof(secp256k1_pubkey)); VG_UNDEF(&pubkey, sizeof(secp256k1_pubkey)); CHECK(secp256k1_ec_pubkey_combine(ctx, &pubkey, pubkeys, 0) == 0); VG_CHECK(&pubkey, sizeof(secp256k1_pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) == 0); CHECK(ecount == 1); CHECK(secp256k1_ec_pubkey_combine(ctx, NULL, pubkeys, 1) == 0); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) == 0); CHECK(ecount == 2); memset(&pubkey, 255, sizeof(secp256k1_pubkey)); VG_UNDEF(&pubkey, sizeof(secp256k1_pubkey)); CHECK(secp256k1_ec_pubkey_combine(ctx, &pubkey, NULL, 1) == 0); VG_CHECK(&pubkey, sizeof(secp256k1_pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) == 0); CHECK(ecount == 3); pubkeys[0] = &pubkey_negone; memset(&pubkey, 255, sizeof(secp256k1_pubkey)); VG_UNDEF(&pubkey, sizeof(secp256k1_pubkey)); CHECK(secp256k1_ec_pubkey_combine(ctx, &pubkey, pubkeys, 1) == 1); VG_CHECK(&pubkey, sizeof(secp256k1_pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) > 0); CHECK(ecount == 3); len = 33; CHECK(secp256k1_ec_pubkey_serialize(ctx, ctmp, &len, &pubkey, SECP256K1_EC_COMPRESSED) == 1); CHECK(secp256k1_ec_pubkey_serialize(ctx, ctmp2, &len, &pubkey_negone, SECP256K1_EC_COMPRESSED) == 1); CHECK(memcmp(ctmp, ctmp2, 33) == 0); /* Result is infinity. */ pubkeys[0] = &pubkey_one; pubkeys[1] = &pubkey_negone; memset(&pubkey, 255, sizeof(secp256k1_pubkey)); VG_UNDEF(&pubkey, sizeof(secp256k1_pubkey)); CHECK(secp256k1_ec_pubkey_combine(ctx, &pubkey, pubkeys, 2) == 0); VG_CHECK(&pubkey, sizeof(secp256k1_pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) == 0); CHECK(ecount == 3); /* Passes through infinity but comes out one. */ pubkeys[2] = &pubkey_one; memset(&pubkey, 255, sizeof(secp256k1_pubkey)); VG_UNDEF(&pubkey, sizeof(secp256k1_pubkey)); CHECK(secp256k1_ec_pubkey_combine(ctx, &pubkey, pubkeys, 3) == 1); VG_CHECK(&pubkey, sizeof(secp256k1_pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) > 0); CHECK(ecount == 3); len = 33; CHECK(secp256k1_ec_pubkey_serialize(ctx, ctmp, &len, &pubkey, SECP256K1_EC_COMPRESSED) == 1); CHECK(secp256k1_ec_pubkey_serialize(ctx, ctmp2, &len, &pubkey_one, SECP256K1_EC_COMPRESSED) == 1); CHECK(memcmp(ctmp, ctmp2, 33) == 0); /* Adds to two. */ pubkeys[1] = &pubkey_one; memset(&pubkey, 255, sizeof(secp256k1_pubkey)); VG_UNDEF(&pubkey, sizeof(secp256k1_pubkey)); CHECK(secp256k1_ec_pubkey_combine(ctx, &pubkey, pubkeys, 2) == 1); VG_CHECK(&pubkey, sizeof(secp256k1_pubkey)); CHECK(memcmp(&pubkey, zeros, sizeof(secp256k1_pubkey)) > 0); CHECK(ecount == 3); secp256k1_context_set_illegal_callback(ctx, NULL, NULL); } void random_sign(secp256k1_scalar *sigr, secp256k1_scalar *sigs, const secp256k1_scalar *key, const secp256k1_scalar *msg, int *recid) { secp256k1_scalar nonce; do { random_scalar_order_test(&nonce); } while(!secp256k1_ecdsa_sig_sign(&ctx->ecmult_gen_ctx, sigr, sigs, key, msg, &nonce, recid)); } void test_ecdsa_sign_verify(void) { secp256k1_gej pubj; secp256k1_ge pub; secp256k1_scalar one; secp256k1_scalar msg, key; secp256k1_scalar sigr, sigs; int recid; int getrec; random_scalar_order_test(&msg); random_scalar_order_test(&key); secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &pubj, &key); secp256k1_ge_set_gej(&pub, &pubj); getrec = secp256k1_rand_bits(1); random_sign(&sigr, &sigs, &key, &msg, getrec?&recid:NULL); if (getrec) { CHECK(recid >= 0 && recid < 4); } CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sigr, &sigs, &pub, &msg)); secp256k1_scalar_set_int(&one, 1); secp256k1_scalar_add(&msg, &msg, &one); CHECK(!secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sigr, &sigs, &pub, &msg)); } void run_ecdsa_sign_verify(void) { int i; for (i = 0; i < 10*count; i++) { test_ecdsa_sign_verify(); } } /** Dummy nonce generation function that just uses a precomputed nonce, and fails if it is not accepted. Use only for testing. */ static int precomputed_nonce_function(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) { (void)msg32; (void)key32; (void)algo16; memcpy(nonce32, data, 32); return (counter == 0); } static int nonce_function_test_fail(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) { /* Dummy nonce generator that has a fatal error on the first counter value. */ if (counter == 0) { return 0; } return nonce_function_rfc6979(nonce32, msg32, key32, algo16, data, counter - 1); } static int nonce_function_test_retry(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) { /* Dummy nonce generator that produces unacceptable nonces for the first several counter values. */ if (counter < 3) { memset(nonce32, counter==0 ? 0 : 255, 32); if (counter == 2) { nonce32[31]--; } return 1; } if (counter < 5) { static const unsigned char order[] = { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE, 0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B, 0xBF,0xD2,0x5E,0x8C,0xD0,0x36,0x41,0x41 }; memcpy(nonce32, order, 32); if (counter == 4) { nonce32[31]++; } return 1; } /* Retry rate of 6979 is negligible esp. as we only call this in deterministic tests. */ /* If someone does fine a case where it retries for secp256k1, we'd like to know. */ if (counter > 5) { return 0; } return nonce_function_rfc6979(nonce32, msg32, key32, algo16, data, counter - 5); } int is_empty_signature(const secp256k1_ecdsa_signature *sig) { static const unsigned char res[sizeof(secp256k1_ecdsa_signature)] = {0}; return memcmp(sig, res, sizeof(secp256k1_ecdsa_signature)) == 0; } void test_ecdsa_end_to_end(void) { unsigned char extra[32] = {0x00}; unsigned char privkey[32]; unsigned char message[32]; unsigned char privkey2[32]; secp256k1_ecdsa_signature signature[6]; secp256k1_scalar r, s; unsigned char sig[74]; size_t siglen = 74; unsigned char pubkeyc[65]; size_t pubkeyclen = 65; secp256k1_pubkey pubkey; secp256k1_pubkey pubkey_tmp; unsigned char seckey[300]; size_t seckeylen = 300; /* Generate a random key and message. */ { secp256k1_scalar msg, key; random_scalar_order_test(&msg); random_scalar_order_test(&key); secp256k1_scalar_get_b32(privkey, &key); secp256k1_scalar_get_b32(message, &msg); } /* Construct and verify corresponding public key. */ CHECK(secp256k1_ec_seckey_verify(ctx, privkey) == 1); CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey, privkey) == 1); /* Verify exporting and importing public key. */ CHECK(secp256k1_ec_pubkey_serialize(ctx, pubkeyc, &pubkeyclen, &pubkey, secp256k1_rand_bits(1) == 1 ? SECP256K1_EC_COMPRESSED : SECP256K1_EC_UNCOMPRESSED)); memset(&pubkey, 0, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_parse(ctx, &pubkey, pubkeyc, pubkeyclen) == 1); /* Verify negation changes the key and changes it back */ memcpy(&pubkey_tmp, &pubkey, sizeof(pubkey)); CHECK(secp256k1_ec_pubkey_negate(ctx, &pubkey_tmp) == 1); CHECK(memcmp(&pubkey_tmp, &pubkey, sizeof(pubkey)) != 0); CHECK(secp256k1_ec_pubkey_negate(ctx, &pubkey_tmp) == 1); CHECK(memcmp(&pubkey_tmp, &pubkey, sizeof(pubkey)) == 0); /* Verify private key import and export. */ CHECK(ec_privkey_export_der(ctx, seckey, &seckeylen, privkey, secp256k1_rand_bits(1) == 1)); CHECK(ec_privkey_import_der(ctx, privkey2, seckey, seckeylen) == 1); CHECK(memcmp(privkey, privkey2, 32) == 0); /* Optionally tweak the keys using addition. */ if (secp256k1_rand_int(3) == 0) { int ret1; int ret2; unsigned char rnd[32]; secp256k1_pubkey pubkey2; secp256k1_rand256_test(rnd); ret1 = secp256k1_ec_privkey_tweak_add(ctx, privkey, rnd); ret2 = secp256k1_ec_pubkey_tweak_add(ctx, &pubkey, rnd); CHECK(ret1 == ret2); if (ret1 == 0) { return; } CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey2, privkey) == 1); CHECK(memcmp(&pubkey, &pubkey2, sizeof(pubkey)) == 0); } /* Optionally tweak the keys using multiplication. */ if (secp256k1_rand_int(3) == 0) { int ret1; int ret2; unsigned char rnd[32]; secp256k1_pubkey pubkey2; secp256k1_rand256_test(rnd); ret1 = secp256k1_ec_privkey_tweak_mul(ctx, privkey, rnd); ret2 = secp256k1_ec_pubkey_tweak_mul(ctx, &pubkey, rnd); CHECK(ret1 == ret2); if (ret1 == 0) { return; } CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey2, privkey) == 1); CHECK(memcmp(&pubkey, &pubkey2, sizeof(pubkey)) == 0); } /* Sign. */ CHECK(secp256k1_ecdsa_sign(ctx, &signature[0], message, privkey, NULL, NULL) == 1); CHECK(secp256k1_ecdsa_sign(ctx, &signature[4], message, privkey, NULL, NULL) == 1); CHECK(secp256k1_ecdsa_sign(ctx, &signature[1], message, privkey, NULL, extra) == 1); extra[31] = 1; CHECK(secp256k1_ecdsa_sign(ctx, &signature[2], message, privkey, NULL, extra) == 1); extra[31] = 0; extra[0] = 1; CHECK(secp256k1_ecdsa_sign(ctx, &signature[3], message, privkey, NULL, extra) == 1); CHECK(memcmp(&signature[0], &signature[4], sizeof(signature[0])) == 0); CHECK(memcmp(&signature[0], &signature[1], sizeof(signature[0])) != 0); CHECK(memcmp(&signature[0], &signature[2], sizeof(signature[0])) != 0); CHECK(memcmp(&signature[0], &signature[3], sizeof(signature[0])) != 0); CHECK(memcmp(&signature[1], &signature[2], sizeof(signature[0])) != 0); CHECK(memcmp(&signature[1], &signature[3], sizeof(signature[0])) != 0); CHECK(memcmp(&signature[2], &signature[3], sizeof(signature[0])) != 0); /* Verify. */ CHECK(secp256k1_ecdsa_verify(ctx, &signature[0], message, &pubkey) == 1); CHECK(secp256k1_ecdsa_verify(ctx, &signature[1], message, &pubkey) == 1); CHECK(secp256k1_ecdsa_verify(ctx, &signature[2], message, &pubkey) == 1); CHECK(secp256k1_ecdsa_verify(ctx, &signature[3], message, &pubkey) == 1); /* Test lower-S form, malleate, verify and fail, test again, malleate again */ CHECK(!secp256k1_ecdsa_signature_normalize(ctx, NULL, &signature[0])); secp256k1_ecdsa_signature_load(ctx, &r, &s, &signature[0]); secp256k1_scalar_negate(&s, &s); secp256k1_ecdsa_signature_save(&signature[5], &r, &s); CHECK(secp256k1_ecdsa_verify(ctx, &signature[5], message, &pubkey) == 0); CHECK(secp256k1_ecdsa_signature_normalize(ctx, NULL, &signature[5])); CHECK(secp256k1_ecdsa_signature_normalize(ctx, &signature[5], &signature[5])); CHECK(!secp256k1_ecdsa_signature_normalize(ctx, NULL, &signature[5])); CHECK(!secp256k1_ecdsa_signature_normalize(ctx, &signature[5], &signature[5])); CHECK(secp256k1_ecdsa_verify(ctx, &signature[5], message, &pubkey) == 1); secp256k1_scalar_negate(&s, &s); secp256k1_ecdsa_signature_save(&signature[5], &r, &s); CHECK(!secp256k1_ecdsa_signature_normalize(ctx, NULL, &signature[5])); CHECK(secp256k1_ecdsa_verify(ctx, &signature[5], message, &pubkey) == 1); CHECK(memcmp(&signature[5], &signature[0], 64) == 0); /* Serialize/parse DER and verify again */ CHECK(secp256k1_ecdsa_signature_serialize_der(ctx, sig, &siglen, &signature[0]) == 1); memset(&signature[0], 0, sizeof(signature[0])); CHECK(secp256k1_ecdsa_signature_parse_der(ctx, &signature[0], sig, siglen) == 1); CHECK(secp256k1_ecdsa_verify(ctx, &signature[0], message, &pubkey) == 1); /* Serialize/destroy/parse DER and verify again. */ siglen = 74; CHECK(secp256k1_ecdsa_signature_serialize_der(ctx, sig, &siglen, &signature[0]) == 1); sig[secp256k1_rand_int(siglen)] += 1 + secp256k1_rand_int(255); CHECK(secp256k1_ecdsa_signature_parse_der(ctx, &signature[0], sig, siglen) == 0 || secp256k1_ecdsa_verify(ctx, &signature[0], message, &pubkey) == 0); } void test_random_pubkeys(void) { secp256k1_ge elem; secp256k1_ge elem2; unsigned char in[65]; /* Generate some randomly sized pubkeys. */ size_t len = secp256k1_rand_bits(2) == 0 ? 65 : 33; if (secp256k1_rand_bits(2) == 0) { len = secp256k1_rand_bits(6); } if (len == 65) { in[0] = secp256k1_rand_bits(1) ? 4 : (secp256k1_rand_bits(1) ? 6 : 7); } else { in[0] = secp256k1_rand_bits(1) ? 2 : 3; } if (secp256k1_rand_bits(3) == 0) { in[0] = secp256k1_rand_bits(8); } if (len > 1) { secp256k1_rand256(&in[1]); } if (len > 33) { secp256k1_rand256(&in[33]); } if (secp256k1_eckey_pubkey_parse(&elem, in, len)) { unsigned char out[65]; unsigned char firstb; int res; size_t size = len; firstb = in[0]; /* If the pubkey can be parsed, it should round-trip... */ CHECK(secp256k1_eckey_pubkey_serialize(&elem, out, &size, len == 33)); CHECK(size == len); CHECK(memcmp(&in[1], &out[1], len-1) == 0); /* ... except for the type of hybrid inputs. */ if ((in[0] != 6) && (in[0] != 7)) { CHECK(in[0] == out[0]); } size = 65; CHECK(secp256k1_eckey_pubkey_serialize(&elem, in, &size, 0)); CHECK(size == 65); CHECK(secp256k1_eckey_pubkey_parse(&elem2, in, size)); ge_equals_ge(&elem,&elem2); /* Check that the X9.62 hybrid type is checked. */ in[0] = secp256k1_rand_bits(1) ? 6 : 7; res = secp256k1_eckey_pubkey_parse(&elem2, in, size); if (firstb == 2 || firstb == 3) { if (in[0] == firstb + 4) { CHECK(res); } else { CHECK(!res); } } if (res) { ge_equals_ge(&elem,&elem2); CHECK(secp256k1_eckey_pubkey_serialize(&elem, out, &size, 0)); CHECK(memcmp(&in[1], &out[1], 64) == 0); } } } void run_random_pubkeys(void) { int i; for (i = 0; i < 10*count; i++) { test_random_pubkeys(); } } void run_ecdsa_end_to_end(void) { int i; for (i = 0; i < 64*count; i++) { test_ecdsa_end_to_end(); } } int test_ecdsa_der_parse(const unsigned char *sig, size_t siglen, int certainly_der, int certainly_not_der) { static const unsigned char zeroes[32] = {0}; #ifdef ENABLE_OPENSSL_TESTS static const unsigned char max_scalar[32] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x40 }; #endif int ret = 0; secp256k1_ecdsa_signature sig_der; unsigned char roundtrip_der[2048]; unsigned char compact_der[64]; size_t len_der = 2048; int parsed_der = 0, valid_der = 0, roundtrips_der = 0; secp256k1_ecdsa_signature sig_der_lax; unsigned char roundtrip_der_lax[2048]; unsigned char compact_der_lax[64]; size_t len_der_lax = 2048; int parsed_der_lax = 0, valid_der_lax = 0, roundtrips_der_lax = 0; #ifdef ENABLE_OPENSSL_TESTS ECDSA_SIG *sig_openssl; const unsigned char *sigptr; unsigned char roundtrip_openssl[2048]; int len_openssl = 2048; int parsed_openssl, valid_openssl = 0, roundtrips_openssl = 0; #endif parsed_der = secp256k1_ecdsa_signature_parse_der(ctx, &sig_der, sig, siglen); if (parsed_der) { ret |= (!secp256k1_ecdsa_signature_serialize_compact(ctx, compact_der, &sig_der)) << 0; valid_der = (memcmp(compact_der, zeroes, 32) != 0) && (memcmp(compact_der + 32, zeroes, 32) != 0); } if (valid_der) { ret |= (!secp256k1_ecdsa_signature_serialize_der(ctx, roundtrip_der, &len_der, &sig_der)) << 1; roundtrips_der = (len_der == siglen) && memcmp(roundtrip_der, sig, siglen) == 0; } parsed_der_lax = ecdsa_signature_parse_der_lax(ctx, &sig_der_lax, sig, siglen); if (parsed_der_lax) { ret |= (!secp256k1_ecdsa_signature_serialize_compact(ctx, compact_der_lax, &sig_der_lax)) << 10; valid_der_lax = (memcmp(compact_der_lax, zeroes, 32) != 0) && (memcmp(compact_der_lax + 32, zeroes, 32) != 0); } if (valid_der_lax) { ret |= (!secp256k1_ecdsa_signature_serialize_der(ctx, roundtrip_der_lax, &len_der_lax, &sig_der_lax)) << 11; roundtrips_der_lax = (len_der_lax == siglen) && memcmp(roundtrip_der_lax, sig, siglen) == 0; } if (certainly_der) { ret |= (!parsed_der) << 2; } if (certainly_not_der) { ret |= (parsed_der) << 17; } if (valid_der) { ret |= (!roundtrips_der) << 3; } if (valid_der) { ret |= (!roundtrips_der_lax) << 12; ret |= (len_der != len_der_lax) << 13; ret |= (memcmp(roundtrip_der_lax, roundtrip_der, len_der) != 0) << 14; } ret |= (roundtrips_der != roundtrips_der_lax) << 15; if (parsed_der) { ret |= (!parsed_der_lax) << 16; } #ifdef ENABLE_OPENSSL_TESTS sig_openssl = ECDSA_SIG_new(); sigptr = sig; parsed_openssl = (d2i_ECDSA_SIG(&sig_openssl, &sigptr, siglen) != NULL); if (parsed_openssl) { valid_openssl = !BN_is_negative(sig_openssl->r) && !BN_is_negative(sig_openssl->s) && BN_num_bits(sig_openssl->r) > 0 && BN_num_bits(sig_openssl->r) <= 256 && BN_num_bits(sig_openssl->s) > 0 && BN_num_bits(sig_openssl->s) <= 256; if (valid_openssl) { unsigned char tmp[32] = {0}; BN_bn2bin(sig_openssl->r, tmp + 32 - BN_num_bytes(sig_openssl->r)); valid_openssl = memcmp(tmp, max_scalar, 32) < 0; } if (valid_openssl) { unsigned char tmp[32] = {0}; BN_bn2bin(sig_openssl->s, tmp + 32 - BN_num_bytes(sig_openssl->s)); valid_openssl = memcmp(tmp, max_scalar, 32) < 0; } } len_openssl = i2d_ECDSA_SIG(sig_openssl, NULL); if (len_openssl <= 2048) { unsigned char *ptr = roundtrip_openssl; CHECK(i2d_ECDSA_SIG(sig_openssl, &ptr) == len_openssl); roundtrips_openssl = valid_openssl && ((size_t)len_openssl == siglen) && (memcmp(roundtrip_openssl, sig, siglen) == 0); } else { len_openssl = 0; } ECDSA_SIG_free(sig_openssl); ret |= (parsed_der && !parsed_openssl) << 4; ret |= (valid_der && !valid_openssl) << 5; ret |= (roundtrips_openssl && !parsed_der) << 6; ret |= (roundtrips_der != roundtrips_openssl) << 7; if (roundtrips_openssl) { ret |= (len_der != (size_t)len_openssl) << 8; ret |= (memcmp(roundtrip_der, roundtrip_openssl, len_der) != 0) << 9; } #endif return ret; } static void assign_big_endian(unsigned char *ptr, size_t ptrlen, uint32_t val) { size_t i; for (i = 0; i < ptrlen; i++) { int shift = ptrlen - 1 - i; if (shift >= 4) { ptr[i] = 0; } else { ptr[i] = (val >> shift) & 0xFF; } } } static void damage_array(unsigned char *sig, size_t *len) { int pos; int action = secp256k1_rand_bits(3); if (action < 1 && *len > 3) { /* Delete a byte. */ pos = secp256k1_rand_int(*len); memmove(sig + pos, sig + pos + 1, *len - pos - 1); (*len)--; return; } else if (action < 2 && *len < 2048) { /* Insert a byte. */ pos = secp256k1_rand_int(1 + *len); memmove(sig + pos + 1, sig + pos, *len - pos); sig[pos] = secp256k1_rand_bits(8); (*len)++; return; } else if (action < 4) { /* Modify a byte. */ sig[secp256k1_rand_int(*len)] += 1 + secp256k1_rand_int(255); return; } else { /* action < 8 */ /* Modify a bit. */ sig[secp256k1_rand_int(*len)] ^= 1 << secp256k1_rand_bits(3); return; } } static void random_ber_signature(unsigned char *sig, size_t *len, int* certainly_der, int* certainly_not_der) { int der; int nlow[2], nlen[2], nlenlen[2], nhbit[2], nhbyte[2], nzlen[2]; size_t tlen, elen, glen; int indet; int n; *len = 0; der = secp256k1_rand_bits(2) == 0; *certainly_der = der; *certainly_not_der = 0; indet = der ? 0 : secp256k1_rand_int(10) == 0; for (n = 0; n < 2; n++) { /* We generate two classes of numbers: nlow==1 "low" ones (up to 32 bytes), nlow==0 "high" ones (32 bytes with 129 top bits set, or larger than 32 bytes) */ nlow[n] = der ? 1 : (secp256k1_rand_bits(3) != 0); /* The length of the number in bytes (the first byte of which will always be nonzero) */ nlen[n] = nlow[n] ? secp256k1_rand_int(33) : 32 + secp256k1_rand_int(200) * secp256k1_rand_int(8) / 8; CHECK(nlen[n] <= 232); /* The top bit of the number. */ nhbit[n] = (nlow[n] == 0 && nlen[n] == 32) ? 1 : (nlen[n] == 0 ? 0 : secp256k1_rand_bits(1)); /* The top byte of the number (after the potential hardcoded 16 0xFF characters for "high" 32 bytes numbers) */ nhbyte[n] = nlen[n] == 0 ? 0 : (nhbit[n] ? 128 + secp256k1_rand_bits(7) : 1 + secp256k1_rand_int(127)); /* The number of zero bytes in front of the number (which is 0 or 1 in case of DER, otherwise we extend up to 300 bytes) */ nzlen[n] = der ? ((nlen[n] == 0 || nhbit[n]) ? 1 : 0) : (nlow[n] ? secp256k1_rand_int(3) : secp256k1_rand_int(300 - nlen[n]) * secp256k1_rand_int(8) / 8); if (nzlen[n] > ((nlen[n] == 0 || nhbit[n]) ? 1 : 0)) { *certainly_not_der = 1; } CHECK(nlen[n] + nzlen[n] <= 300); /* The length of the length descriptor for the number. 0 means short encoding, anything else is long encoding. */ nlenlen[n] = nlen[n] + nzlen[n] < 128 ? 0 : (nlen[n] + nzlen[n] < 256 ? 1 : 2); if (!der) { /* nlenlen[n] max 127 bytes */ int add = secp256k1_rand_int(127 - nlenlen[n]) * secp256k1_rand_int(16) * secp256k1_rand_int(16) / 256; nlenlen[n] += add; if (add != 0) { *certainly_not_der = 1; } } CHECK(nlen[n] + nzlen[n] + nlenlen[n] <= 427); } /* The total length of the data to go, so far */ tlen = 2 + nlenlen[0] + nlen[0] + nzlen[0] + 2 + nlenlen[1] + nlen[1] + nzlen[1]; CHECK(tlen <= 856); /* The length of the garbage inside the tuple. */ elen = (der || indet) ? 0 : secp256k1_rand_int(980 - tlen) * secp256k1_rand_int(8) / 8; if (elen != 0) { *certainly_not_der = 1; } tlen += elen; CHECK(tlen <= 980); /* The length of the garbage after the end of the tuple. */ glen = der ? 0 : secp256k1_rand_int(990 - tlen) * secp256k1_rand_int(8) / 8; if (glen != 0) { *certainly_not_der = 1; } CHECK(tlen + glen <= 990); /* Write the tuple header. */ sig[(*len)++] = 0x30; if (indet) { /* Indeterminate length */ sig[(*len)++] = 0x80; *certainly_not_der = 1; } else { int tlenlen = tlen < 128 ? 0 : (tlen < 256 ? 1 : 2); if (!der) { int add = secp256k1_rand_int(127 - tlenlen) * secp256k1_rand_int(16) * secp256k1_rand_int(16) / 256; tlenlen += add; if (add != 0) { *certainly_not_der = 1; } } if (tlenlen == 0) { /* Short length notation */ sig[(*len)++] = tlen; } else { /* Long length notation */ sig[(*len)++] = 128 + tlenlen; assign_big_endian(sig + *len, tlenlen, tlen); *len += tlenlen; } tlen += tlenlen; } tlen += 2; CHECK(tlen + glen <= 1119); for (n = 0; n < 2; n++) { /* Write the integer header. */ sig[(*len)++] = 0x02; if (nlenlen[n] == 0) { /* Short length notation */ sig[(*len)++] = nlen[n] + nzlen[n]; } else { /* Long length notation. */ sig[(*len)++] = 128 + nlenlen[n]; assign_big_endian(sig + *len, nlenlen[n], nlen[n] + nzlen[n]); *len += nlenlen[n]; } /* Write zero padding */ while (nzlen[n] > 0) { sig[(*len)++] = 0x00; nzlen[n]--; } if (nlen[n] == 32 && !nlow[n]) { /* Special extra 16 0xFF bytes in "high" 32-byte numbers */ int i; for (i = 0; i < 16; i++) { sig[(*len)++] = 0xFF; } nlen[n] -= 16; } /* Write first byte of number */ if (nlen[n] > 0) { sig[(*len)++] = nhbyte[n]; nlen[n]--; } /* Generate remaining random bytes of number */ secp256k1_rand_bytes_test(sig + *len, nlen[n]); *len += nlen[n]; nlen[n] = 0; } /* Generate random garbage inside tuple. */ secp256k1_rand_bytes_test(sig + *len, elen); *len += elen; /* Generate end-of-contents bytes. */ if (indet) { sig[(*len)++] = 0; sig[(*len)++] = 0; tlen += 2; } CHECK(tlen + glen <= 1121); /* Generate random garbage outside tuple. */ secp256k1_rand_bytes_test(sig + *len, glen); *len += glen; tlen += glen; CHECK(tlen <= 1121); CHECK(tlen == *len); } void run_ecdsa_der_parse(void) { int i,j; for (i = 0; i < 200 * count; i++) { unsigned char buffer[2048]; size_t buflen = 0; int certainly_der = 0; int certainly_not_der = 0; random_ber_signature(buffer, &buflen, &certainly_der, &certainly_not_der); CHECK(buflen <= 2048); for (j = 0; j < 16; j++) { int ret = 0; if (j > 0) { damage_array(buffer, &buflen); /* We don't know anything anymore about the DERness of the result */ certainly_der = 0; certainly_not_der = 0; } ret = test_ecdsa_der_parse(buffer, buflen, certainly_der, certainly_not_der); if (ret != 0) { size_t k; fprintf(stderr, "Failure %x on ", ret); for (k = 0; k < buflen; k++) { fprintf(stderr, "%02x ", buffer[k]); } fprintf(stderr, "\n"); } CHECK(ret == 0); } } } /* Tests several edge cases. */ void test_ecdsa_edge_cases(void) { int t; secp256k1_ecdsa_signature sig; /* Test the case where ECDSA recomputes a point that is infinity. */ { secp256k1_gej keyj; secp256k1_ge key; secp256k1_scalar msg; secp256k1_scalar sr, ss; secp256k1_scalar_set_int(&ss, 1); secp256k1_scalar_negate(&ss, &ss); secp256k1_scalar_inverse(&ss, &ss); secp256k1_scalar_set_int(&sr, 1); secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &keyj, &sr); secp256k1_ge_set_gej(&key, &keyj); msg = ss; CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 0); } /* Verify signature with r of zero fails. */ { const unsigned char pubkey_mods_zero[33] = { 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41 }; secp256k1_ge key; secp256k1_scalar msg; secp256k1_scalar sr, ss; secp256k1_scalar_set_int(&ss, 1); secp256k1_scalar_set_int(&msg, 0); secp256k1_scalar_set_int(&sr, 0); CHECK(secp256k1_eckey_pubkey_parse(&key, pubkey_mods_zero, 33)); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 0); } /* Verify signature with s of zero fails. */ { const unsigned char pubkey[33] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; secp256k1_ge key; secp256k1_scalar msg; secp256k1_scalar sr, ss; secp256k1_scalar_set_int(&ss, 0); secp256k1_scalar_set_int(&msg, 0); secp256k1_scalar_set_int(&sr, 1); CHECK(secp256k1_eckey_pubkey_parse(&key, pubkey, 33)); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 0); } /* Verify signature with message 0 passes. */ { const unsigned char pubkey[33] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; const unsigned char pubkey2[33] = { 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x43 }; secp256k1_ge key; secp256k1_ge key2; secp256k1_scalar msg; secp256k1_scalar sr, ss; secp256k1_scalar_set_int(&ss, 2); secp256k1_scalar_set_int(&msg, 0); secp256k1_scalar_set_int(&sr, 2); CHECK(secp256k1_eckey_pubkey_parse(&key, pubkey, 33)); CHECK(secp256k1_eckey_pubkey_parse(&key2, pubkey2, 33)); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 1); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key2, &msg) == 1); secp256k1_scalar_negate(&ss, &ss); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 1); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key2, &msg) == 1); secp256k1_scalar_set_int(&ss, 1); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 0); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key2, &msg) == 0); } /* Verify signature with message 1 passes. */ { const unsigned char pubkey[33] = { 0x02, 0x14, 0x4e, 0x5a, 0x58, 0xef, 0x5b, 0x22, 0x6f, 0xd2, 0xe2, 0x07, 0x6a, 0x77, 0xcf, 0x05, 0xb4, 0x1d, 0xe7, 0x4a, 0x30, 0x98, 0x27, 0x8c, 0x93, 0xe6, 0xe6, 0x3c, 0x0b, 0xc4, 0x73, 0x76, 0x25 }; const unsigned char pubkey2[33] = { 0x02, 0x8a, 0xd5, 0x37, 0xed, 0x73, 0xd9, 0x40, 0x1d, 0xa0, 0x33, 0xd2, 0xdc, 0xf0, 0xaf, 0xae, 0x34, 0xcf, 0x5f, 0x96, 0x4c, 0x73, 0x28, 0x0f, 0x92, 0xc0, 0xf6, 0x9d, 0xd9, 0xb2, 0x09, 0x10, 0x62 }; const unsigned char csr[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x45, 0x51, 0x23, 0x19, 0x50, 0xb7, 0x5f, 0xc4, 0x40, 0x2d, 0xa1, 0x72, 0x2f, 0xc9, 0xba, 0xeb }; secp256k1_ge key; secp256k1_ge key2; secp256k1_scalar msg; secp256k1_scalar sr, ss; secp256k1_scalar_set_int(&ss, 1); secp256k1_scalar_set_int(&msg, 1); secp256k1_scalar_set_b32(&sr, csr, NULL); CHECK(secp256k1_eckey_pubkey_parse(&key, pubkey, 33)); CHECK(secp256k1_eckey_pubkey_parse(&key2, pubkey2, 33)); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 1); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key2, &msg) == 1); secp256k1_scalar_negate(&ss, &ss); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 1); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key2, &msg) == 1); secp256k1_scalar_set_int(&ss, 2); secp256k1_scalar_inverse_var(&ss, &ss); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 0); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key2, &msg) == 0); } /* Verify signature with message -1 passes. */ { const unsigned char pubkey[33] = { 0x03, 0xaf, 0x97, 0xff, 0x7d, 0x3a, 0xf6, 0xa0, 0x02, 0x94, 0xbd, 0x9f, 0x4b, 0x2e, 0xd7, 0x52, 0x28, 0xdb, 0x49, 0x2a, 0x65, 0xcb, 0x1e, 0x27, 0x57, 0x9c, 0xba, 0x74, 0x20, 0xd5, 0x1d, 0x20, 0xf1 }; const unsigned char csr[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x45, 0x51, 0x23, 0x19, 0x50, 0xb7, 0x5f, 0xc4, 0x40, 0x2d, 0xa1, 0x72, 0x2f, 0xc9, 0xba, 0xee }; secp256k1_ge key; secp256k1_scalar msg; secp256k1_scalar sr, ss; secp256k1_scalar_set_int(&ss, 1); secp256k1_scalar_set_int(&msg, 1); secp256k1_scalar_negate(&msg, &msg); secp256k1_scalar_set_b32(&sr, csr, NULL); CHECK(secp256k1_eckey_pubkey_parse(&key, pubkey, 33)); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 1); secp256k1_scalar_negate(&ss, &ss); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 1); secp256k1_scalar_set_int(&ss, 3); secp256k1_scalar_inverse_var(&ss, &ss); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sr, &ss, &key, &msg) == 0); } /* Signature where s would be zero. */ { secp256k1_pubkey pubkey; size_t siglen; int32_t ecount; unsigned char signature[72]; static const unsigned char nonce[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }; static const unsigned char nonce2[32] = { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE, 0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B, 0xBF,0xD2,0x5E,0x8C,0xD0,0x36,0x41,0x40 }; const unsigned char key[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }; unsigned char msg[32] = { 0x86, 0x41, 0x99, 0x81, 0x06, 0x23, 0x44, 0x53, 0xaa, 0x5f, 0x9d, 0x6a, 0x31, 0x78, 0xf4, 0xf7, 0xb8, 0x12, 0xe0, 0x0b, 0x81, 0x7a, 0x77, 0x62, 0x65, 0xdf, 0xdd, 0x31, 0xb9, 0x3e, 0x29, 0xa9, }; ecount = 0; secp256k1_context_set_illegal_callback(ctx, counting_illegal_callback_fn, &ecount); CHECK(secp256k1_ecdsa_sign(ctx, &sig, msg, key, precomputed_nonce_function, nonce) == 0); CHECK(secp256k1_ecdsa_sign(ctx, &sig, msg, key, precomputed_nonce_function, nonce2) == 0); msg[31] = 0xaa; CHECK(secp256k1_ecdsa_sign(ctx, &sig, msg, key, precomputed_nonce_function, nonce) == 1); CHECK(ecount == 0); CHECK(secp256k1_ecdsa_sign(ctx, NULL, msg, key, precomputed_nonce_function, nonce2) == 0); CHECK(ecount == 1); CHECK(secp256k1_ecdsa_sign(ctx, &sig, NULL, key, precomputed_nonce_function, nonce2) == 0); CHECK(ecount == 2); CHECK(secp256k1_ecdsa_sign(ctx, &sig, msg, NULL, precomputed_nonce_function, nonce2) == 0); CHECK(ecount == 3); CHECK(secp256k1_ecdsa_sign(ctx, &sig, msg, key, precomputed_nonce_function, nonce2) == 1); CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey, key) == 1); CHECK(secp256k1_ecdsa_verify(ctx, NULL, msg, &pubkey) == 0); CHECK(ecount == 4); CHECK(secp256k1_ecdsa_verify(ctx, &sig, NULL, &pubkey) == 0); CHECK(ecount == 5); CHECK(secp256k1_ecdsa_verify(ctx, &sig, msg, NULL) == 0); CHECK(ecount == 6); CHECK(secp256k1_ecdsa_verify(ctx, &sig, msg, &pubkey) == 1); CHECK(ecount == 6); CHECK(secp256k1_ec_pubkey_create(ctx, &pubkey, NULL) == 0); CHECK(ecount == 7); /* That pubkeyload fails via an ARGCHECK is a little odd but makes sense because pubkeys are an opaque data type. */ CHECK(secp256k1_ecdsa_verify(ctx, &sig, msg, &pubkey) == 0); CHECK(ecount == 8); siglen = 72; CHECK(secp256k1_ecdsa_signature_serialize_der(ctx, NULL, &siglen, &sig) == 0); CHECK(ecount == 9); CHECK(secp256k1_ecdsa_signature_serialize_der(ctx, signature, NULL, &sig) == 0); CHECK(ecount == 10); CHECK(secp256k1_ecdsa_signature_serialize_der(ctx, signature, &siglen, NULL) == 0); CHECK(ecount == 11); CHECK(secp256k1_ecdsa_signature_serialize_der(ctx, signature, &siglen, &sig) == 1); CHECK(ecount == 11); CHECK(secp256k1_ecdsa_signature_parse_der(ctx, NULL, signature, siglen) == 0); CHECK(ecount == 12); CHECK(secp256k1_ecdsa_signature_parse_der(ctx, &sig, NULL, siglen) == 0); CHECK(ecount == 13); CHECK(secp256k1_ecdsa_signature_parse_der(ctx, &sig, signature, siglen) == 1); CHECK(ecount == 13); siglen = 10; /* Too little room for a signature does not fail via ARGCHECK. */ CHECK(secp256k1_ecdsa_signature_serialize_der(ctx, signature, &siglen, &sig) == 0); CHECK(ecount == 13); ecount = 0; CHECK(secp256k1_ecdsa_signature_normalize(ctx, NULL, NULL) == 0); CHECK(ecount == 1); CHECK(secp256k1_ecdsa_signature_serialize_compact(ctx, NULL, &sig) == 0); CHECK(ecount == 2); CHECK(secp256k1_ecdsa_signature_serialize_compact(ctx, signature, NULL) == 0); CHECK(ecount == 3); CHECK(secp256k1_ecdsa_signature_serialize_compact(ctx, signature, &sig) == 1); CHECK(ecount == 3); CHECK(secp256k1_ecdsa_signature_parse_compact(ctx, NULL, signature) == 0); CHECK(ecount == 4); CHECK(secp256k1_ecdsa_signature_parse_compact(ctx, &sig, NULL) == 0); CHECK(ecount == 5); CHECK(secp256k1_ecdsa_signature_parse_compact(ctx, &sig, signature) == 1); CHECK(ecount == 5); memset(signature, 255, 64); CHECK(secp256k1_ecdsa_signature_parse_compact(ctx, &sig, signature) == 0); CHECK(ecount == 5); secp256k1_context_set_illegal_callback(ctx, NULL, NULL); } /* Nonce function corner cases. */ for (t = 0; t < 2; t++) { static const unsigned char zero[32] = {0x00}; int i; unsigned char key[32]; unsigned char msg[32]; secp256k1_ecdsa_signature sig2; secp256k1_scalar sr[512], ss; const unsigned char *extra; extra = t == 0 ? NULL : zero; memset(msg, 0, 32); msg[31] = 1; /* High key results in signature failure. */ memset(key, 0xFF, 32); CHECK(secp256k1_ecdsa_sign(ctx, &sig, msg, key, NULL, extra) == 0); CHECK(is_empty_signature(&sig)); /* Zero key results in signature failure. */ memset(key, 0, 32); CHECK(secp256k1_ecdsa_sign(ctx, &sig, msg, key, NULL, extra) == 0); CHECK(is_empty_signature(&sig)); /* Nonce function failure results in signature failure. */ key[31] = 1; CHECK(secp256k1_ecdsa_sign(ctx, &sig, msg, key, nonce_function_test_fail, extra) == 0); CHECK(is_empty_signature(&sig)); /* The retry loop successfully makes its way to the first good value. */ CHECK(secp256k1_ecdsa_sign(ctx, &sig, msg, key, nonce_function_test_retry, extra) == 1); CHECK(!is_empty_signature(&sig)); CHECK(secp256k1_ecdsa_sign(ctx, &sig2, msg, key, nonce_function_rfc6979, extra) == 1); CHECK(!is_empty_signature(&sig2)); CHECK(memcmp(&sig, &sig2, sizeof(sig)) == 0); /* The default nonce function is deterministic. */ CHECK(secp256k1_ecdsa_sign(ctx, &sig2, msg, key, NULL, extra) == 1); CHECK(!is_empty_signature(&sig2)); CHECK(memcmp(&sig, &sig2, sizeof(sig)) == 0); /* The default nonce function changes output with different messages. */ for(i = 0; i < 256; i++) { int j; msg[0] = i; CHECK(secp256k1_ecdsa_sign(ctx, &sig2, msg, key, NULL, extra) == 1); CHECK(!is_empty_signature(&sig2)); secp256k1_ecdsa_signature_load(ctx, &sr[i], &ss, &sig2); for (j = 0; j < i; j++) { CHECK(!secp256k1_scalar_eq(&sr[i], &sr[j])); } } msg[0] = 0; msg[31] = 2; /* The default nonce function changes output with different keys. */ for(i = 256; i < 512; i++) { int j; key[0] = i - 256; CHECK(secp256k1_ecdsa_sign(ctx, &sig2, msg, key, NULL, extra) == 1); CHECK(!is_empty_signature(&sig2)); secp256k1_ecdsa_signature_load(ctx, &sr[i], &ss, &sig2); for (j = 0; j < i; j++) { CHECK(!secp256k1_scalar_eq(&sr[i], &sr[j])); } } key[0] = 0; } { /* Check that optional nonce arguments do not have equivalent effect. */ const unsigned char zeros[32] = {0}; unsigned char nonce[32]; unsigned char nonce2[32]; unsigned char nonce3[32]; unsigned char nonce4[32]; VG_UNDEF(nonce,32); VG_UNDEF(nonce2,32); VG_UNDEF(nonce3,32); VG_UNDEF(nonce4,32); CHECK(nonce_function_rfc6979(nonce, zeros, zeros, NULL, NULL, 0) == 1); VG_CHECK(nonce,32); CHECK(nonce_function_rfc6979(nonce2, zeros, zeros, zeros, NULL, 0) == 1); VG_CHECK(nonce2,32); CHECK(nonce_function_rfc6979(nonce3, zeros, zeros, NULL, (void *)zeros, 0) == 1); VG_CHECK(nonce3,32); CHECK(nonce_function_rfc6979(nonce4, zeros, zeros, zeros, (void *)zeros, 0) == 1); VG_CHECK(nonce4,32); CHECK(memcmp(nonce, nonce2, 32) != 0); CHECK(memcmp(nonce, nonce3, 32) != 0); CHECK(memcmp(nonce, nonce4, 32) != 0); CHECK(memcmp(nonce2, nonce3, 32) != 0); CHECK(memcmp(nonce2, nonce4, 32) != 0); CHECK(memcmp(nonce3, nonce4, 32) != 0); } /* Privkey export where pubkey is the point at infinity. */ { unsigned char privkey[300]; unsigned char seckey[32] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, }; size_t outlen = 300; CHECK(!ec_privkey_export_der(ctx, privkey, &outlen, seckey, 0)); outlen = 300; CHECK(!ec_privkey_export_der(ctx, privkey, &outlen, seckey, 1)); } } void run_ecdsa_edge_cases(void) { test_ecdsa_edge_cases(); } #ifdef ENABLE_OPENSSL_TESTS EC_KEY *get_openssl_key(const unsigned char *key32) { unsigned char privkey[300]; size_t privkeylen; const unsigned char* pbegin = privkey; int compr = secp256k1_rand_bits(1); EC_KEY *ec_key = EC_KEY_new_by_curve_name(NID_secp256k1); CHECK(ec_privkey_export_der(ctx, privkey, &privkeylen, key32, compr)); CHECK(d2i_ECPrivateKey(&ec_key, &pbegin, privkeylen)); CHECK(EC_KEY_check_key(ec_key)); return ec_key; } void test_ecdsa_openssl(void) { secp256k1_gej qj; secp256k1_ge q; secp256k1_scalar sigr, sigs; secp256k1_scalar one; secp256k1_scalar msg2; secp256k1_scalar key, msg; EC_KEY *ec_key; unsigned int sigsize = 80; size_t secp_sigsize = 80; unsigned char message[32]; unsigned char signature[80]; unsigned char key32[32]; secp256k1_rand256_test(message); secp256k1_scalar_set_b32(&msg, message, NULL); random_scalar_order_test(&key); secp256k1_scalar_get_b32(key32, &key); secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &qj, &key); secp256k1_ge_set_gej(&q, &qj); ec_key = get_openssl_key(key32); CHECK(ec_key != NULL); CHECK(ECDSA_sign(0, message, sizeof(message), signature, &sigsize, ec_key)); CHECK(secp256k1_ecdsa_sig_parse(&sigr, &sigs, signature, sigsize)); CHECK(secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sigr, &sigs, &q, &msg)); secp256k1_scalar_set_int(&one, 1); secp256k1_scalar_add(&msg2, &msg, &one); CHECK(!secp256k1_ecdsa_sig_verify(&ctx->ecmult_ctx, &sigr, &sigs, &q, &msg2)); random_sign(&sigr, &sigs, &key, &msg, NULL); CHECK(secp256k1_ecdsa_sig_serialize(signature, &secp_sigsize, &sigr, &sigs)); CHECK(ECDSA_verify(0, message, sizeof(message), signature, secp_sigsize, ec_key) == 1); EC_KEY_free(ec_key); } void run_ecdsa_openssl(void) { int i; for (i = 0; i < 10*count; i++) { test_ecdsa_openssl(); } } #endif #ifdef ENABLE_MODULE_ECDH # include "modules/ecdh/tests_impl.h" #endif #ifdef ENABLE_MODULE_RECOVERY # include "modules/recovery/tests_impl.h" #endif int main(int argc, char **argv) { unsigned char seed16[16] = {0}; unsigned char run32[32] = {0}; /* find iteration count */ if (argc > 1) { count = strtol(argv[1], NULL, 0); } /* find random seed */ if (argc > 2) { int pos = 0; const char* ch = argv[2]; while (pos < 16 && ch[0] != 0 && ch[1] != 0) { unsigned short sh; if (sscanf(ch, "%2hx", &sh)) { seed16[pos] = sh; } else { break; } ch += 2; pos++; } } else { FILE *frand = fopen("/dev/urandom", "r"); if ((frand == NULL) || !fread(&seed16, sizeof(seed16), 1, frand)) { uint64_t t = time(NULL) * (uint64_t)1337; seed16[0] ^= t; seed16[1] ^= t >> 8; seed16[2] ^= t >> 16; seed16[3] ^= t >> 24; seed16[4] ^= t >> 32; seed16[5] ^= t >> 40; seed16[6] ^= t >> 48; seed16[7] ^= t >> 56; } fclose(frand); } secp256k1_rand_seed(seed16); printf("test count = %i\n", count); printf("random seed = %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", seed16[0], seed16[1], seed16[2], seed16[3], seed16[4], seed16[5], seed16[6], seed16[7], seed16[8], seed16[9], seed16[10], seed16[11], seed16[12], seed16[13], seed16[14], seed16[15]); /* initialize */ run_context_tests(); ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); if (secp256k1_rand_bits(1)) { secp256k1_rand256(run32); CHECK(secp256k1_context_randomize(ctx, secp256k1_rand_bits(1) ? run32 : NULL)); } run_rand_bits(); run_rand_int(); run_sha256_tests(); run_hmac_sha256_tests(); run_rfc6979_hmac_sha256_tests(); #ifndef USE_NUM_NONE /* num tests */ run_num_smalltests(); #endif /* scalar tests */ run_scalar_tests(); /* field tests */ run_field_inv(); run_field_inv_var(); run_field_inv_all_var(); run_field_misc(); run_field_convert(); run_sqr(); run_sqrt(); /* group tests */ run_ge(); run_group_decompress(); /* ecmult tests */ run_wnaf(); run_point_times_order(); run_ecmult_chain(); run_ecmult_constants(); run_ecmult_gen_blind(); run_ecmult_const_tests(); run_ec_combine(); /* endomorphism tests */ #ifdef USE_ENDOMORPHISM run_endomorphism_tests(); #endif /* EC point parser test */ run_ec_pubkey_parse_test(); /* EC key edge cases */ run_eckey_edge_case_test(); #ifdef ENABLE_MODULE_ECDH /* ecdh tests */ run_ecdh_tests(); #endif /* ecdsa tests */ run_random_pubkeys(); run_ecdsa_der_parse(); run_ecdsa_sign_verify(); run_ecdsa_end_to_end(); run_ecdsa_edge_cases(); #ifdef ENABLE_OPENSSL_TESTS run_ecdsa_openssl(); #endif #ifdef ENABLE_MODULE_RECOVERY /* ECDSA pubkey recovery tests */ run_recovery_tests(); #endif secp256k1_rand256(run32); printf("random run = %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", run32[0], run32[1], run32[2], run32[3], run32[4], run32[5], run32[6], run32[7], run32[8], run32[9], run32[10], run32[11], run32[12], run32[13], run32[14], run32[15]); /* shutdown */ secp256k1_context_destroy(ctx); printf("no problems found\n"); return 0; }
793611.c
/* CF3 Copyright (c) 2015 ishiura-lab. Released under the MIT license. https://github.com/ishiura-compiler/CF3/MIT-LICENSE.md */ #include<stdio.h> #include<stdint.h> #include<stdlib.h> #include"test1.h" uint8_t x1 = 6U; int32_t t3 = 5820604; volatile int32_t t4 = -202; volatile uint8_t x22 = 27U; static int32_t t5 = 0; static int8_t x32 = 14; static volatile int32_t t7 = 124164; static uint16_t x35 = UINT16_MAX; int32_t x37 = -1; int8_t x38 = -1; int64_t x42 = -1LL; static int8_t x44 = 63; volatile int64_t x52 = -1LL; int32_t t12 = 10212; uint64_t x55 = 48977832501LLU; int32_t t13 = -50183; uint32_t x57 = 47111549U; int32_t x69 = INT32_MAX; int64_t x73 = INT64_MIN; uint32_t x84 = 893U; volatile int32_t t20 = -22150; static volatile int8_t x85 = -1; uint8_t x89 = 106U; static uint32_t x90 = 8U; int32_t x93 = INT32_MIN; int32_t x99 = 8299; int16_t x102 = INT16_MAX; int32_t t25 = 4070; int16_t x111 = INT16_MIN; volatile uint16_t x115 = 34U; int32_t t28 = 6049705; uint16_t x117 = 414U; int8_t x124 = -1; int16_t x127 = INT16_MIN; int32_t x128 = INT32_MIN; volatile int64_t x131 = INT64_MAX; volatile int32_t t32 = 1; int8_t x135 = -4; uint64_t x136 = 21521798LLU; int32_t t33 = -141598; uint64_t x141 = 122651LLU; static int16_t x143 = 45; static volatile uint8_t x144 = UINT8_MAX; uint16_t x148 = UINT16_MAX; uint64_t x153 = UINT64_MAX; int32_t x155 = -97487083; int32_t x165 = INT32_MAX; int32_t t41 = -192; int64_t x176 = INT64_MAX; static volatile uint64_t x180 = UINT64_MAX; int64_t x181 = INT64_MIN; uint64_t x182 = 34310181470123LLU; int32_t t47 = -11; volatile uint16_t x197 = UINT16_MAX; uint16_t x200 = UINT16_MAX; volatile int32_t t51 = 130289228; int32_t t52 = -554874; static int16_t x214 = INT16_MIN; int64_t x215 = INT64_MIN; uint8_t x223 = UINT8_MAX; int64_t x229 = -265499982LL; uint16_t x231 = 144U; static int16_t x234 = INT16_MAX; int64_t x235 = -1LL; int16_t x236 = -1; int32_t t58 = 1142152; volatile int32_t t59 = 339117; volatile int32_t t60 = 11; int32_t t61 = -13; int32_t x249 = INT32_MIN; int64_t x251 = INT64_MIN; int64_t x252 = -61143365682486222LL; static int64_t x254 = -1LL; uint8_t x264 = 5U; uint16_t x266 = 452U; int64_t x271 = INT64_MAX; volatile int32_t x276 = -1; int32_t x282 = INT32_MIN; int32_t x292 = 29546928; int8_t x295 = INT8_MAX; static int32_t t74 = -487984681; int64_t x307 = INT64_MIN; int32_t x313 = INT32_MAX; volatile int32_t t78 = 1; int32_t x319 = INT32_MAX; static int32_t t79 = -55881; uint32_t x322 = UINT32_MAX; volatile int32_t t80 = 107626183; static int8_t x329 = -1; int8_t x343 = 0; static int32_t x344 = INT32_MAX; static uint32_t x346 = UINT32_MAX; uint64_t x347 = UINT64_MAX; volatile int32_t t86 = 7602005; static volatile int32_t t88 = 281963259; uint16_t x361 = 51U; volatile uint64_t x367 = 2750403833020LLU; uint16_t x368 = 2U; static int32_t x372 = INT32_MIN; uint64_t x379 = 97525049290980685LLU; volatile int32_t t94 = -126; int32_t x384 = -14; uint64_t x388 = UINT64_MAX; volatile uint64_t x390 = UINT64_MAX; static int32_t x398 = INT32_MAX; static volatile int64_t x402 = -2879729250110913478LL; int16_t x405 = 15853; static int32_t t101 = -402; static int64_t x409 = -1LL; volatile int16_t x428 = INT16_MIN; static int16_t x440 = 0; uint8_t x443 = 32U; static volatile int32_t t110 = 25; int16_t x445 = INT16_MIN; static uint32_t x449 = 1256U; int16_t x451 = 0; int32_t x452 = 4; int64_t x457 = -1LL; uint8_t x463 = 3U; int32_t t115 = 960; static int32_t t116 = 133079045; static volatile uint16_t x473 = UINT16_MAX; uint32_t x477 = 507U; int8_t x479 = -1; static int32_t t119 = 8719; int8_t x481 = -1; volatile uint8_t x483 = 1U; int16_t x485 = INT16_MIN; int32_t x495 = -28791; int32_t t123 = 0; uint64_t x498 = 15LLU; int64_t x499 = INT64_MIN; int64_t x500 = INT64_MIN; static uint32_t x501 = 1806U; int16_t x503 = 1; static int32_t t127 = -4252431; volatile uint64_t x526 = 4011LLU; volatile int32_t t132 = 2002119; uint64_t x533 = 235230103772235276LLU; volatile int32_t t133 = 524; volatile int8_t x537 = INT8_MIN; int32_t x545 = 382866244; int32_t x547 = 0; volatile int16_t x549 = INT16_MIN; static volatile int16_t x550 = -1; int32_t t137 = 5; volatile int8_t x554 = INT8_MIN; int32_t x561 = -1; int8_t x567 = 24; static uint32_t x572 = UINT32_MAX; int8_t x578 = INT8_MIN; uint8_t x581 = UINT8_MAX; volatile int32_t t145 = -1702; volatile int32_t x587 = -5004; int64_t x593 = INT64_MIN; int32_t x595 = INT32_MIN; static int64_t x604 = -463LL; volatile int32_t x608 = INT32_MIN; int32_t t152 = 414; int64_t x616 = -1LL; int32_t x618 = INT32_MAX; int8_t x619 = -1; static volatile uint8_t x622 = UINT8_MAX; static int64_t x634 = -1LL; int64_t x636 = 445662010630876LL; static volatile int32_t t158 = -776006951; uint32_t x637 = 1497408314U; int32_t x644 = -1; int64_t x647 = INT64_MAX; static int64_t x664 = -1LL; volatile int32_t t165 = 15036547; static volatile uint64_t x668 = 135499321484100LLU; int32_t t166 = -22800; int32_t t168 = 20; int16_t x677 = -262; static int64_t x679 = 42293483073682600LL; int8_t x680 = INT8_MAX; int16_t x686 = INT16_MIN; int64_t x688 = INT64_MIN; int8_t x690 = INT8_MIN; int8_t x692 = 0; volatile int32_t t172 = 31141; uint64_t x698 = UINT64_MAX; volatile int32_t x702 = -1; static int32_t x708 = -166; int32_t x713 = -1; int8_t x714 = INT8_MIN; volatile int32_t t178 = -964; static int8_t x727 = INT8_MAX; volatile int8_t x728 = 56; int8_t x733 = 0; int64_t x742 = -1LL; int64_t x744 = 13766770200LL; int8_t x750 = INT8_MIN; int32_t x752 = -20; int32_t x759 = 100124; static uint8_t x763 = 6U; int8_t x765 = 5; static int64_t x766 = -1LL; static volatile int32_t t193 = 3670501; int32_t t194 = -65; volatile uint16_t x782 = 5341U; int16_t x784 = 131; int16_t x789 = 22; volatile int32_t t197 = -391257; void f0(void) { uint8_t x2 = 1U; int32_t x3 = -1; static volatile uint64_t x4 = UINT64_MAX; volatile int32_t t0 = 42008024; t0 = (((x1!=x2)!=x3)==x4); if (t0 != 0) { NG(); } else { ; } } void f1(void) { int64_t x5 = INT64_MIN; static int8_t x6 = INT8_MIN; uint64_t x7 = 15119LLU; static volatile uint32_t x8 = 3U; volatile int32_t t1 = 1; t1 = (((x5!=x6)!=x7)==x8); if (t1 != 0) { NG(); } else { ; } } void f2(void) { static int64_t x9 = -1327799840043339LL; int16_t x10 = -1811; volatile int32_t x11 = -1; int32_t x12 = INT32_MIN; volatile int32_t t2 = -10888; t2 = (((x9!=x10)!=x11)==x12); if (t2 != 0) { NG(); } else { ; } } void f3(void) { volatile int64_t x13 = INT64_MIN; uint16_t x14 = UINT16_MAX; int32_t x15 = INT32_MIN; uint64_t x16 = 21LLU; t3 = (((x13!=x14)!=x15)==x16); if (t3 != 0) { NG(); } else { ; } } void f4(void) { int64_t x17 = -1LL; int64_t x18 = INT64_MIN; int8_t x19 = INT8_MAX; volatile int64_t x20 = INT64_MIN; t4 = (((x17!=x18)!=x19)==x20); if (t4 != 0) { NG(); } else { ; } } void f5(void) { static uint16_t x21 = 241U; static volatile uint8_t x23 = 95U; uint64_t x24 = 33063652094984LLU; t5 = (((x21!=x22)!=x23)==x24); if (t5 != 0) { NG(); } else { ; } } void f6(void) { static volatile int32_t x25 = INT32_MAX; volatile uint8_t x26 = 10U; uint64_t x27 = UINT64_MAX; int32_t x28 = INT32_MIN; static int32_t t6 = 4; t6 = (((x25!=x26)!=x27)==x28); if (t6 != 0) { NG(); } else { ; } } void f7(void) { static volatile int64_t x29 = INT64_MIN; uint16_t x30 = UINT16_MAX; volatile uint64_t x31 = 25LLU; t7 = (((x29!=x30)!=x31)==x32); if (t7 != 0) { NG(); } else { ; } } void f8(void) { static int32_t x33 = INT32_MAX; int8_t x34 = INT8_MIN; static int32_t x36 = INT32_MIN; volatile int32_t t8 = -3; t8 = (((x33!=x34)!=x35)==x36); if (t8 != 0) { NG(); } else { ; } } void f9(void) { int16_t x39 = 22; int64_t x40 = 3835575007731LL; volatile int32_t t9 = 41; t9 = (((x37!=x38)!=x39)==x40); if (t9 != 0) { NG(); } else { ; } } void f10(void) { uint64_t x41 = 10686LLU; int8_t x43 = -1; static int32_t t10 = -792695; t10 = (((x41!=x42)!=x43)==x44); if (t10 != 0) { NG(); } else { ; } } void f11(void) { volatile uint8_t x45 = 1U; uint32_t x46 = 2920U; int64_t x47 = -188082833000850LL; uint8_t x48 = UINT8_MAX; volatile int32_t t11 = 1; t11 = (((x45!=x46)!=x47)==x48); if (t11 != 0) { NG(); } else { ; } } void f12(void) { int32_t x49 = INT32_MAX; uint32_t x50 = 3294055U; int8_t x51 = 0; t12 = (((x49!=x50)!=x51)==x52); if (t12 != 0) { NG(); } else { ; } } void f13(void) { uint32_t x53 = 1537869U; static uint32_t x54 = 4U; int64_t x56 = INT64_MIN; t13 = (((x53!=x54)!=x55)==x56); if (t13 != 0) { NG(); } else { ; } } void f14(void) { uint64_t x58 = 0LLU; volatile uint16_t x59 = 11U; volatile int32_t x60 = INT32_MIN; static int32_t t14 = 79446172; t14 = (((x57!=x58)!=x59)==x60); if (t14 != 0) { NG(); } else { ; } } void f15(void) { int8_t x61 = 0; int16_t x62 = 1554; int32_t x63 = INT32_MIN; int64_t x64 = -14LL; int32_t t15 = 1827; t15 = (((x61!=x62)!=x63)==x64); if (t15 != 0) { NG(); } else { ; } } void f16(void) { uint32_t x65 = 998717U; int64_t x66 = -113050810LL; static int64_t x67 = INT64_MIN; int8_t x68 = 0; volatile int32_t t16 = 88846504; t16 = (((x65!=x66)!=x67)==x68); if (t16 != 0) { NG(); } else { ; } } void f17(void) { volatile int64_t x70 = INT64_MIN; uint16_t x71 = 14U; uint32_t x72 = UINT32_MAX; static volatile int32_t t17 = -20700; t17 = (((x69!=x70)!=x71)==x72); if (t17 != 0) { NG(); } else { ; } } void f18(void) { int32_t x74 = INT32_MIN; uint64_t x75 = 2625490LLU; static int16_t x76 = -1; int32_t t18 = 338428; t18 = (((x73!=x74)!=x75)==x76); if (t18 != 0) { NG(); } else { ; } } void f19(void) { static uint32_t x77 = UINT32_MAX; static uint8_t x78 = UINT8_MAX; uint8_t x79 = UINT8_MAX; static uint32_t x80 = UINT32_MAX; volatile int32_t t19 = 337; t19 = (((x77!=x78)!=x79)==x80); if (t19 != 0) { NG(); } else { ; } } void f20(void) { static uint64_t x81 = 2LLU; int64_t x82 = -1LL; volatile int32_t x83 = INT32_MAX; t20 = (((x81!=x82)!=x83)==x84); if (t20 != 0) { NG(); } else { ; } } void f21(void) { int32_t x86 = INT32_MIN; static int64_t x87 = INT64_MIN; uint16_t x88 = 1U; int32_t t21 = -273; t21 = (((x85!=x86)!=x87)==x88); if (t21 != 1) { NG(); } else { ; } } void f22(void) { int8_t x91 = INT8_MIN; int32_t x92 = 4098831; volatile int32_t t22 = -2026; t22 = (((x89!=x90)!=x91)==x92); if (t22 != 0) { NG(); } else { ; } } void f23(void) { static volatile int8_t x94 = INT8_MIN; uint64_t x95 = 25409263LLU; static volatile uint16_t x96 = UINT16_MAX; volatile int32_t t23 = 596; t23 = (((x93!=x94)!=x95)==x96); if (t23 != 0) { NG(); } else { ; } } void f24(void) { int16_t x97 = -4400; int16_t x98 = INT16_MIN; volatile int16_t x100 = 12; static volatile int32_t t24 = -8647; t24 = (((x97!=x98)!=x99)==x100); if (t24 != 0) { NG(); } else { ; } } void f25(void) { uint8_t x101 = 15U; static int8_t x103 = INT8_MAX; int8_t x104 = -1; t25 = (((x101!=x102)!=x103)==x104); if (t25 != 0) { NG(); } else { ; } } void f26(void) { volatile uint16_t x105 = 72U; uint64_t x106 = UINT64_MAX; int8_t x107 = -1; volatile int16_t x108 = INT16_MAX; int32_t t26 = -100828; t26 = (((x105!=x106)!=x107)==x108); if (t26 != 0) { NG(); } else { ; } } void f27(void) { int16_t x109 = 197; static uint64_t x110 = UINT64_MAX; uint64_t x112 = 339LLU; volatile int32_t t27 = 64293; t27 = (((x109!=x110)!=x111)==x112); if (t27 != 0) { NG(); } else { ; } } void f28(void) { int32_t x113 = -1; uint32_t x114 = UINT32_MAX; int16_t x116 = -1; t28 = (((x113!=x114)!=x115)==x116); if (t28 != 0) { NG(); } else { ; } } void f29(void) { uint32_t x118 = 194U; int64_t x119 = -1LL; static int32_t x120 = -1; int32_t t29 = -213; t29 = (((x117!=x118)!=x119)==x120); if (t29 != 0) { NG(); } else { ; } } void f30(void) { int64_t x121 = -1LL; int16_t x122 = INT16_MIN; int16_t x123 = INT16_MIN; volatile int32_t t30 = 19; t30 = (((x121!=x122)!=x123)==x124); if (t30 != 0) { NG(); } else { ; } } void f31(void) { int16_t x125 = INT16_MIN; int16_t x126 = -7204; int32_t t31 = 1; t31 = (((x125!=x126)!=x127)==x128); if (t31 != 0) { NG(); } else { ; } } void f32(void) { int64_t x129 = INT64_MIN; int64_t x130 = INT64_MIN; volatile int16_t x132 = 15; t32 = (((x129!=x130)!=x131)==x132); if (t32 != 0) { NG(); } else { ; } } void f33(void) { uint32_t x133 = 31011783U; static int32_t x134 = -1; t33 = (((x133!=x134)!=x135)==x136); if (t33 != 0) { NG(); } else { ; } } void f34(void) { uint16_t x137 = 29U; volatile int32_t x138 = -19931; static volatile int32_t x139 = INT32_MAX; uint32_t x140 = UINT32_MAX; volatile int32_t t34 = 177952; t34 = (((x137!=x138)!=x139)==x140); if (t34 != 0) { NG(); } else { ; } } void f35(void) { static int8_t x142 = -7; static volatile int32_t t35 = 21385; t35 = (((x141!=x142)!=x143)==x144); if (t35 != 0) { NG(); } else { ; } } void f36(void) { int64_t x145 = -1LL; volatile uint64_t x146 = 6949673750210525272LLU; int16_t x147 = -1154; volatile int32_t t36 = 1926185; t36 = (((x145!=x146)!=x147)==x148); if (t36 != 0) { NG(); } else { ; } } void f37(void) { static int16_t x149 = INT16_MAX; uint32_t x150 = 8130721U; static uint64_t x151 = 1LLU; volatile uint32_t x152 = 30766415U; int32_t t37 = -29550198; t37 = (((x149!=x150)!=x151)==x152); if (t37 != 0) { NG(); } else { ; } } void f38(void) { static int16_t x154 = INT16_MIN; int8_t x156 = -1; int32_t t38 = -55796; t38 = (((x153!=x154)!=x155)==x156); if (t38 != 0) { NG(); } else { ; } } void f39(void) { uint32_t x157 = 1U; int32_t x158 = INT32_MIN; int64_t x159 = INT64_MIN; int8_t x160 = INT8_MIN; static int32_t t39 = 921; t39 = (((x157!=x158)!=x159)==x160); if (t39 != 0) { NG(); } else { ; } } void f40(void) { volatile int64_t x161 = 844448753LL; uint64_t x162 = 15LLU; int16_t x163 = INT16_MIN; uint16_t x164 = 402U; volatile int32_t t40 = 94; t40 = (((x161!=x162)!=x163)==x164); if (t40 != 0) { NG(); } else { ; } } void f41(void) { static int32_t x166 = 18; volatile int8_t x167 = INT8_MIN; int32_t x168 = INT32_MIN; t41 = (((x165!=x166)!=x167)==x168); if (t41 != 0) { NG(); } else { ; } } void f42(void) { int16_t x169 = INT16_MIN; static uint16_t x170 = 7084U; int8_t x171 = INT8_MAX; int16_t x172 = INT16_MAX; int32_t t42 = 73; t42 = (((x169!=x170)!=x171)==x172); if (t42 != 0) { NG(); } else { ; } } void f43(void) { static int64_t x173 = INT64_MAX; int16_t x174 = INT16_MIN; int32_t x175 = -3409704; int32_t t43 = -860; t43 = (((x173!=x174)!=x175)==x176); if (t43 != 0) { NG(); } else { ; } } void f44(void) { volatile int16_t x177 = INT16_MIN; int8_t x178 = -1; int64_t x179 = INT64_MAX; int32_t t44 = -6566; t44 = (((x177!=x178)!=x179)==x180); if (t44 != 0) { NG(); } else { ; } } void f45(void) { volatile int32_t x183 = INT32_MIN; int8_t x184 = INT8_MAX; static volatile int32_t t45 = -892; t45 = (((x181!=x182)!=x183)==x184); if (t45 != 0) { NG(); } else { ; } } void f46(void) { volatile int8_t x185 = INT8_MAX; uint16_t x186 = 15U; static uint32_t x187 = 2U; static uint64_t x188 = 33634354879224LLU; static int32_t t46 = 239; t46 = (((x185!=x186)!=x187)==x188); if (t46 != 0) { NG(); } else { ; } } void f47(void) { uint8_t x189 = UINT8_MAX; static uint32_t x190 = 39367U; uint16_t x191 = UINT16_MAX; volatile uint8_t x192 = 26U; t47 = (((x189!=x190)!=x191)==x192); if (t47 != 0) { NG(); } else { ; } } void f48(void) { volatile uint64_t x193 = UINT64_MAX; int8_t x194 = -1; uint16_t x195 = 1U; static int64_t x196 = -2239776678149372908LL; static volatile int32_t t48 = 26301937; t48 = (((x193!=x194)!=x195)==x196); if (t48 != 0) { NG(); } else { ; } } void f49(void) { uint8_t x198 = 1U; uint16_t x199 = 53U; static int32_t t49 = -8354538; t49 = (((x197!=x198)!=x199)==x200); if (t49 != 0) { NG(); } else { ; } } void f50(void) { int16_t x201 = -3; int16_t x202 = INT16_MAX; static int16_t x203 = 168; uint8_t x204 = UINT8_MAX; volatile int32_t t50 = -55; t50 = (((x201!=x202)!=x203)==x204); if (t50 != 0) { NG(); } else { ; } } void f51(void) { int32_t x205 = INT32_MIN; volatile int8_t x206 = 0; volatile uint64_t x207 = 6437460LLU; int32_t x208 = INT32_MAX; t51 = (((x205!=x206)!=x207)==x208); if (t51 != 0) { NG(); } else { ; } } void f52(void) { uint16_t x209 = 21183U; uint32_t x210 = 56222013U; int8_t x211 = INT8_MAX; static uint64_t x212 = 545640LLU; t52 = (((x209!=x210)!=x211)==x212); if (t52 != 0) { NG(); } else { ; } } void f53(void) { uint8_t x213 = 11U; uint64_t x216 = UINT64_MAX; int32_t t53 = -11362; t53 = (((x213!=x214)!=x215)==x216); if (t53 != 0) { NG(); } else { ; } } void f54(void) { uint64_t x217 = 1103128936369LLU; static volatile uint32_t x218 = UINT32_MAX; uint32_t x219 = 1058111704U; int16_t x220 = -1; static int32_t t54 = 1; t54 = (((x217!=x218)!=x219)==x220); if (t54 != 0) { NG(); } else { ; } } void f55(void) { int64_t x221 = -41142732924LL; int8_t x222 = -1; volatile int8_t x224 = INT8_MIN; volatile int32_t t55 = 1; t55 = (((x221!=x222)!=x223)==x224); if (t55 != 0) { NG(); } else { ; } } void f56(void) { int32_t x225 = -1; int8_t x226 = -9; uint8_t x227 = UINT8_MAX; static uint32_t x228 = 108185U; volatile int32_t t56 = 819874524; t56 = (((x225!=x226)!=x227)==x228); if (t56 != 0) { NG(); } else { ; } } void f57(void) { int32_t x230 = 1329; static int16_t x232 = INT16_MIN; static volatile int32_t t57 = 8438631; t57 = (((x229!=x230)!=x231)==x232); if (t57 != 0) { NG(); } else { ; } } void f58(void) { uint16_t x233 = UINT16_MAX; t58 = (((x233!=x234)!=x235)==x236); if (t58 != 0) { NG(); } else { ; } } void f59(void) { int16_t x237 = 43; uint32_t x238 = 5U; static uint64_t x239 = UINT64_MAX; volatile int8_t x240 = -26; t59 = (((x237!=x238)!=x239)==x240); if (t59 != 0) { NG(); } else { ; } } void f60(void) { uint16_t x241 = 735U; volatile int64_t x242 = INT64_MAX; static uint64_t x243 = 499825592LLU; int64_t x244 = INT64_MAX; t60 = (((x241!=x242)!=x243)==x244); if (t60 != 0) { NG(); } else { ; } } void f61(void) { int8_t x245 = 1; static uint8_t x246 = 3U; uint16_t x247 = 4716U; volatile uint8_t x248 = UINT8_MAX; t61 = (((x245!=x246)!=x247)==x248); if (t61 != 0) { NG(); } else { ; } } void f62(void) { uint8_t x250 = 21U; int32_t t62 = 107; t62 = (((x249!=x250)!=x251)==x252); if (t62 != 0) { NG(); } else { ; } } void f63(void) { static uint32_t x253 = 3287U; uint8_t x255 = 27U; int64_t x256 = INT64_MIN; int32_t t63 = -75; t63 = (((x253!=x254)!=x255)==x256); if (t63 != 0) { NG(); } else { ; } } void f64(void) { volatile int16_t x257 = INT16_MIN; uint64_t x258 = UINT64_MAX; static int16_t x259 = 1439; volatile uint64_t x260 = UINT64_MAX; static volatile int32_t t64 = -116; t64 = (((x257!=x258)!=x259)==x260); if (t64 != 0) { NG(); } else { ; } } void f65(void) { static uint32_t x261 = 575258575U; volatile uint16_t x262 = 7541U; uint16_t x263 = 13U; volatile int32_t t65 = -39; t65 = (((x261!=x262)!=x263)==x264); if (t65 != 0) { NG(); } else { ; } } void f66(void) { int32_t x265 = 64; static uint8_t x267 = UINT8_MAX; int16_t x268 = -50; volatile int32_t t66 = -465151; t66 = (((x265!=x266)!=x267)==x268); if (t66 != 0) { NG(); } else { ; } } void f67(void) { uint32_t x269 = 4749U; uint32_t x270 = UINT32_MAX; int32_t x272 = INT32_MIN; int32_t t67 = -14452070; t67 = (((x269!=x270)!=x271)==x272); if (t67 != 0) { NG(); } else { ; } } void f68(void) { int16_t x273 = INT16_MIN; volatile int8_t x274 = -1; static int32_t x275 = INT32_MAX; static volatile int32_t t68 = -1; t68 = (((x273!=x274)!=x275)==x276); if (t68 != 0) { NG(); } else { ; } } void f69(void) { volatile int32_t x277 = INT32_MIN; static uint32_t x278 = 263747U; static int16_t x279 = INT16_MIN; int16_t x280 = INT16_MAX; volatile int32_t t69 = 120085529; t69 = (((x277!=x278)!=x279)==x280); if (t69 != 0) { NG(); } else { ; } } void f70(void) { uint16_t x281 = 0U; static int64_t x283 = -1LL; int64_t x284 = INT64_MAX; int32_t t70 = 1340529; t70 = (((x281!=x282)!=x283)==x284); if (t70 != 0) { NG(); } else { ; } } void f71(void) { uint8_t x285 = 0U; volatile uint64_t x286 = UINT64_MAX; int8_t x287 = INT8_MAX; static volatile int16_t x288 = -1; volatile int32_t t71 = -98; t71 = (((x285!=x286)!=x287)==x288); if (t71 != 0) { NG(); } else { ; } } void f72(void) { int64_t x289 = INT64_MIN; int16_t x290 = INT16_MAX; int32_t x291 = -195101; int32_t t72 = 101475771; t72 = (((x289!=x290)!=x291)==x292); if (t72 != 0) { NG(); } else { ; } } void f73(void) { int32_t x293 = INT32_MIN; uint16_t x294 = 10040U; static int64_t x296 = INT64_MIN; volatile int32_t t73 = -2; t73 = (((x293!=x294)!=x295)==x296); if (t73 != 0) { NG(); } else { ; } } void f74(void) { int8_t x297 = INT8_MIN; uint32_t x298 = 231U; uint16_t x299 = 7279U; int16_t x300 = -1; t74 = (((x297!=x298)!=x299)==x300); if (t74 != 0) { NG(); } else { ; } } void f75(void) { int8_t x301 = -1; uint64_t x302 = 57264238922904LLU; static int64_t x303 = INT64_MIN; static volatile uint16_t x304 = 26080U; volatile int32_t t75 = 4854; t75 = (((x301!=x302)!=x303)==x304); if (t75 != 0) { NG(); } else { ; } } void f76(void) { volatile int64_t x305 = INT64_MIN; int16_t x306 = -2; static uint32_t x308 = 3652U; int32_t t76 = -504579419; t76 = (((x305!=x306)!=x307)==x308); if (t76 != 0) { NG(); } else { ; } } void f77(void) { volatile int32_t x309 = INT32_MIN; uint32_t x310 = UINT32_MAX; int64_t x311 = INT64_MAX; uint8_t x312 = UINT8_MAX; int32_t t77 = 834149558; t77 = (((x309!=x310)!=x311)==x312); if (t77 != 0) { NG(); } else { ; } } void f78(void) { int8_t x314 = 11; volatile uint32_t x315 = UINT32_MAX; int8_t x316 = INT8_MIN; t78 = (((x313!=x314)!=x315)==x316); if (t78 != 0) { NG(); } else { ; } } void f79(void) { volatile uint8_t x317 = 5U; int16_t x318 = 46; volatile int32_t x320 = INT32_MAX; t79 = (((x317!=x318)!=x319)==x320); if (t79 != 0) { NG(); } else { ; } } void f80(void) { volatile int8_t x321 = INT8_MAX; static int8_t x323 = 1; static int16_t x324 = 1; t80 = (((x321!=x322)!=x323)==x324); if (t80 != 0) { NG(); } else { ; } } void f81(void) { uint8_t x325 = 0U; int8_t x326 = INT8_MIN; int8_t x327 = INT8_MIN; int8_t x328 = -1; volatile int32_t t81 = -30363920; t81 = (((x325!=x326)!=x327)==x328); if (t81 != 0) { NG(); } else { ; } } void f82(void) { volatile int8_t x330 = -1; static volatile int8_t x331 = 1; int16_t x332 = -7; static int32_t t82 = 430837; t82 = (((x329!=x330)!=x331)==x332); if (t82 != 0) { NG(); } else { ; } } void f83(void) { static int64_t x333 = INT64_MAX; int32_t x334 = -1; int32_t x335 = INT32_MAX; int32_t x336 = -1; int32_t t83 = 2767; t83 = (((x333!=x334)!=x335)==x336); if (t83 != 0) { NG(); } else { ; } } void f84(void) { static int32_t x337 = 1233863; uint64_t x338 = UINT64_MAX; int8_t x339 = -1; static int16_t x340 = INT16_MIN; int32_t t84 = 2; t84 = (((x337!=x338)!=x339)==x340); if (t84 != 0) { NG(); } else { ; } } void f85(void) { uint8_t x341 = UINT8_MAX; int8_t x342 = -24; int32_t t85 = 3482; t85 = (((x341!=x342)!=x343)==x344); if (t85 != 0) { NG(); } else { ; } } void f86(void) { int16_t x345 = INT16_MIN; static int16_t x348 = INT16_MIN; t86 = (((x345!=x346)!=x347)==x348); if (t86 != 0) { NG(); } else { ; } } void f87(void) { volatile int64_t x349 = 1439450341406479LL; int64_t x350 = -1LL; uint16_t x351 = 63U; static int8_t x352 = INT8_MAX; static int32_t t87 = -14; t87 = (((x349!=x350)!=x351)==x352); if (t87 != 0) { NG(); } else { ; } } void f88(void) { int32_t x353 = INT32_MIN; int64_t x354 = INT64_MIN; volatile int32_t x355 = 0; static volatile int32_t x356 = INT32_MIN; t88 = (((x353!=x354)!=x355)==x356); if (t88 != 0) { NG(); } else { ; } } void f89(void) { int64_t x357 = -1LL; uint16_t x358 = 282U; int64_t x359 = -1LL; volatile int32_t x360 = 3; static int32_t t89 = -225; t89 = (((x357!=x358)!=x359)==x360); if (t89 != 0) { NG(); } else { ; } } void f90(void) { static uint32_t x362 = 1148549590U; int32_t x363 = INT32_MAX; int32_t x364 = -2; volatile int32_t t90 = 69813; t90 = (((x361!=x362)!=x363)==x364); if (t90 != 0) { NG(); } else { ; } } void f91(void) { static uint8_t x365 = UINT8_MAX; int32_t x366 = INT32_MIN; volatile int32_t t91 = -7261; t91 = (((x365!=x366)!=x367)==x368); if (t91 != 0) { NG(); } else { ; } } void f92(void) { volatile int64_t x369 = INT64_MIN; uint64_t x370 = 676LLU; int8_t x371 = 20; int32_t t92 = 88584; t92 = (((x369!=x370)!=x371)==x372); if (t92 != 0) { NG(); } else { ; } } void f93(void) { int64_t x373 = INT64_MIN; int8_t x374 = -1; int8_t x375 = -1; volatile uint32_t x376 = 909U; int32_t t93 = -28692685; t93 = (((x373!=x374)!=x375)==x376); if (t93 != 0) { NG(); } else { ; } } void f94(void) { volatile int16_t x377 = -115; int32_t x378 = -10910467; uint16_t x380 = UINT16_MAX; t94 = (((x377!=x378)!=x379)==x380); if (t94 != 0) { NG(); } else { ; } } void f95(void) { int64_t x381 = INT64_MIN; int8_t x382 = INT8_MAX; int16_t x383 = INT16_MAX; volatile int32_t t95 = 228966806; t95 = (((x381!=x382)!=x383)==x384); if (t95 != 0) { NG(); } else { ; } } void f96(void) { uint64_t x385 = 126LLU; int8_t x386 = INT8_MIN; int32_t x387 = INT32_MAX; int32_t t96 = 346653284; t96 = (((x385!=x386)!=x387)==x388); if (t96 != 0) { NG(); } else { ; } } void f97(void) { uint16_t x389 = UINT16_MAX; static uint8_t x391 = UINT8_MAX; volatile int8_t x392 = INT8_MAX; int32_t t97 = -81694; t97 = (((x389!=x390)!=x391)==x392); if (t97 != 0) { NG(); } else { ; } } void f98(void) { int8_t x393 = -50; int64_t x394 = INT64_MIN; static int64_t x395 = INT64_MIN; volatile uint64_t x396 = 8028336117589LLU; int32_t t98 = 381; t98 = (((x393!=x394)!=x395)==x396); if (t98 != 0) { NG(); } else { ; } } void f99(void) { volatile int16_t x397 = 15; int16_t x399 = 7916; int8_t x400 = INT8_MAX; static int32_t t99 = 0; t99 = (((x397!=x398)!=x399)==x400); if (t99 != 0) { NG(); } else { ; } } void f100(void) { static uint8_t x401 = UINT8_MAX; int16_t x403 = -2; static volatile int16_t x404 = -1; int32_t t100 = 0; t100 = (((x401!=x402)!=x403)==x404); if (t100 != 0) { NG(); } else { ; } } void f101(void) { volatile uint64_t x406 = 31661436712952LLU; static uint32_t x407 = 22109U; uint8_t x408 = 1U; t101 = (((x405!=x406)!=x407)==x408); if (t101 != 1) { NG(); } else { ; } } void f102(void) { static int64_t x410 = INT64_MIN; int32_t x411 = -19461; int8_t x412 = -18; volatile int32_t t102 = 1009472; t102 = (((x409!=x410)!=x411)==x412); if (t102 != 0) { NG(); } else { ; } } void f103(void) { static uint64_t x413 = 5569LLU; int32_t x414 = INT32_MAX; uint64_t x415 = UINT64_MAX; uint64_t x416 = 14841257954949LLU; volatile int32_t t103 = 3996; t103 = (((x413!=x414)!=x415)==x416); if (t103 != 0) { NG(); } else { ; } } void f104(void) { int8_t x417 = INT8_MIN; int8_t x418 = INT8_MIN; volatile uint64_t x419 = 2605690974362047LLU; uint64_t x420 = UINT64_MAX; volatile int32_t t104 = -2386; t104 = (((x417!=x418)!=x419)==x420); if (t104 != 0) { NG(); } else { ; } } void f105(void) { uint16_t x421 = 3010U; volatile int8_t x422 = INT8_MIN; uint8_t x423 = 76U; static volatile int64_t x424 = INT64_MAX; static int32_t t105 = 79342; t105 = (((x421!=x422)!=x423)==x424); if (t105 != 0) { NG(); } else { ; } } void f106(void) { uint8_t x425 = 118U; uint32_t x426 = 973598U; int16_t x427 = 10; int32_t t106 = -511; t106 = (((x425!=x426)!=x427)==x428); if (t106 != 0) { NG(); } else { ; } } void f107(void) { static uint16_t x429 = UINT16_MAX; uint16_t x430 = 14U; static uint32_t x431 = UINT32_MAX; int8_t x432 = -1; int32_t t107 = 126374; t107 = (((x429!=x430)!=x431)==x432); if (t107 != 0) { NG(); } else { ; } } void f108(void) { uint32_t x433 = UINT32_MAX; volatile int32_t x434 = -11999167; static int16_t x435 = INT16_MIN; static uint16_t x436 = 1213U; volatile int32_t t108 = 320; t108 = (((x433!=x434)!=x435)==x436); if (t108 != 0) { NG(); } else { ; } } void f109(void) { int8_t x437 = -1; static int32_t x438 = INT32_MIN; uint32_t x439 = 1538963937U; volatile int32_t t109 = 471232686; t109 = (((x437!=x438)!=x439)==x440); if (t109 != 0) { NG(); } else { ; } } void f110(void) { uint16_t x441 = 32524U; static volatile int16_t x442 = INT16_MIN; int8_t x444 = INT8_MIN; t110 = (((x441!=x442)!=x443)==x444); if (t110 != 0) { NG(); } else { ; } } void f111(void) { volatile int64_t x446 = INT64_MIN; volatile int64_t x447 = -1LL; int8_t x448 = INT8_MIN; int32_t t111 = 60586; t111 = (((x445!=x446)!=x447)==x448); if (t111 != 0) { NG(); } else { ; } } void f112(void) { int8_t x450 = INT8_MAX; int32_t t112 = -43018349; t112 = (((x449!=x450)!=x451)==x452); if (t112 != 0) { NG(); } else { ; } } void f113(void) { int16_t x453 = INT16_MAX; static int32_t x454 = -17831096; int8_t x455 = -1; int8_t x456 = INT8_MAX; volatile int32_t t113 = -791; t113 = (((x453!=x454)!=x455)==x456); if (t113 != 0) { NG(); } else { ; } } void f114(void) { static int8_t x458 = INT8_MIN; int64_t x459 = INT64_MIN; int32_t x460 = -1; volatile int32_t t114 = 127682623; t114 = (((x457!=x458)!=x459)==x460); if (t114 != 0) { NG(); } else { ; } } void f115(void) { static uint32_t x461 = 1579U; int64_t x462 = -9LL; int8_t x464 = -2; t115 = (((x461!=x462)!=x463)==x464); if (t115 != 0) { NG(); } else { ; } } void f116(void) { uint64_t x465 = UINT64_MAX; static uint64_t x466 = UINT64_MAX; int16_t x467 = INT16_MIN; uint16_t x468 = 7274U; t116 = (((x465!=x466)!=x467)==x468); if (t116 != 0) { NG(); } else { ; } } void f117(void) { volatile int64_t x469 = -1LL; int64_t x470 = -473519741340910536LL; volatile int8_t x471 = -1; static int64_t x472 = 2766419500438LL; static volatile int32_t t117 = 3145; t117 = (((x469!=x470)!=x471)==x472); if (t117 != 0) { NG(); } else { ; } } void f118(void) { int32_t x474 = -1; static volatile int16_t x475 = -1790; int64_t x476 = INT64_MIN; int32_t t118 = 13; t118 = (((x473!=x474)!=x475)==x476); if (t118 != 0) { NG(); } else { ; } } void f119(void) { int64_t x478 = -525979LL; int64_t x480 = 16830872388752130LL; t119 = (((x477!=x478)!=x479)==x480); if (t119 != 0) { NG(); } else { ; } } void f120(void) { int64_t x482 = -1LL; int64_t x484 = INT64_MIN; volatile int32_t t120 = -126642; t120 = (((x481!=x482)!=x483)==x484); if (t120 != 0) { NG(); } else { ; } } void f121(void) { int16_t x486 = 0; uint64_t x487 = 941139445407290879LLU; static volatile uint64_t x488 = 10624459152116433LLU; static int32_t t121 = 1090960; t121 = (((x485!=x486)!=x487)==x488); if (t121 != 0) { NG(); } else { ; } } void f122(void) { int8_t x489 = INT8_MIN; int64_t x490 = 87954117806LL; int64_t x491 = 23362275155655412LL; int64_t x492 = 4LL; int32_t t122 = -3; t122 = (((x489!=x490)!=x491)==x492); if (t122 != 0) { NG(); } else { ; } } void f123(void) { int64_t x493 = INT64_MIN; static volatile int8_t x494 = -1; static int8_t x496 = -1; t123 = (((x493!=x494)!=x495)==x496); if (t123 != 0) { NG(); } else { ; } } void f124(void) { int32_t x497 = INT32_MIN; static volatile int32_t t124 = 3; t124 = (((x497!=x498)!=x499)==x500); if (t124 != 0) { NG(); } else { ; } } void f125(void) { int64_t x502 = INT64_MAX; int16_t x504 = -1; volatile int32_t t125 = -120508; t125 = (((x501!=x502)!=x503)==x504); if (t125 != 0) { NG(); } else { ; } } void f126(void) { int8_t x505 = INT8_MIN; int16_t x506 = 0; int64_t x507 = INT64_MAX; static volatile int8_t x508 = INT8_MIN; int32_t t126 = -3391864; t126 = (((x505!=x506)!=x507)==x508); if (t126 != 0) { NG(); } else { ; } } void f127(void) { int16_t x509 = 8; volatile uint8_t x510 = 8U; int32_t x511 = -1; int8_t x512 = INT8_MIN; t127 = (((x509!=x510)!=x511)==x512); if (t127 != 0) { NG(); } else { ; } } void f128(void) { static int16_t x513 = INT16_MIN; volatile int16_t x514 = INT16_MIN; uint8_t x515 = 93U; volatile int16_t x516 = INT16_MIN; volatile int32_t t128 = 26097050; t128 = (((x513!=x514)!=x515)==x516); if (t128 != 0) { NG(); } else { ; } } void f129(void) { volatile int32_t x517 = INT32_MAX; static int16_t x518 = -2432; int8_t x519 = INT8_MIN; volatile uint16_t x520 = 1733U; int32_t t129 = -822; t129 = (((x517!=x518)!=x519)==x520); if (t129 != 0) { NG(); } else { ; } } void f130(void) { uint8_t x521 = 2U; int64_t x522 = INT64_MIN; static int16_t x523 = -1; int16_t x524 = 1585; int32_t t130 = -2671; t130 = (((x521!=x522)!=x523)==x524); if (t130 != 0) { NG(); } else { ; } } void f131(void) { volatile int16_t x525 = -2627; static int8_t x527 = INT8_MIN; volatile uint16_t x528 = 5U; volatile int32_t t131 = 1278; t131 = (((x525!=x526)!=x527)==x528); if (t131 != 0) { NG(); } else { ; } } void f132(void) { int8_t x529 = -1; int32_t x530 = 2067; uint32_t x531 = UINT32_MAX; int32_t x532 = INT32_MAX; t132 = (((x529!=x530)!=x531)==x532); if (t132 != 0) { NG(); } else { ; } } void f133(void) { uint16_t x534 = 17329U; volatile int16_t x535 = INT16_MAX; uint8_t x536 = 3U; t133 = (((x533!=x534)!=x535)==x536); if (t133 != 0) { NG(); } else { ; } } void f134(void) { int32_t x538 = -14185479; static volatile int8_t x539 = -1; uint8_t x540 = 26U; int32_t t134 = 5327834; t134 = (((x537!=x538)!=x539)==x540); if (t134 != 0) { NG(); } else { ; } } void f135(void) { int64_t x541 = INT64_MAX; volatile uint32_t x542 = 152408U; volatile int8_t x543 = INT8_MIN; uint32_t x544 = UINT32_MAX; volatile int32_t t135 = -878613345; t135 = (((x541!=x542)!=x543)==x544); if (t135 != 0) { NG(); } else { ; } } void f136(void) { static volatile int16_t x546 = INT16_MIN; int16_t x548 = -1; int32_t t136 = 407118007; t136 = (((x545!=x546)!=x547)==x548); if (t136 != 0) { NG(); } else { ; } } void f137(void) { int32_t x551 = -446001; int32_t x552 = INT32_MAX; t137 = (((x549!=x550)!=x551)==x552); if (t137 != 0) { NG(); } else { ; } } void f138(void) { int32_t x553 = 898911323; volatile int32_t x555 = 10765; uint8_t x556 = 91U; static volatile int32_t t138 = 4439; t138 = (((x553!=x554)!=x555)==x556); if (t138 != 0) { NG(); } else { ; } } void f139(void) { int32_t x557 = INT32_MIN; int32_t x558 = INT32_MIN; int16_t x559 = -6004; int64_t x560 = INT64_MIN; static volatile int32_t t139 = 65; t139 = (((x557!=x558)!=x559)==x560); if (t139 != 0) { NG(); } else { ; } } void f140(void) { uint8_t x562 = UINT8_MAX; int32_t x563 = INT32_MIN; int32_t x564 = 6686111; volatile int32_t t140 = -488; t140 = (((x561!=x562)!=x563)==x564); if (t140 != 0) { NG(); } else { ; } } void f141(void) { uint64_t x565 = UINT64_MAX; volatile uint32_t x566 = UINT32_MAX; int16_t x568 = 366; int32_t t141 = 13539; t141 = (((x565!=x566)!=x567)==x568); if (t141 != 0) { NG(); } else { ; } } void f142(void) { int64_t x569 = -2LL; uint16_t x570 = 0U; int64_t x571 = -712440499871496726LL; volatile int32_t t142 = -3309; t142 = (((x569!=x570)!=x571)==x572); if (t142 != 0) { NG(); } else { ; } } void f143(void) { static int64_t x573 = INT64_MIN; static volatile int64_t x574 = 42LL; int16_t x575 = INT16_MIN; int32_t x576 = INT32_MAX; static int32_t t143 = -7752768; t143 = (((x573!=x574)!=x575)==x576); if (t143 != 0) { NG(); } else { ; } } void f144(void) { int64_t x577 = -1LL; static int64_t x579 = INT64_MIN; volatile int8_t x580 = -1; volatile int32_t t144 = -231399492; t144 = (((x577!=x578)!=x579)==x580); if (t144 != 0) { NG(); } else { ; } } void f145(void) { volatile uint8_t x582 = 0U; int32_t x583 = -1; int32_t x584 = INT32_MAX; t145 = (((x581!=x582)!=x583)==x584); if (t145 != 0) { NG(); } else { ; } } void f146(void) { int32_t x585 = -1; int16_t x586 = 8; int32_t x588 = INT32_MIN; volatile int32_t t146 = -1148; t146 = (((x585!=x586)!=x587)==x588); if (t146 != 0) { NG(); } else { ; } } void f147(void) { int16_t x589 = 1; static int64_t x590 = -2570318414LL; uint8_t x591 = UINT8_MAX; volatile int8_t x592 = 3; int32_t t147 = 0; t147 = (((x589!=x590)!=x591)==x592); if (t147 != 0) { NG(); } else { ; } } void f148(void) { int8_t x594 = -1; uint32_t x596 = 6197U; int32_t t148 = 288; t148 = (((x593!=x594)!=x595)==x596); if (t148 != 0) { NG(); } else { ; } } void f149(void) { volatile int32_t x597 = INT32_MIN; volatile int64_t x598 = INT64_MIN; static int16_t x599 = 11311; int64_t x600 = -18977516687432253LL; static volatile int32_t t149 = -335; t149 = (((x597!=x598)!=x599)==x600); if (t149 != 0) { NG(); } else { ; } } void f150(void) { int32_t x601 = -1; uint64_t x602 = 57024298476LLU; int8_t x603 = -1; volatile int32_t t150 = 49; t150 = (((x601!=x602)!=x603)==x604); if (t150 != 0) { NG(); } else { ; } } void f151(void) { int16_t x605 = INT16_MAX; uint32_t x606 = 3802524U; uint32_t x607 = 283U; volatile int32_t t151 = 21457001; t151 = (((x605!=x606)!=x607)==x608); if (t151 != 0) { NG(); } else { ; } } void f152(void) { volatile uint16_t x609 = 2U; int64_t x610 = INT64_MAX; static uint32_t x611 = 102U; int32_t x612 = 928; t152 = (((x609!=x610)!=x611)==x612); if (t152 != 0) { NG(); } else { ; } } void f153(void) { uint64_t x613 = 1LLU; uint8_t x614 = 0U; static uint32_t x615 = 15360U; volatile int32_t t153 = 2672; t153 = (((x613!=x614)!=x615)==x616); if (t153 != 0) { NG(); } else { ; } } void f154(void) { static int8_t x617 = INT8_MIN; int8_t x620 = INT8_MIN; static volatile int32_t t154 = -26; t154 = (((x617!=x618)!=x619)==x620); if (t154 != 0) { NG(); } else { ; } } void f155(void) { static int32_t x621 = INT32_MIN; static volatile int32_t x623 = -187265; uint32_t x624 = 155U; int32_t t155 = 44268074; t155 = (((x621!=x622)!=x623)==x624); if (t155 != 0) { NG(); } else { ; } } void f156(void) { int16_t x625 = INT16_MIN; static volatile int64_t x626 = -134779393351LL; int64_t x627 = -25965025LL; int32_t x628 = 154; volatile int32_t t156 = 688150612; t156 = (((x625!=x626)!=x627)==x628); if (t156 != 0) { NG(); } else { ; } } void f157(void) { int16_t x629 = 19; static volatile uint32_t x630 = UINT32_MAX; volatile int8_t x631 = INT8_MIN; uint16_t x632 = 385U; volatile int32_t t157 = -1129; t157 = (((x629!=x630)!=x631)==x632); if (t157 != 0) { NG(); } else { ; } } void f158(void) { int16_t x633 = -1; uint16_t x635 = 69U; t158 = (((x633!=x634)!=x635)==x636); if (t158 != 0) { NG(); } else { ; } } void f159(void) { int16_t x638 = INT16_MIN; int16_t x639 = -1; volatile int64_t x640 = -1729543087061043LL; volatile int32_t t159 = -5336229; t159 = (((x637!=x638)!=x639)==x640); if (t159 != 0) { NG(); } else { ; } } void f160(void) { int8_t x641 = INT8_MAX; int32_t x642 = -822108; int8_t x643 = -1; int32_t t160 = -12811411; t160 = (((x641!=x642)!=x643)==x644); if (t160 != 0) { NG(); } else { ; } } void f161(void) { volatile int8_t x645 = INT8_MIN; int64_t x646 = INT64_MAX; uint32_t x648 = 1U; volatile int32_t t161 = 451; t161 = (((x645!=x646)!=x647)==x648); if (t161 != 1) { NG(); } else { ; } } void f162(void) { uint16_t x649 = 21077U; volatile int16_t x650 = INT16_MIN; int8_t x651 = INT8_MIN; int32_t x652 = INT32_MAX; volatile int32_t t162 = 806884505; t162 = (((x649!=x650)!=x651)==x652); if (t162 != 0) { NG(); } else { ; } } void f163(void) { int64_t x653 = INT64_MIN; static int16_t x654 = 1; int64_t x655 = -246894249333948LL; volatile int16_t x656 = 1; int32_t t163 = 2016; t163 = (((x653!=x654)!=x655)==x656); if (t163 != 1) { NG(); } else { ; } } void f164(void) { int16_t x657 = 10; int64_t x658 = 1302138615741814601LL; int64_t x659 = INT64_MIN; int32_t x660 = -1010616401; volatile int32_t t164 = 386891; t164 = (((x657!=x658)!=x659)==x660); if (t164 != 0) { NG(); } else { ; } } void f165(void) { int32_t x661 = INT32_MIN; int32_t x662 = INT32_MIN; volatile int16_t x663 = 3; t165 = (((x661!=x662)!=x663)==x664); if (t165 != 0) { NG(); } else { ; } } void f166(void) { int16_t x665 = INT16_MIN; int32_t x666 = INT32_MAX; int16_t x667 = INT16_MIN; t166 = (((x665!=x666)!=x667)==x668); if (t166 != 0) { NG(); } else { ; } } void f167(void) { uint64_t x669 = 3661521012846LLU; int32_t x670 = INT32_MAX; int32_t x671 = 48938636; int32_t x672 = INT32_MIN; int32_t t167 = 5218487; t167 = (((x669!=x670)!=x671)==x672); if (t167 != 0) { NG(); } else { ; } } void f168(void) { int16_t x673 = INT16_MIN; static int64_t x674 = -58424LL; int64_t x675 = INT64_MAX; uint8_t x676 = UINT8_MAX; t168 = (((x673!=x674)!=x675)==x676); if (t168 != 0) { NG(); } else { ; } } void f169(void) { volatile uint16_t x678 = 189U; volatile int32_t t169 = 1; t169 = (((x677!=x678)!=x679)==x680); if (t169 != 0) { NG(); } else { ; } } void f170(void) { int32_t x681 = INT32_MAX; uint32_t x682 = 3U; volatile int16_t x683 = 55; int16_t x684 = INT16_MIN; volatile int32_t t170 = -25343453; t170 = (((x681!=x682)!=x683)==x684); if (t170 != 0) { NG(); } else { ; } } void f171(void) { int64_t x685 = -128529414108522LL; int64_t x687 = INT64_MIN; volatile int32_t t171 = -6483283; t171 = (((x685!=x686)!=x687)==x688); if (t171 != 0) { NG(); } else { ; } } void f172(void) { static volatile int64_t x689 = INT64_MIN; int16_t x691 = INT16_MAX; t172 = (((x689!=x690)!=x691)==x692); if (t172 != 0) { NG(); } else { ; } } void f173(void) { int64_t x693 = -15LL; uint64_t x694 = UINT64_MAX; int8_t x695 = INT8_MAX; int16_t x696 = INT16_MIN; static int32_t t173 = -45007504; t173 = (((x693!=x694)!=x695)==x696); if (t173 != 0) { NG(); } else { ; } } void f174(void) { uint16_t x697 = 2U; int32_t x699 = -1; static int16_t x700 = -1; volatile int32_t t174 = 13767694; t174 = (((x697!=x698)!=x699)==x700); if (t174 != 0) { NG(); } else { ; } } void f175(void) { int64_t x701 = INT64_MIN; int8_t x703 = 13; static uint32_t x704 = UINT32_MAX; static volatile int32_t t175 = -15; t175 = (((x701!=x702)!=x703)==x704); if (t175 != 0) { NG(); } else { ; } } void f176(void) { int8_t x705 = INT8_MAX; int32_t x706 = -1; volatile int16_t x707 = INT16_MIN; volatile int32_t t176 = -113421099; t176 = (((x705!=x706)!=x707)==x708); if (t176 != 0) { NG(); } else { ; } } void f177(void) { int64_t x709 = INT64_MAX; static volatile uint8_t x710 = 23U; static int16_t x711 = INT16_MIN; int16_t x712 = -1; int32_t t177 = 297739; t177 = (((x709!=x710)!=x711)==x712); if (t177 != 0) { NG(); } else { ; } } void f178(void) { uint8_t x715 = UINT8_MAX; int16_t x716 = INT16_MAX; t178 = (((x713!=x714)!=x715)==x716); if (t178 != 0) { NG(); } else { ; } } void f179(void) { volatile int32_t x717 = INT32_MAX; int8_t x718 = -1; int8_t x719 = -23; volatile int32_t x720 = INT32_MIN; int32_t t179 = 61393404; t179 = (((x717!=x718)!=x719)==x720); if (t179 != 0) { NG(); } else { ; } } void f180(void) { static int32_t x721 = -58901279; static int16_t x722 = -1; int8_t x723 = INT8_MIN; volatile int64_t x724 = INT64_MIN; int32_t t180 = -115234; t180 = (((x721!=x722)!=x723)==x724); if (t180 != 0) { NG(); } else { ; } } void f181(void) { int64_t x725 = -1LL; int64_t x726 = 3583128686LL; int32_t t181 = 2; t181 = (((x725!=x726)!=x727)==x728); if (t181 != 0) { NG(); } else { ; } } void f182(void) { int8_t x729 = -1; volatile int64_t x730 = INT64_MAX; int8_t x731 = INT8_MIN; static int16_t x732 = 1; int32_t t182 = -640157999; t182 = (((x729!=x730)!=x731)==x732); if (t182 != 1) { NG(); } else { ; } } void f183(void) { uint32_t x734 = 11877U; static int8_t x735 = INT8_MIN; volatile int8_t x736 = -1; int32_t t183 = -294; t183 = (((x733!=x734)!=x735)==x736); if (t183 != 0) { NG(); } else { ; } } void f184(void) { uint64_t x737 = 58255LLU; int8_t x738 = INT8_MAX; uint16_t x739 = UINT16_MAX; int64_t x740 = INT64_MIN; volatile int32_t t184 = 47494; t184 = (((x737!=x738)!=x739)==x740); if (t184 != 0) { NG(); } else { ; } } void f185(void) { int32_t x741 = INT32_MAX; static int8_t x743 = 4; static int32_t t185 = -20; t185 = (((x741!=x742)!=x743)==x744); if (t185 != 0) { NG(); } else { ; } } void f186(void) { int8_t x745 = -1; uint8_t x746 = 10U; int16_t x747 = -4; int8_t x748 = 1; volatile int32_t t186 = 262102182; t186 = (((x745!=x746)!=x747)==x748); if (t186 != 1) { NG(); } else { ; } } void f187(void) { int16_t x749 = INT16_MIN; uint16_t x751 = 4U; static int32_t t187 = -4983; t187 = (((x749!=x750)!=x751)==x752); if (t187 != 0) { NG(); } else { ; } } void f188(void) { int32_t x753 = INT32_MIN; int8_t x754 = -14; int64_t x755 = INT64_MAX; volatile int16_t x756 = INT16_MIN; static volatile int32_t t188 = -3682778; t188 = (((x753!=x754)!=x755)==x756); if (t188 != 0) { NG(); } else { ; } } void f189(void) { int16_t x757 = 4091; int16_t x758 = INT16_MIN; static uint16_t x760 = 0U; volatile int32_t t189 = -28054; t189 = (((x757!=x758)!=x759)==x760); if (t189 != 0) { NG(); } else { ; } } void f190(void) { uint16_t x761 = UINT16_MAX; int16_t x762 = -1; int16_t x764 = INT16_MIN; volatile int32_t t190 = 1; t190 = (((x761!=x762)!=x763)==x764); if (t190 != 0) { NG(); } else { ; } } void f191(void) { volatile int8_t x767 = INT8_MIN; uint32_t x768 = UINT32_MAX; volatile int32_t t191 = -3646; t191 = (((x765!=x766)!=x767)==x768); if (t191 != 0) { NG(); } else { ; } } void f192(void) { static volatile int16_t x769 = -71; uint64_t x770 = UINT64_MAX; int32_t x771 = 1614013; int64_t x772 = -1LL; volatile int32_t t192 = 2; t192 = (((x769!=x770)!=x771)==x772); if (t192 != 0) { NG(); } else { ; } } void f193(void) { int8_t x773 = -1; volatile int64_t x774 = 119988LL; int16_t x775 = -2686; volatile uint8_t x776 = 2U; t193 = (((x773!=x774)!=x775)==x776); if (t193 != 0) { NG(); } else { ; } } void f194(void) { volatile int16_t x777 = INT16_MIN; uint64_t x778 = 66517744LLU; static int16_t x779 = INT16_MIN; uint8_t x780 = 27U; t194 = (((x777!=x778)!=x779)==x780); if (t194 != 0) { NG(); } else { ; } } void f195(void) { uint32_t x781 = UINT32_MAX; int16_t x783 = -1; volatile int32_t t195 = 263; t195 = (((x781!=x782)!=x783)==x784); if (t195 != 0) { NG(); } else { ; } } void f196(void) { int64_t x785 = INT64_MAX; int16_t x786 = INT16_MIN; uint8_t x787 = 1U; uint32_t x788 = 4728549U; int32_t t196 = 6; t196 = (((x785!=x786)!=x787)==x788); if (t196 != 0) { NG(); } else { ; } } void f197(void) { volatile int16_t x790 = INT16_MAX; uint8_t x791 = UINT8_MAX; uint64_t x792 = UINT64_MAX; t197 = (((x789!=x790)!=x791)==x792); if (t197 != 0) { NG(); } else { ; } } void f198(void) { volatile uint16_t x793 = 13U; int8_t x794 = INT8_MIN; static int16_t x795 = -1932; static volatile uint8_t x796 = 1U; static volatile int32_t t198 = -402433490; t198 = (((x793!=x794)!=x795)==x796); if (t198 != 1) { NG(); } else { ; } } void f199(void) { int16_t x797 = INT16_MAX; int64_t x798 = 411895089408LL; static int32_t x799 = -1; volatile uint64_t x800 = 155LLU; volatile int32_t t199 = 2409; t199 = (((x797!=x798)!=x799)==x800); if (t199 != 0) { NG(); } else { ; } } int main(void) { f0(); f1(); f2(); f3(); f4(); f5(); f6(); f7(); f8(); f9(); f10(); f11(); f12(); f13(); f14(); f15(); f16(); f17(); f18(); f19(); f20(); f21(); f22(); f23(); f24(); f25(); f26(); f27(); f28(); f29(); f30(); f31(); f32(); f33(); f34(); f35(); f36(); f37(); f38(); f39(); f40(); f41(); f42(); f43(); f44(); f45(); f46(); f47(); f48(); f49(); f50(); f51(); f52(); f53(); f54(); f55(); f56(); f57(); f58(); f59(); f60(); f61(); f62(); f63(); f64(); f65(); f66(); f67(); f68(); f69(); f70(); f71(); f72(); f73(); f74(); f75(); f76(); f77(); f78(); f79(); f80(); f81(); f82(); f83(); f84(); f85(); f86(); f87(); f88(); f89(); f90(); f91(); f92(); f93(); f94(); f95(); f96(); f97(); f98(); f99(); f100(); f101(); f102(); f103(); f104(); f105(); f106(); f107(); f108(); f109(); f110(); f111(); f112(); f113(); f114(); f115(); f116(); f117(); f118(); f119(); f120(); f121(); f122(); f123(); f124(); f125(); f126(); f127(); f128(); f129(); f130(); f131(); f132(); f133(); f134(); f135(); f136(); f137(); f138(); f139(); f140(); f141(); f142(); f143(); f144(); f145(); f146(); f147(); f148(); f149(); f150(); f151(); f152(); f153(); f154(); f155(); f156(); f157(); f158(); f159(); f160(); f161(); f162(); f163(); f164(); f165(); f166(); f167(); f168(); f169(); f170(); f171(); f172(); f173(); f174(); f175(); f176(); f177(); f178(); f179(); f180(); f181(); f182(); f183(); f184(); f185(); f186(); f187(); f188(); f189(); f190(); f191(); f192(); f193(); f194(); f195(); f196(); f197(); f198(); f199(); return 0; }
83375.c
/* ** EPITECH PROJECT, 2021 ** my_rpg ** File description: ** function for pause button */ #include "rpg.h" void launch_save(head_t *head, button_t *button) { char *path_save_file; if (button == head->scenes->load_save_menu->first_save_button) { path_save_file = "saves/save_1.json"; head->technical->index_save = 1; } else if (button == head->scenes->load_save_menu->second_save_button) { path_save_file = "saves/save_2.json"; head->technical->index_save = 2; } else { path_save_file = "saves/save_3.json"; head->technical->index_save = 3; } load_save(head, path_save_file); } void delete_save_button(head_t *head, button_t *button) { char *path_save_file; if (button == head->scenes->load_save_menu->delete_first_save) path_save_file = "saves/save_1.json"; if (button == head->scenes->load_save_menu->delete_second_save) path_save_file = "saves/save_2.json"; if (button == head->scenes->load_save_menu->delete_third_save) path_save_file = "saves/save_3.json"; delete_save(path_save_file); update_load_save_menu(head); }
755799.c
/* * Licensed Materials - Property of IBM * * trousers - An open source TCG Software Stack * * (C) Copyright International Business Machines Corp. 2004-2006 * */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/mman.h> #include <errno.h> #include "trousers/tss.h" #include "trousers/trousers.h" #include "trousers_types.h" #include "trousers_types.h" #include "spi_utils.h" #include "capabilities.h" #include "tsplog.h" #include "obj.h" UINT16 get_num_pcrs(TSS_HCONTEXT tspContext) { TSS_RESULT result; static UINT16 ret = 0; UINT32 subCap; UINT32 respSize; BYTE *resp; if (ret != 0) return ret; subCap = endian32(TPM_CAP_PROP_PCR); if ((result = TCS_API(tspContext)->GetTPMCapability(tspContext, TPM_CAP_PROPERTY, sizeof(UINT32), (BYTE *)&subCap, &respSize, &resp))) { if ((resp = (BYTE *)getenv("TSS_DEFAULT_NUM_PCRS")) == NULL) return TSS_DEFAULT_NUM_PCRS; /* don't set ret here, next time we may be connected */ return atoi((char *)resp); } ret = (UINT16)Decode_UINT32(resp); free(resp); return ret; } TSS_RESULT pcrs_calc_composite(TPM_PCR_SELECTION *select, TPM_PCRVALUE *arrayOfPcrs, TPM_DIGEST *digestOut) { UINT32 size, index; BYTE mask; BYTE hashBlob[1024]; UINT32 numPCRs = 0; UINT64 offset = 0; UINT64 sizeOffset = 0; if (select->sizeOfSelect > 0) { sizeOffset = 0; Trspi_LoadBlob_PCR_SELECTION(&sizeOffset, hashBlob, select); offset = sizeOffset + 4; for (size = 0; size < select->sizeOfSelect; size++) { for (index = 0, mask = 1; index < 8; index++, mask = mask << 1) { if (select->pcrSelect[size] & mask) { memcpy(&hashBlob[(numPCRs * TPM_SHA1_160_HASH_LEN) + offset], arrayOfPcrs[index + (size << 3)].digest, TPM_SHA1_160_HASH_LEN); numPCRs++; } } } if (numPCRs > 0) { offset += (numPCRs * TPM_SHA1_160_HASH_LEN); UINT32ToArray(numPCRs * TPM_SHA1_160_HASH_LEN, &hashBlob[sizeOffset]); return Trspi_Hash(TSS_HASH_SHA1, offset, hashBlob, digestOut->digest); } } return TSPERR(TSS_E_INTERNAL_ERROR); } TSS_RESULT pcrs_sanity_check_selection(TSS_HCONTEXT tspContext, struct tr_pcrs_obj *pcrs, TPM_PCR_SELECTION *select) { UINT16 num_pcrs, bytes_to_hold; if ((num_pcrs = get_num_pcrs(tspContext)) == 0) return TSPERR(TSS_E_INTERNAL_ERROR); bytes_to_hold = num_pcrs / 8; /* Is the current select object going to be interpretable by the TPM? * If the select object is of a size greater than the one the TPM * wants, just calculate the composite hash and let the TPM return an * error code to the user. If its less than the size of the one the * TPM wants, add extra zero bytes until its the right size. */ if (bytes_to_hold > select->sizeOfSelect) { if ((select->pcrSelect = realloc(select->pcrSelect, bytes_to_hold)) == NULL) { LogError("malloc of %hu bytes failed.", bytes_to_hold); return TSPERR(TSS_E_OUTOFMEMORY); } /* set the newly allocated bytes to 0 */ __tspi_memset(&select->pcrSelect[select->sizeOfSelect], 0, bytes_to_hold - select->sizeOfSelect); select->sizeOfSelect = bytes_to_hold; /* realloc the pcr array as well */ if ((pcrs->pcrs = realloc(pcrs->pcrs, (bytes_to_hold * 8) * TPM_SHA1_160_HASH_LEN)) == NULL) { LogError("malloc of %d bytes failed.", (bytes_to_hold * 8) * TPM_SHA1_160_HASH_LEN); return TSPERR(TSS_E_OUTOFMEMORY); } } #ifdef TSS_DEBUG { int i; for (i = 0; i < select->sizeOfSelect * 8; i++) { if (select->pcrSelect[i/8] & (1 << (i % 8))) { LogDebug("PCR%d: Selected", i); LogBlobData(APPID, TPM_SHA1_160_HASH_LEN, (unsigned char *)&pcrs->pcrs[i]); } else { LogDebug("PCR%d: Not Selected", i); } } } #endif return TSS_SUCCESS; }
695672.c
/** testme.c - MakeMe unit test framework This program runs a script of the same name as this script. Copyright (c) All Rights Reserved. See details at the end of the file. */ /********************************** Includes **********************************/ #include "ejs.h" /*********************************** Locals ***********************************/ typedef struct App { Ejs *ejs; cchar *script; } App; static App *app; static cchar *findTestMe(); static void manageApp(App *app, int flags); /************************************ Code ************************************/ MAIN(ejsMain, int argc, char **argv, char **envp) { Mpr *mpr; Ejs *ejs; EcCompiler *ec; char *argp, *searchPath, *homeDir, *logSpec, *traceSpec; int nextArg, err, flags; /* Initialize Multithreaded Portable Runtime (MPR) */ mpr = mprCreate(argc, argv, 0); app = mprAllocObj(App, manageApp); mprAddRoot(app); mprAddStandardSignals(); if (httpCreate(HTTP_CLIENT_SIDE | HTTP_SERVER_SIDE) < 0) { mprLog("me", 0, "Cannot create HTTP services"); return EJS_ERR; } if (mprStart(mpr) < 0) { mprLog("me", 0, "Cannot start mpr services"); return EJS_ERR; } argc = mpr->argc; argv = (char**) mpr->argv; err = 0; logSpec = 0; traceSpec = 0; searchPath = 0; for (nextArg = 1; nextArg < argc; nextArg++) { argp = argv[nextArg]; if (*argp != '-') { break; } if (smatch(argp, "--chdir") || smatch(argp, "--home") || smatch(argp, "-C")) { if (nextArg >= argc) { err++; } else { homeDir = argv[++nextArg]; if (chdir((char*) homeDir) < 0) { mprLog("me", 0, "Cannot change directory to %s", homeDir); } } } else if (smatch(argp, "--debugger") || smatch(argp, "-D")) { mprSetDebugMode(1); } else if (smatch(argp, "--log")) { if (nextArg >= argc) { err++; } else { logSpec = argv[++nextArg]; } } else if (smatch(argp, "--name")) { /* Just ignore. Used to tag commands with a unique command line */ nextArg++; } else if (smatch(argp, "--search") || smatch(argp, "--searchpath")) { if (nextArg >= argc) { err++; } else { searchPath = argv[++nextArg]; } } else if (smatch(argp, "--trace") || smatch(argp, "-t")) { if (nextArg >= argc) { err++; } else { traceSpec = argv[++nextArg]; } } else if (smatch(argp, "--version") || smatch(argp, "-V")) { mprPrintf("%s\n", ME_VERSION); return 0; } else if (*argp == '-' && isdigit((uchar) argp[1])) { if (!logSpec) { logSpec = sfmt("stdout:%d", (int) stoi(&argp[1])); } if (!traceSpec) { traceSpec = sfmt("stdout:%d", (int) stoi(&argp[1])); } } else { /* Ignore */ } } if (logSpec) { mprStartLogging(logSpec, MPR_LOG_CMDLINE); } else { mprStartLogging("stdout", MPR_LOG_CMDLINE); } if (traceSpec) { httpStartTracing(traceSpec); } if ((app->script = findTestMe()) == 0) { mprLog("me", 0, "Cannot find testme.es or testme.mod"); return MPR_ERR_CANT_FIND; } argv[0] = (char*) app->script; if ((ejs = ejsCreateVM(argc, (cchar**) &argv[0], 0)) == 0) { return MPR_ERR_MEMORY; } mprStartDispatcher(ejs->dispatcher); app->ejs = ejs; if (ejsLoadModules(ejs, searchPath, NULL) < 0) { return MPR_ERR_CANT_READ; } flags = EC_FLAGS_BIND | EC_FLAGS_DEBUG | EC_FLAGS_NO_OUT | EC_FLAGS_THROW; if ((ec = ecCreateCompiler(ejs, flags)) == 0) { return MPR_ERR_MEMORY; } mprAddRoot(ec); ecSetOptimizeLevel(ec, 9); ecSetWarnLevel(ec, 1); if (ecCompile(ec, 1, (char**) &app->script) < 0) { if (flags & EC_FLAGS_THROW) { ejsThrowSyntaxError(ejs, "%s", ec->errorMsg ? ec->errorMsg : "Cannot parse script"); ejsReportError(ejs, "Error in script"); } err = MPR_ERR; } else { mprRemoveRoot(ec); if (ejsRunProgram(ejs, NULL, NULL) < 0) { ejsReportError(ejs, "Error in script"); err = MPR_ERR; } } if (err) { mprSetExitStatus(err); } app->ejs = 0; return mprGetExitStatus(); } static void manageApp(App *app, int flags) { if (flags & MPR_MANAGE_MARK) { mprMark(app->ejs); mprMark(app->script); } } static cchar *findTestMe() { cchar *path; path = mprJoinPath(mprGetAppDir(), "testme.mod"); if (mprPathExists(path, R_OK)) { return path; } path = mprJoinPath(mprGetAppDir(), "testme.es"); if (mprPathExists(path, R_OK)) { return path; } return 0; } /* @copy default Copyright (c) Embedthis Software. All Rights Reserved. This software is distributed under commercial and open source licenses. You may use the Embedthis Open Source license or you may acquire a commercial license from Embedthis Software. You agree to be fully bound by the terms of either license. Consult the LICENSE.md distributed with this software for full details and other copyrights. Local variables: tab-width: 4 c-basic-offset: 4 End: vim: sw=4 ts=4 expandtab @end */
929992.c
/** * Created by ywh on 01/08/2020. */ #include <stdlib.h> #include <limits.h> #include <stdio.h> /** * * @param a * @param b * @return */ static int compare(const void *a, const void *b) { return *(int *) a - *(int *) b; } /** * 求和最接近目标值的三个数 * * @param nums * @param numsSize * @param target * @return */ int threeSumClosest(int *nums, int numsSize, int target) { int ret = 0, min = INT_MAX, diff; qsort(nums, numsSize, sizeof(*nums), compare); for (int k = numsSize - 1; k >= 2; k--) { int left = 0, right = k - 1, sum; while (left < right) { sum = nums[left] + nums[right] + nums[k]; if (sum == target) { return target; } if (sum < target) { left++; } else { right--; } diff = abs(target - sum); if (diff < min) { ret = sum; min = diff; } } } return ret; }
940058.c
/** * @brief Example usage of GPIO peripheral. Three LEDs are toggled using * GPIO functionality. A hardware-to-software interrupt is set up and * triggered by a button switch. * * The tsb0 board has three LEDs (red, green, blue) connected to ports * PB11, PB12, PA5 respectively. The button switch is connected to port * PF4. LED and button locations (pin and port numbers) can be found from * the tsb0 board wiring schematics. * * EFR32 Application Note on GPIO * https://www.silabs.com/documents/public/application-notes/an0012-efm32-gpio.pdf * * EFR32MG12 Wireless Gecko Reference Manual (GPIO p1105) * https://www.silabs.com/documents/public/reference-manuals/efr32xg12-rm.pdf * * GPIO API documentation * https://docs.silabs.com/mcu/latest/efr32mg12/group-GPIO * * ARM RTOS API * https://arm-software.github.io/CMSIS_5/RTOS2/html/group__CMSIS__RTOS.html * * Copyright Thinnect Inc. 2019 * Copyright ProLab TTÜ 2022 * @license MIT * @author Johannes Ehala */ #include <stdio.h> #include <stdint.h> #include <string.h> #include <inttypes.h> #include "retargetserial.h" #include "cmsis_os2.h" #include "platform.h" #include "SignatureArea.h" #include "DeviceSignature.h" #include "loggers_ext.h" #include "logger_fwrite.h" #include "loglevels.h" #define __MODUUL__ "main" #define __LOG_LEVEL__ (LOG_LEVEL_main & BASE_LOG_LEVEL) #include "log.h" // Include the information header binary #include "incbin.h" INCBIN(Header, "header.bin"); // Heartbeat thread, initialize GPIO and print heartbeat messages. void hp_loop () { #define ESWGPIO_HB_DELAY 10 // Heartbeat message delay, seconds // TODO Initialize GPIO. for (;;) { osDelay(ESWGPIO_HB_DELAY*osKernelGetTickFreq()); info1("Heartbeat"); } } // TODO LED toggle thread. // TODO Button interrupt thread. int logger_fwrite_boot (const char *ptr, int len) { fwrite(ptr, len, 1, stdout); fflush(stdout); return len; } int main () { PLATFORM_Init(); // Configure log message output RETARGET_SerialInit(); log_init(BASE_LOG_LEVEL, &logger_fwrite_boot, NULL); info1("ESW-GPIO "VERSION_STR" (%d.%d.%d)", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); // Initialize OS kernel. osKernelInitialize(); // Create a thread. const osThreadAttr_t hp_thread_attr = { .name = "hp" }; osThreadNew(hp_loop, NULL, &hp_thread_attr); if (osKernelReady == osKernelGetState()) { // Switch to a thread-safe logger logger_fwrite_init(); log_init(BASE_LOG_LEVEL, &logger_fwrite, NULL); // Start the kernel osKernelStart(); } else { err1("!osKernelReady"); } for(;;); }
232590.c
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char season[20], group_type[20]; scanf("%s %s", season, group_type); int students, nights; scanf("%d %d", &students, &nights); double price = 0.0; char sport[20]; if(strcmp(season, "Winter") == 0) { if(strcmp(group_type, "boys") == 0) { price = students * 9.60 * nights; strcpy(sport, "Judo"); } else if(strcmp(group_type, "girls") == 0) { price = students * 9.60 * nights; strcpy(sport, "Gymnastics"); } else if(strcmp(group_type, "mixed") == 0) { price = students * 10.00 * nights; strcpy(sport, "Ski"); } } else if(strcmp(season, "Spring") == 0) { if(strcmp(group_type, "boys") == 0) { price = students * 7.20 * nights; strcpy(sport, "Tennis"); } else if(strcmp(group_type, "girls") == 0) { price = students * 7.20 * nights; strcpy(sport, "Athletics"); } else if(strcmp(group_type, "mixed") == 0) { price = students * 9.50 * nights; strcpy(sport, "Cycling"); } } else if(strcmp(season, "Summer") == 0) { if(strcmp(group_type, "boys") == 0) { price = students * 15.00 * nights; strcpy(sport, "Football"); } else if(strcmp(group_type, "girls") == 0) { price = students * 15.00 * nights; strcpy(sport, "Volleyball"); } else if(strcmp(group_type, "mixed") == 0) { price = students * 20.00 * nights; strcpy(sport, "Swimming"); } } if(students >= 50) { price *= 0.50; } else if(students >= 20 && students < 50) { price *= 0.85; } else if(students >= 10 && students < 20) { price *= 0.95; } printf("%s %.2lf lv.", sport, price); return 0; }
714903.c
/** * \file md_wrap.c * * \brief Generic message digest wrapper for mbed TLS * * \author Adriaan de Jong <[email protected]> * * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved * SPDX-License-Identifier: GPL-2.0 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This file is part of mbed TLS (https://tls.mbed.org) */ #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #if defined(MBEDTLS_MD_C) #include "mbedtls/md_internal.h" #if defined(MBEDTLS_MD2_C) #include "mbedtls/md2.h" #endif #if defined(MBEDTLS_MD4_C) #include "mbedtls/md4.h" #endif #if defined(MBEDTLS_MD5_C) #include "mbedtls/md5.h" #endif #if defined(MBEDTLS_RIPEMD160_C) #include "mbedtls/ripemd160.h" #endif #if defined(MBEDTLS_SHA1_C) #include "mbedtls/sha1.h" #endif #if defined(MBEDTLS_SHA256_C) #include "mbedtls/sha256.h" #endif #if defined(MBEDTLS_SHA512_C) #include "mbedtls/sha512.h" #endif #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" #else #include <stdlib.h> #define mbedtls_calloc calloc #define mbedtls_free free #endif #if defined(MBEDTLS_MD2_C) static int md2_starts_wrap( void *ctx ) { return( mbedtls_md2_starts_ret( (mbedtls_md2_context *) ctx ) ); } static int md2_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) { return( mbedtls_md2_update_ret( (mbedtls_md2_context *) ctx, input, ilen ) ); } static int md2_finish_wrap( void *ctx, unsigned char *output ) { return( mbedtls_md2_finish_ret( (mbedtls_md2_context *) ctx, output ) ); } static void *md2_ctx_alloc( void ) { void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md2_context ) ); if( ctx != NULL ) mbedtls_md2_init( (mbedtls_md2_context *) ctx ); return( ctx ); } static void md2_ctx_free( void *ctx ) { mbedtls_md2_free( (mbedtls_md2_context *) ctx ); mbedtls_free( ctx ); } static void md2_clone_wrap( void *dst, const void *src ) { mbedtls_md2_clone( (mbedtls_md2_context *) dst, (const mbedtls_md2_context *) src ); } static int md2_process_wrap( void *ctx, const unsigned char *data ) { ((void) data); return( mbedtls_internal_md2_process( (mbedtls_md2_context *) ctx ) ); } const mbedtls_md_info_t mbedtls_md2_info = { MBEDTLS_MD_MD2, "MD2", 16, 16, md2_starts_wrap, md2_update_wrap, md2_finish_wrap, mbedtls_md2_ret, md2_ctx_alloc, md2_ctx_free, md2_clone_wrap, md2_process_wrap, }; #endif /* MBEDTLS_MD2_C */ #if defined(MBEDTLS_MD4_C) static int md4_starts_wrap( void *ctx ) { return( mbedtls_md4_starts_ret( (mbedtls_md4_context *) ctx ) ); } static int md4_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) { return( mbedtls_md4_update_ret( (mbedtls_md4_context *) ctx, input, ilen ) ); } static int md4_finish_wrap( void *ctx, unsigned char *output ) { return( mbedtls_md4_finish_ret( (mbedtls_md4_context *) ctx, output ) ); } static void *md4_ctx_alloc( void ) { void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md4_context ) ); if( ctx != NULL ) mbedtls_md4_init( (mbedtls_md4_context *) ctx ); return( ctx ); } static void md4_ctx_free( void *ctx ) { mbedtls_md4_free( (mbedtls_md4_context *) ctx ); mbedtls_free( ctx ); } static void md4_clone_wrap( void *dst, const void *src ) { mbedtls_md4_clone( (mbedtls_md4_context *) dst, (const mbedtls_md4_context *) src ); } static int md4_process_wrap( void *ctx, const unsigned char *data ) { return( mbedtls_internal_md4_process( (mbedtls_md4_context *) ctx, data ) ); } const mbedtls_md_info_t mbedtls_md4_info = { MBEDTLS_MD_MD4, "MD4", 16, 64, md4_starts_wrap, md4_update_wrap, md4_finish_wrap, mbedtls_md4_ret, md4_ctx_alloc, md4_ctx_free, md4_clone_wrap, md4_process_wrap, }; #endif /* MBEDTLS_MD4_C */ #if defined(MBEDTLS_MD5_C) static int md5_starts_wrap( void *ctx ) { return( mbedtls_md5_starts_ret( (mbedtls_md5_context *) ctx ) ); } static int md5_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) { return( mbedtls_md5_update_ret( (mbedtls_md5_context *) ctx, input, ilen ) ); } static int md5_finish_wrap( void *ctx, unsigned char *output ) { return( mbedtls_md5_finish_ret( (mbedtls_md5_context *) ctx, output ) ); } static void *md5_ctx_alloc( void ) { void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_md5_context ) ); if( ctx != NULL ) mbedtls_md5_init( (mbedtls_md5_context *) ctx ); return( ctx ); } static void md5_ctx_free( void *ctx ) { mbedtls_md5_free( (mbedtls_md5_context *) ctx ); mbedtls_free( ctx ); } static void md5_clone_wrap( void *dst, const void *src ) { mbedtls_md5_clone( (mbedtls_md5_context *) dst, (const mbedtls_md5_context *) src ); } static int md5_process_wrap( void *ctx, const unsigned char *data ) { return( mbedtls_internal_md5_process( (mbedtls_md5_context *) ctx, data ) ); } const mbedtls_md_info_t mbedtls_md5_info = { MBEDTLS_MD_MD5, "MD5", 16, 64, md5_starts_wrap, md5_update_wrap, md5_finish_wrap, mbedtls_md5_ret, md5_ctx_alloc, md5_ctx_free, md5_clone_wrap, md5_process_wrap, }; #endif /* MBEDTLS_MD5_C */ #if defined(MBEDTLS_RIPEMD160_C) static int ripemd160_starts_wrap( void *ctx ) { return( mbedtls_ripemd160_starts_ret( (mbedtls_ripemd160_context *) ctx ) ); } static int ripemd160_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) { return( mbedtls_ripemd160_update_ret( (mbedtls_ripemd160_context *) ctx, input, ilen ) ); } static int ripemd160_finish_wrap( void *ctx, unsigned char *output ) { return( mbedtls_ripemd160_finish_ret( (mbedtls_ripemd160_context *) ctx, output ) ); } static void *ripemd160_ctx_alloc( void ) { void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ripemd160_context ) ); if( ctx != NULL ) mbedtls_ripemd160_init( (mbedtls_ripemd160_context *) ctx ); return( ctx ); } static void ripemd160_ctx_free( void *ctx ) { mbedtls_ripemd160_free( (mbedtls_ripemd160_context *) ctx ); mbedtls_free( ctx ); } static void ripemd160_clone_wrap( void *dst, const void *src ) { mbedtls_ripemd160_clone( (mbedtls_ripemd160_context *) dst, (const mbedtls_ripemd160_context *) src ); } static int ripemd160_process_wrap( void *ctx, const unsigned char *data ) { return( mbedtls_internal_ripemd160_process( (mbedtls_ripemd160_context *) ctx, data ) ); } const mbedtls_md_info_t mbedtls_ripemd160_info = { MBEDTLS_MD_RIPEMD160, "RIPEMD160", 20, 64, ripemd160_starts_wrap, ripemd160_update_wrap, ripemd160_finish_wrap, mbedtls_ripemd160_ret, ripemd160_ctx_alloc, ripemd160_ctx_free, ripemd160_clone_wrap, ripemd160_process_wrap, }; #endif /* MBEDTLS_RIPEMD160_C */ #if defined(MBEDTLS_SHA1_C) static int sha1_starts_wrap( void *ctx ) { return( mbedtls_sha1_starts_ret( (mbedtls_sha1_context *) ctx ) ); } static int sha1_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) { return( mbedtls_sha1_update_ret( (mbedtls_sha1_context *) ctx, input, ilen ) ); } static int sha1_finish_wrap( void *ctx, unsigned char *output ) { return( mbedtls_sha1_finish_ret( (mbedtls_sha1_context *) ctx, output ) ); } static void *sha1_ctx_alloc( void ) { void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha1_context ) ); if( ctx != NULL ) mbedtls_sha1_init( (mbedtls_sha1_context *) ctx ); return( ctx ); } static void sha1_clone_wrap( void *dst, const void *src ) { mbedtls_sha1_clone( (mbedtls_sha1_context *) dst, (const mbedtls_sha1_context *) src ); } static void sha1_ctx_free( void *ctx ) { mbedtls_sha1_free( (mbedtls_sha1_context *) ctx ); mbedtls_free( ctx ); } static int sha1_process_wrap( void *ctx, const unsigned char *data ) { return( mbedtls_internal_sha1_process( (mbedtls_sha1_context *) ctx, data ) ); } const mbedtls_md_info_t mbedtls_sha1_info = { MBEDTLS_MD_SHA1, "SHA1", 20, 64, sha1_starts_wrap, sha1_update_wrap, sha1_finish_wrap, mbedtls_sha1_ret, sha1_ctx_alloc, sha1_ctx_free, sha1_clone_wrap, sha1_process_wrap, }; #endif /* MBEDTLS_SHA1_C */ /* * Wrappers for generic message digests */ #if defined(MBEDTLS_SHA256_C) static int sha224_starts_wrap( void *ctx ) { return( mbedtls_sha256_starts_ret( (mbedtls_sha256_context *) ctx, 1 ) ); } static int sha224_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) { return( mbedtls_sha256_update_ret( (mbedtls_sha256_context *) ctx, input, ilen ) ); } static int sha224_finish_wrap( void *ctx, unsigned char *output ) { return( mbedtls_sha256_finish_ret( (mbedtls_sha256_context *) ctx, output ) ); } static int sha224_wrap( const unsigned char *input, size_t ilen, unsigned char *output ) { return( mbedtls_sha256_ret( input, ilen, output, 1 ) ); } static void *sha224_ctx_alloc( void ) { void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha256_context ) ); if( ctx != NULL ) mbedtls_sha256_init( (mbedtls_sha256_context *) ctx ); return( ctx ); } static void sha224_ctx_free( void *ctx ) { mbedtls_sha256_free( (mbedtls_sha256_context *) ctx ); mbedtls_free( ctx ); } static void sha224_clone_wrap( void *dst, const void *src ) { mbedtls_sha256_clone( (mbedtls_sha256_context *) dst, (const mbedtls_sha256_context *) src ); } static int sha224_process_wrap( void *ctx, const unsigned char *data ) { return( mbedtls_internal_sha256_process( (mbedtls_sha256_context *) ctx, data ) ); } const mbedtls_md_info_t mbedtls_sha224_info = { MBEDTLS_MD_SHA224, "SHA224", 28, 64, sha224_starts_wrap, sha224_update_wrap, sha224_finish_wrap, sha224_wrap, sha224_ctx_alloc, sha224_ctx_free, sha224_clone_wrap, sha224_process_wrap, }; static int sha256_starts_wrap( void *ctx ) { return( mbedtls_sha256_starts_ret( (mbedtls_sha256_context *) ctx, 0 ) ); } static int sha256_wrap( const unsigned char *input, size_t ilen, unsigned char *output ) { return( mbedtls_sha256_ret( input, ilen, output, 0 ) ); } const mbedtls_md_info_t mbedtls_sha256_info = { MBEDTLS_MD_SHA256, "SHA256", 32, 64, sha256_starts_wrap, sha224_update_wrap, sha224_finish_wrap, sha256_wrap, sha224_ctx_alloc, sha224_ctx_free, sha224_clone_wrap, sha224_process_wrap, }; #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) static int sha384_starts_wrap( void *ctx ) { return( mbedtls_sha512_starts_ret( (mbedtls_sha512_context *) ctx, 1 ) ); } static int sha384_update_wrap( void *ctx, const unsigned char *input, size_t ilen ) { return( mbedtls_sha512_update_ret( (mbedtls_sha512_context *) ctx, input, ilen ) ); } static int sha384_finish_wrap( void *ctx, unsigned char *output ) { return( mbedtls_sha512_finish_ret( (mbedtls_sha512_context *) ctx, output ) ); } static int sha384_wrap( const unsigned char *input, size_t ilen, unsigned char *output ) { return( mbedtls_sha512_ret( input, ilen, output, 1 ) ); } static void *sha384_ctx_alloc( void ) { void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_sha512_context ) ); if( ctx != NULL ) mbedtls_sha512_init( (mbedtls_sha512_context *) ctx ); return( ctx ); } static void sha384_ctx_free( void *ctx ) { mbedtls_sha512_free( (mbedtls_sha512_context *) ctx ); mbedtls_free( ctx ); } static void sha384_clone_wrap( void *dst, const void *src ) { mbedtls_sha512_clone( (mbedtls_sha512_context *) dst, (const mbedtls_sha512_context *) src ); } static int sha384_process_wrap( void *ctx, const unsigned char *data ) { return( mbedtls_internal_sha512_process( (mbedtls_sha512_context *) ctx, data ) ); } const mbedtls_md_info_t mbedtls_sha384_info = { MBEDTLS_MD_SHA384, "SHA384", 48, 128, sha384_starts_wrap, sha384_update_wrap, sha384_finish_wrap, sha384_wrap, sha384_ctx_alloc, sha384_ctx_free, sha384_clone_wrap, sha384_process_wrap, }; static int sha512_starts_wrap( void *ctx ) { return( mbedtls_sha512_starts_ret( (mbedtls_sha512_context *) ctx, 0 ) ); } static int sha512_wrap( const unsigned char *input, size_t ilen, unsigned char *output ) { return( mbedtls_sha512_ret( input, ilen, output, 0 ) ); } const mbedtls_md_info_t mbedtls_sha512_info = { MBEDTLS_MD_SHA512, "SHA512", 64, 128, sha512_starts_wrap, sha384_update_wrap, sha384_finish_wrap, sha512_wrap, sha384_ctx_alloc, sha384_ctx_free, sha384_clone_wrap, sha384_process_wrap, }; #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_MD_C */
675334.c
/* * mergechan.c - Merge channels from multiple RLE images * * Author: John W. Peterson * Computer Science Dept. * University of Utah * Date: Mon Nov 9 1987 * Copyright (c) 1987, University of Utah * * Warning: this code does not intelligently deal with color maps! * */ #include <stdlib.h> #include <stdio.h> #include "rle.h" #include "rle_raw.h" #define MIN(i,j) ( (i) < (j) ? (i) : (j) ) #define RLE_END 32768 /* This should be in rle.h */ int main( argc, argv ) int argc; char ** argv; { int nfiles; rle_hdr * in_hdr; rle_hdr out_hdr; int alpha_flag = 0, oflag = 0; rle_op *** in_rows; /* A Carl Sagan pointer. */ int ** in_counts; /* nraw */ rle_op ** out_rows; int * out_count; int * skips; CONST_DECL char **filenames, *out_fname = NULL, *cmd_nm; FILE *outfile = stdout; int minskip = 0, y; register int i; int rle_cnt, rle_err, stdin_used = -1; if (! scanargs( argc, argv, "% a%- o%-outfile!s files%*s", &alpha_flag, &oflag, &out_fname, &nfiles, &filenames )) exit( -1 ); cmd_nm = cmd_name( argv ); if (alpha_flag) alpha_flag = 1; /* So indexing's right. */ in_hdr = (rle_hdr *) malloc( sizeof( rle_hdr ) * nfiles ); RLE_CHECK_ALLOC( cmd_nm, in_hdr, "file headers" ); in_rows = (rle_op ***) malloc( sizeof( rle_op ** ) * nfiles ); RLE_CHECK_ALLOC( cmd_nm, in_rows, "input data" ); in_counts = (int **) malloc( sizeof( int * ) * nfiles ); RLE_CHECK_ALLOC( cmd_nm, in_counts, 0 ); skips = (int *) malloc( sizeof( int ) * nfiles ); RLE_CHECK_ALLOC( cmd_nm, skips, 0 ); out_rows = (rle_op **) malloc( sizeof( rle_op * ) * nfiles ); RLE_CHECK_ALLOC( cmd_nm, out_rows, "output data" ); out_count = (int *) malloc( sizeof( int ) * nfiles ); RLE_CHECK_ALLOC( cmd_nm, out_count, 0 ); /* Open all the files, and check consistancy */ for (i = 0; i < nfiles; i++) { in_hdr[i] = *rle_hdr_init( NULL ); rle_names( &in_hdr[i], cmd_name( argv ), filenames[i], 0 ); in_hdr[i].rle_file = rle_open_f( in_hdr[i].cmd, filenames[i], "r"); if ( in_hdr[i].rle_file == stdin ) if ( stdin_used < 0 ) { filenames[i] = "Standard Input"; stdin_used = i; } else { fprintf( stderr, "%s: Images %d and %d are both from the standard input\n", argv[0], stdin_used, i ); exit( -1 ); } } out_hdr = *rle_hdr_init( NULL ); rle_names( &out_hdr, in_hdr[0].cmd, out_fname, 0 ); /* Note: the only way out of this loop is via one of the two exit * calls below. */ for ( rle_cnt = 0; ; rle_cnt++ ) { for (i = 0; i < nfiles; i++) { /* Check for an error. EOF or EMPTY is ok if at least one image * has been read. Otherwise, print an error message. EOF * or EMPTY after first image means end of input. */ if ( (rle_err = rle_get_setup( &in_hdr[i])) != RLE_SUCCESS ) if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) ) { rle_get_error( rle_err, cmd_name( argv ), filenames[i] ); exit( 1 ); } else if ( rle_err == RLE_EOF || rle_err == RLE_EMPTY ) exit( 0 ); /* Check that the channel's really there */ if (((in_hdr[i].ncolors-1) < (i-alpha_flag)) || (! RLE_BIT( in_hdr[i], i-alpha_flag ))) { fprintf(stderr, "mergechan: channel %d not in file %s\n", i-alpha_flag, filenames[i] ); exit( -2 ); } /* Check to make sure all images have the same size */ if (i > 0) { if (! ((in_hdr[0].xmin == in_hdr[i].xmin) && (in_hdr[0].xmax == in_hdr[i].xmax) && (in_hdr[0].ymin == in_hdr[i].ymin) && (in_hdr[0].ymax == in_hdr[i].ymax)) ) { fprintf(stderr, "mergechan: image %s is not the same size as image %s\n", filenames[i], filenames[0] ); exit( -2 ); } } if ( rle_raw_alloc( &in_hdr[i], &in_rows[i], &in_counts[i] ) < 0 ) RLE_CHECK_ALLOC( cmd_nm, 0, "input image data" ); } /* Setup output stuff */ (void)rle_hdr_cp( &in_hdr[0], &out_hdr ); rle_addhist( argv, &in_hdr[0], &out_hdr ); if ( rle_cnt == 0 ) outfile = rle_open_f("mergechan", out_fname, "w"); out_hdr.rle_file = outfile; out_hdr.ncolors = nfiles - alpha_flag; out_hdr.alpha = alpha_flag; /* Set background color appropriately. */ if ( out_hdr.ncolors > 0 ) { out_hdr.background = 2; out_hdr.bg_color = (int *)malloc(out_hdr.ncolors * sizeof(int)); RLE_CHECK_ALLOC( cmd_nm, out_hdr.bg_color, "output background color" ); for ( i = 0; i < out_hdr.ncolors; i++ ) if ( in_hdr[i + alpha_flag].background > 0 ) out_hdr.bg_color[i] = in_hdr[i + alpha_flag].bg_color[i]; else out_hdr.bg_color[i] = 0; } else out_hdr.background = 0; /* Enable all output channels. */ for (i = -alpha_flag; i < out_hdr.ncolors; i++) RLE_SET_BIT( out_hdr, i ); rle_put_setup( &out_hdr ); if (alpha_flag) /* So indexing's right (alpha == -1) */ { in_hdr++; in_rows++; in_counts++; out_rows++; out_count++; skips++; } /* Initialize counters */ for (i = -alpha_flag; i < out_hdr.ncolors; i++) { skips[i] = 0; out_rows[i] = in_rows[i][i]; } y = out_hdr.ymin - 1; /* -1 'cuz we haven't read data yet */ /* * Do the actual work. Since rle_getraw may "skip" several lines * ahead, we need to keep track of the Y position of each channel * independently with skips[]. The output moves ahead by the * minimum of these skip values (minskip). */ while (1) /* Stops at EOF on all files */ { for (i = -alpha_flag; i < out_hdr.ncolors; i++) { if (! skips[i]) { skips[i] = rle_getraw( &(in_hdr[i]), in_rows[i], in_counts[i] ); if (skips[i] != RLE_END) skips[i] -= y; /* Store delta to next data */ } /* Find smallest skip distance until a channel has data again */ if (i == -alpha_flag) minskip = skips[i]; else minskip = MIN( skips[i], minskip ); } if (minskip == RLE_END) break; /* Hit the end of all input files */ if (minskip > 1) rle_skiprow( &out_hdr, minskip-1 ); y += minskip; for (i = -alpha_flag; i < out_hdr.ncolors; i++) { if (skips[i] != RLE_END) skips[i] -= minskip; if (skips[i] == 0) /* Has data to go out */ { out_count[i] = in_counts[i][i]; } else { out_count[i] = 0; } } rle_putraw( out_rows, out_count, &out_hdr ); for (i = -alpha_flag; i < out_hdr.ncolors; i++) { if (skips[i] == 0) /* Data is written, so free the raws */ { rle_freeraw( &(in_hdr[i]), in_rows[i], in_counts[i] ); } } } rle_puteof( &out_hdr ); /* Free storage. */ if (alpha_flag) { in_hdr--; in_rows--; in_counts--; out_rows--; out_count--; skips--; } for ( i = 0; i < nfiles; i++ ) rle_raw_free( &in_hdr[i], in_rows[i], in_counts[i] ); } /* NOTREACHED */ }
966496.c
/* | PC-LISP (C) 1984-1989 Peter J.Ashwood-Smith */ #include <stdio.h> #include <math.h> #include "lisp.h" /************************************************************************* ** bucons : this function is the built in `cons' function, and will if ** ** given two parameters the second of which must be a list, return the ** ** result of constructing a new list, the head of which is the first ** ** parameter and the tail of which is the second parameter. For example** ** (cons a (b c d)) is just (a b c d) ** *************************************************************************/ struct conscell *bucons(form) struct conscell *form; { struct conscell *temp1,*temp2; xpush(form); if (form != NULL) { temp1 = form->carp; form = form->cdrp; if ((form != NULL)&&(form->cdrp == NULL)) { temp2 = new(CONSCELL); temp2->carp=temp1; temp2->cdrp=form->carp; fret(temp2,1); }; }; ierror("cons"); /* doesn't return */ return NULL; /* keep compiler happy */ }
652472.c
/* * linux/arch/arm/kernel/early_printk.c * * Copyright (C) 2009 Sascha Hauer <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/kernel.h> #include <linux/console.h> #include <linux/init.h> extern void printch(int); static void early_write(const char *s, unsigned n) { while (n-- > 0) { if (*s == '\n') printch('\r'); printch(*s); s++; } } static void early_console_write(struct console *con, const char *s, unsigned n) { early_write(s, n); } static struct console early_console = { .name = "earlycon", .write = early_console_write, .flags = CON_PRINTBUFFER | CON_BOOT, .index = -1, }; asmlinkage void early_printk(const char *fmt, ...) { char buf[512]; int n; va_list ap; va_start(ap, fmt); n = vscnprintf(buf, sizeof(buf), fmt, ap); early_write(buf, n); va_end(ap); } static int __init setup_early_printk(char *buf) { register_console(&early_console); return 0; } early_param("earlyprintk", setup_early_printk);
412620.c
/*- * Copyright (c) 1989, 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software developed by the Computer Systems * Engineering group at Lawrence Berkeley Laboratory under DARPA contract * BG 91-66 and contributed to Berkeley. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <sys/cdefs.h> __FBSDID("$FreeBSD: soc2013/dpl/head/lib/libkvm/kvm_amd64.c 217787 2011-01-23 11:08:28Z uqs $"); #if defined(LIBC_SCCS) && !defined(lint) #if 0 static char sccsid[] = "@(#)kvm_hp300.c 8.1 (Berkeley) 6/4/93"; #endif #endif /* LIBC_SCCS and not lint */ /* * AMD64 machine dependent routines for kvm. Hopefully, the forthcoming * vm code will one day obsolete this module. */ #include <sys/param.h> #include <sys/user.h> #include <sys/proc.h> #include <sys/stat.h> #include <sys/mman.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <nlist.h> #include <kvm.h> #include <vm/vm.h> #include <vm/vm_param.h> #include <machine/elf.h> #include <limits.h> #include "kvm_private.h" #ifndef btop #define btop(x) (amd64_btop(x)) #define ptob(x) (amd64_ptob(x)) #endif /* minidump must be the first item! */ struct vmstate { int minidump; /* 1 = minidump mode */ void *mmapbase; size_t mmapsize; pml4_entry_t *PML4; }; /* * Map the ELF headers into the process' address space. We do this in two * steps: first the ELF header itself and using that information the whole * set of headers. (Taken from kvm_ia64.c) */ static int _kvm_maphdrs(kvm_t *kd, size_t sz) { struct vmstate *vm = kd->vmst; /* munmap() previous mmap(). */ if (vm->mmapbase != NULL) { munmap(vm->mmapbase, vm->mmapsize); vm->mmapbase = NULL; } vm->mmapsize = sz; vm->mmapbase = mmap(NULL, sz, PROT_READ, MAP_PRIVATE, kd->pmfd, 0); if (vm->mmapbase == MAP_FAILED) { _kvm_err(kd, kd->program, "cannot mmap corefile"); return (-1); } return (0); } /* * Translate a physical memory address to a file-offset in the crash-dump. * (Taken from kvm_ia64.c) */ static size_t _kvm_pa2off(kvm_t *kd, uint64_t pa, off_t *ofs) { Elf_Ehdr *e = kd->vmst->mmapbase; Elf_Phdr *p; int n; if (kd->rawdump) { *ofs = pa; return (PAGE_SIZE - ((size_t)pa & PAGE_MASK)); } p = (Elf_Phdr*)((char*)e + e->e_phoff); n = e->e_phnum; while (n && (pa < p->p_paddr || pa >= p->p_paddr + p->p_memsz)) p++, n--; if (n == 0) return (0); *ofs = (pa - p->p_paddr) + p->p_offset; return (PAGE_SIZE - ((size_t)pa & PAGE_MASK)); } void _kvm_freevtop(kvm_t *kd) { struct vmstate *vm = kd->vmst; if (kd->vmst->minidump) return (_kvm_minidump_freevtop(kd)); if (vm->mmapbase != NULL) munmap(vm->mmapbase, vm->mmapsize); if (vm->PML4) free(vm->PML4); free(vm); kd->vmst = NULL; } int _kvm_initvtop(kvm_t *kd) { struct nlist nl[2]; u_long pa; u_long kernbase; pml4_entry_t *PML4; Elf_Ehdr *ehdr; size_t hdrsz; char minihdr[8]; if (!kd->rawdump && pread(kd->pmfd, &minihdr, 8, 0) == 8) if (memcmp(&minihdr, "minidump", 8) == 0) return (_kvm_minidump_initvtop(kd)); kd->vmst = (struct vmstate *)_kvm_malloc(kd, sizeof(*kd->vmst)); if (kd->vmst == 0) { _kvm_err(kd, kd->program, "cannot allocate vm"); return (-1); } kd->vmst->PML4 = 0; if (kd->rawdump == 0) { if (_kvm_maphdrs(kd, sizeof(Elf_Ehdr)) == -1) return (-1); ehdr = kd->vmst->mmapbase; hdrsz = ehdr->e_phoff + ehdr->e_phentsize * ehdr->e_phnum; if (_kvm_maphdrs(kd, hdrsz) == -1) return (-1); } nl[0].n_name = "kernbase"; nl[1].n_name = 0; if (kvm_nlist(kd, nl) != 0) { _kvm_err(kd, kd->program, "bad namelist - no kernbase"); return (-1); } kernbase = nl[0].n_value; nl[0].n_name = "KPML4phys"; nl[1].n_name = 0; if (kvm_nlist(kd, nl) != 0) { _kvm_err(kd, kd->program, "bad namelist - no KPML4phys"); return (-1); } if (kvm_read(kd, (nl[0].n_value - kernbase), &pa, sizeof(pa)) != sizeof(pa)) { _kvm_err(kd, kd->program, "cannot read KPML4phys"); return (-1); } PML4 = _kvm_malloc(kd, PAGE_SIZE); if (kvm_read(kd, pa, PML4, PAGE_SIZE) != PAGE_SIZE) { _kvm_err(kd, kd->program, "cannot read KPML4phys"); return (-1); } kd->vmst->PML4 = PML4; return (0); } static int _kvm_vatop(kvm_t *kd, u_long va, off_t *pa) { struct vmstate *vm; u_long offset; u_long pdpe_pa; u_long pde_pa; u_long pte_pa; pml4_entry_t pml4e; pdp_entry_t pdpe; pd_entry_t pde; pt_entry_t pte; u_long pml4eindex; u_long pdpeindex; u_long pdeindex; u_long pteindex; u_long a; off_t ofs; size_t s; vm = kd->vmst; offset = va & (PAGE_SIZE - 1); /* * If we are initializing (kernel page table descriptor pointer * not yet set) then return pa == va to avoid infinite recursion. */ if (vm->PML4 == 0) { s = _kvm_pa2off(kd, va, pa); if (s == 0) { _kvm_err(kd, kd->program, "_kvm_vatop: bootstrap data not in dump"); goto invalid; } else return (PAGE_SIZE - offset); } pml4eindex = (va >> PML4SHIFT) & (NPML4EPG - 1); pml4e = vm->PML4[pml4eindex]; if (((u_long)pml4e & PG_V) == 0) { _kvm_err(kd, kd->program, "_kvm_vatop: pml4e not valid"); goto invalid; } pdpeindex = (va >> PDPSHIFT) & (NPDPEPG-1); pdpe_pa = ((u_long)pml4e & PG_FRAME) + (pdpeindex * sizeof(pdp_entry_t)); s = _kvm_pa2off(kd, pdpe_pa, &ofs); if (s < sizeof pdpe) { _kvm_err(kd, kd->program, "_kvm_vatop: pdpe_pa not found"); goto invalid; } if (lseek(kd->pmfd, ofs, 0) == -1) { _kvm_syserr(kd, kd->program, "_kvm_vatop: lseek pdpe_pa"); goto invalid; } if (read(kd->pmfd, &pdpe, sizeof pdpe) != sizeof pdpe) { _kvm_syserr(kd, kd->program, "_kvm_vatop: read pdpe"); goto invalid; } if (((u_long)pdpe & PG_V) == 0) { _kvm_err(kd, kd->program, "_kvm_vatop: pdpe not valid"); goto invalid; } pdeindex = (va >> PDRSHIFT) & (NPDEPG-1); pde_pa = ((u_long)pdpe & PG_FRAME) + (pdeindex * sizeof(pd_entry_t)); s = _kvm_pa2off(kd, pde_pa, &ofs); if (s < sizeof pde) { _kvm_syserr(kd, kd->program, "_kvm_vatop: pde_pa not found"); goto invalid; } if (lseek(kd->pmfd, ofs, 0) == -1) { _kvm_err(kd, kd->program, "_kvm_vatop: lseek pde_pa"); goto invalid; } if (read(kd->pmfd, &pde, sizeof pde) != sizeof pde) { _kvm_syserr(kd, kd->program, "_kvm_vatop: read pde"); goto invalid; } if (((u_long)pde & PG_V) == 0) { _kvm_err(kd, kd->program, "_kvm_vatop: pde not valid"); goto invalid; } if ((u_long)pde & PG_PS) { /* * No final-level page table; ptd describes one 2MB page. */ #define PAGE2M_MASK (NBPDR - 1) #define PG_FRAME2M (~PAGE2M_MASK) a = ((u_long)pde & PG_FRAME2M) + (va & PAGE2M_MASK); s = _kvm_pa2off(kd, a, pa); if (s == 0) { _kvm_err(kd, kd->program, "_kvm_vatop: 2MB page address not in dump"); goto invalid; } else return (NBPDR - (va & PAGE2M_MASK)); } pteindex = (va >> PAGE_SHIFT) & (NPTEPG-1); pte_pa = ((u_long)pde & PG_FRAME) + (pteindex * sizeof(pt_entry_t)); s = _kvm_pa2off(kd, pte_pa, &ofs); if (s < sizeof pte) { _kvm_err(kd, kd->program, "_kvm_vatop: pte_pa not found"); goto invalid; } if (lseek(kd->pmfd, ofs, 0) == -1) { _kvm_syserr(kd, kd->program, "_kvm_vatop: lseek"); goto invalid; } if (read(kd->pmfd, &pte, sizeof pte) != sizeof pte) { _kvm_syserr(kd, kd->program, "_kvm_vatop: read"); goto invalid; } if (((u_long)pte & PG_V) == 0) { _kvm_err(kd, kd->program, "_kvm_vatop: pte not valid"); goto invalid; } a = ((u_long)pte & PG_FRAME) + offset; s = _kvm_pa2off(kd, a, pa); if (s == 0) { _kvm_err(kd, kd->program, "_kvm_vatop: address not in dump"); goto invalid; } else return (PAGE_SIZE - offset); invalid: _kvm_err(kd, 0, "invalid address (0x%lx)", va); return (0); } int _kvm_kvatop(kvm_t *kd, u_long va, off_t *pa) { if (kd->vmst->minidump) return (_kvm_minidump_kvatop(kd, va, pa)); if (ISALIVE(kd)) { _kvm_err(kd, 0, "kvm_kvatop called in live kernel!"); return (0); } return (_kvm_vatop(kd, va, pa)); }
987258.c
/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2017, Daniel Stenberg, <[email protected]>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ #include "curl_setup.h" #include <curl/curl.h> #ifndef CURL_DISABLE_HTTP #if defined(HAVE_LIBGEN_H) && defined(HAVE_BASENAME) #include <libgen.h> #endif #include "urldata.h" /* for struct Curl_easy */ #include "formdata.h" #include "mime.h" #include "non-ascii.h" #include "vtls/vtls.h" #include "strcase.h" #include "sendf.h" #include "strdup.h" #include "rand.h" /* The last 3 #include files should be in this order */ #include "curl_printf.h" #include "curl_memory.h" #include "memdebug.h" /* What kind of Content-Type to use on un-specified files with unrecognized extensions. */ #define HTTPPOST_CONTENTTYPE_DEFAULT "application/octet-stream" #define HTTPPOST_PTRNAME CURL_HTTPPOST_PTRNAME #define HTTPPOST_FILENAME CURL_HTTPPOST_FILENAME #define HTTPPOST_PTRCONTENTS CURL_HTTPPOST_PTRCONTENTS #define HTTPPOST_READFILE CURL_HTTPPOST_READFILE #define HTTPPOST_PTRBUFFER CURL_HTTPPOST_PTRBUFFER #define HTTPPOST_CALLBACK CURL_HTTPPOST_CALLBACK #define HTTPPOST_BUFFER CURL_HTTPPOST_BUFFER /*************************************************************************** * * AddHttpPost() * * Adds a HttpPost structure to the list, if parent_post is given becomes * a subpost of parent_post instead of a direct list element. * * Returns newly allocated HttpPost on success and NULL if malloc failed. * ***************************************************************************/ static struct curl_httppost * AddHttpPost(char *name, size_t namelength, char *value, curl_off_t contentslength, char *buffer, size_t bufferlength, char *contenttype, long flags, struct curl_slist *contentHeader, char *showfilename, char *userp, struct curl_httppost *parent_post, struct curl_httppost **httppost, struct curl_httppost **last_post) { struct curl_httppost *post; post = calloc(1, sizeof(struct curl_httppost)); if(post) { post->name = name; post->namelength = (long)(name?(namelength?namelength:strlen(name)):0); post->contents = value; post->contentlen = contentslength; post->buffer = buffer; post->bufferlength = (long)bufferlength; post->contenttype = contenttype; post->contentheader = contentHeader; post->showfilename = showfilename; post->userp = userp; post->flags = flags | CURL_HTTPPOST_LARGE; } else return NULL; if(parent_post) { /* now, point our 'more' to the original 'more' */ post->more = parent_post->more; /* then move the original 'more' to point to ourselves */ parent_post->more = post; } else { /* make the previous point to this */ if(*last_post) (*last_post)->next = post; else (*httppost) = post; (*last_post) = post; } return post; } /*************************************************************************** * * AddFormInfo() * * Adds a FormInfo structure to the list presented by parent_form_info. * * Returns newly allocated FormInfo on success and NULL if malloc failed/ * parent_form_info is NULL. * ***************************************************************************/ static FormInfo * AddFormInfo(char *value, char *contenttype, FormInfo *parent_form_info) { FormInfo *form_info; form_info = calloc(1, sizeof(struct FormInfo)); if(form_info) { if(value) form_info->value = value; if(contenttype) form_info->contenttype = contenttype; form_info->flags = HTTPPOST_FILENAME; } else return NULL; if(parent_form_info) { /* now, point our 'more' to the original 'more' */ form_info->more = parent_form_info->more; /* then move the original 'more' to point to ourselves */ parent_form_info->more = form_info; } return form_info; } /*************************************************************************** * * ContentTypeForFilename() * * Provides content type for filename if one of the known types (else * (either the prevtype or the default is returned). * * Returns some valid contenttype for filename. * ***************************************************************************/ static const char *ContentTypeForFilename(const char *filename, const char *prevtype) { const char *contenttype = NULL; unsigned int i; /* * No type was specified, we scan through a few well-known * extensions and pick the first we match! */ struct ContentType { const char *extension; const char *type; }; static const struct ContentType ctts[]={ {".gif", "image/gif"}, {".jpg", "image/jpeg"}, {".jpeg", "image/jpeg"}, {".txt", "text/plain"}, {".html", "text/html"}, {".xml", "application/xml"} }; if(prevtype) /* default to the previously set/used! */ contenttype = prevtype; else contenttype = HTTPPOST_CONTENTTYPE_DEFAULT; if(filename) { /* in case a NULL was passed in */ for(i = 0; i<sizeof(ctts)/sizeof(ctts[0]); i++) { if(strlen(filename) >= strlen(ctts[i].extension)) { if(strcasecompare(filename + strlen(filename) - strlen(ctts[i].extension), ctts[i].extension)) { contenttype = ctts[i].type; break; } } } } /* we have a contenttype by now */ return contenttype; } /*************************************************************************** * * FormAdd() * * Stores a formpost parameter and builds the appropriate linked list. * * Has two principal functionalities: using files and byte arrays as * post parts. Byte arrays are either copied or just the pointer is stored * (as the user requests) while for files only the filename and not the * content is stored. * * While you may have only one byte array for each name, multiple filenames * are allowed (and because of this feature CURLFORM_END is needed after * using CURLFORM_FILE). * * Examples: * * Simple name/value pair with copied contents: * curl_formadd (&post, &last, CURLFORM_COPYNAME, "name", * CURLFORM_COPYCONTENTS, "value", CURLFORM_END); * * name/value pair where only the content pointer is remembered: * curl_formadd (&post, &last, CURLFORM_COPYNAME, "name", * CURLFORM_PTRCONTENTS, ptr, CURLFORM_CONTENTSLENGTH, 10, CURLFORM_END); * (if CURLFORM_CONTENTSLENGTH is missing strlen () is used) * * storing a filename (CONTENTTYPE is optional!): * curl_formadd (&post, &last, CURLFORM_COPYNAME, "name", * CURLFORM_FILE, "filename1", CURLFORM_CONTENTTYPE, "plain/text", * CURLFORM_END); * * storing multiple filenames: * curl_formadd (&post, &last, CURLFORM_COPYNAME, "name", * CURLFORM_FILE, "filename1", CURLFORM_FILE, "filename2", CURLFORM_END); * * Returns: * CURL_FORMADD_OK on success * CURL_FORMADD_MEMORY if the FormInfo allocation fails * CURL_FORMADD_OPTION_TWICE if one option is given twice for one Form * CURL_FORMADD_NULL if a null pointer was given for a char * CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed * CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used * CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error) * CURL_FORMADD_MEMORY if a HttpPost struct cannot be allocated * CURL_FORMADD_MEMORY if some allocation for string copying failed. * CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array * ***************************************************************************/ static CURLFORMcode FormAdd(struct curl_httppost **httppost, struct curl_httppost **last_post, va_list params) { FormInfo *first_form, *current_form, *form = NULL; CURLFORMcode return_value = CURL_FORMADD_OK; const char *prevtype = NULL; struct curl_httppost *post = NULL; CURLformoption option; struct curl_forms *forms = NULL; char *array_value = NULL; /* value read from an array */ /* This is a state variable, that if TRUE means that we're parsing an array that we got passed to us. If FALSE we're parsing the input va_list arguments. */ bool array_state = FALSE; /* * We need to allocate the first struct to fill in. */ first_form = calloc(1, sizeof(struct FormInfo)); if(!first_form) return CURL_FORMADD_MEMORY; current_form = first_form; /* * Loop through all the options set. Break if we have an error to report. */ while(return_value == CURL_FORMADD_OK) { /* first see if we have more parts of the array param */ if(array_state && forms) { /* get the upcoming option from the given array */ option = forms->option; array_value = (char *)forms->value; forms++; /* advance this to next entry */ if(CURLFORM_END == option) { /* end of array state */ array_state = FALSE; continue; } } else { /* This is not array-state, get next option */ option = va_arg(params, CURLformoption); if(CURLFORM_END == option) break; } switch(option) { case CURLFORM_ARRAY: if(array_state) /* we don't support an array from within an array */ return_value = CURL_FORMADD_ILLEGAL_ARRAY; else { forms = va_arg(params, struct curl_forms *); if(forms) array_state = TRUE; else return_value = CURL_FORMADD_NULL; } break; /* * Set the Name property. */ case CURLFORM_PTRNAME: #ifdef CURL_DOES_CONVERSIONS /* Treat CURLFORM_PTR like CURLFORM_COPYNAME so that libcurl will copy * the data in all cases so that we'll have safe memory for the eventual * conversion. */ #else current_form->flags |= HTTPPOST_PTRNAME; /* fall through */ #endif /* FALLTHROUGH */ case CURLFORM_COPYNAME: if(current_form->name) return_value = CURL_FORMADD_OPTION_TWICE; else { char *name = array_state? array_value:va_arg(params, char *); if(name) current_form->name = name; /* store for the moment */ else return_value = CURL_FORMADD_NULL; } break; case CURLFORM_NAMELENGTH: if(current_form->namelength) return_value = CURL_FORMADD_OPTION_TWICE; else current_form->namelength = array_state?(size_t)array_value:(size_t)va_arg(params, long); break; /* * Set the contents property. */ case CURLFORM_PTRCONTENTS: current_form->flags |= HTTPPOST_PTRCONTENTS; /* fall through */ case CURLFORM_COPYCONTENTS: if(current_form->value) return_value = CURL_FORMADD_OPTION_TWICE; else { char *value = array_state?array_value:va_arg(params, char *); if(value) current_form->value = value; /* store for the moment */ else return_value = CURL_FORMADD_NULL; } break; case CURLFORM_CONTENTSLENGTH: current_form->contentslength = array_state?(size_t)array_value:(size_t)va_arg(params, long); break; case CURLFORM_CONTENTLEN: current_form->flags |= CURL_HTTPPOST_LARGE; current_form->contentslength = array_state?(curl_off_t)(size_t)array_value:va_arg(params, curl_off_t); break; /* Get contents from a given file name */ case CURLFORM_FILECONTENT: if(current_form->flags & (HTTPPOST_PTRCONTENTS|HTTPPOST_READFILE)) return_value = CURL_FORMADD_OPTION_TWICE; else { const char *filename = array_state? array_value:va_arg(params, char *); if(filename) { current_form->value = strdup(filename); if(!current_form->value) return_value = CURL_FORMADD_MEMORY; else { current_form->flags |= HTTPPOST_READFILE; current_form->value_alloc = TRUE; } } else return_value = CURL_FORMADD_NULL; } break; /* We upload a file */ case CURLFORM_FILE: { const char *filename = array_state?array_value: va_arg(params, char *); if(current_form->value) { if(current_form->flags & HTTPPOST_FILENAME) { if(filename) { char *fname = strdup(filename); if(!fname) return_value = CURL_FORMADD_MEMORY; else { form = AddFormInfo(fname, NULL, current_form); if(!form) { free(fname); return_value = CURL_FORMADD_MEMORY; } else { form->value_alloc = TRUE; current_form = form; form = NULL; } } } else return_value = CURL_FORMADD_NULL; } else return_value = CURL_FORMADD_OPTION_TWICE; } else { if(filename) { current_form->value = strdup(filename); if(!current_form->value) return_value = CURL_FORMADD_MEMORY; else { current_form->flags |= HTTPPOST_FILENAME; current_form->value_alloc = TRUE; } } else return_value = CURL_FORMADD_NULL; } break; } case CURLFORM_BUFFERPTR: current_form->flags |= HTTPPOST_PTRBUFFER|HTTPPOST_BUFFER; if(current_form->buffer) return_value = CURL_FORMADD_OPTION_TWICE; else { char *buffer = array_state?array_value:va_arg(params, char *); if(buffer) { current_form->buffer = buffer; /* store for the moment */ current_form->value = buffer; /* make it non-NULL to be accepted as fine */ } else return_value = CURL_FORMADD_NULL; } break; case CURLFORM_BUFFERLENGTH: if(current_form->bufferlength) return_value = CURL_FORMADD_OPTION_TWICE; else current_form->bufferlength = array_state?(size_t)array_value:(size_t)va_arg(params, long); break; case CURLFORM_STREAM: current_form->flags |= HTTPPOST_CALLBACK; if(current_form->userp) return_value = CURL_FORMADD_OPTION_TWICE; else { char *userp = array_state?array_value:va_arg(params, char *); if(userp) { current_form->userp = userp; current_form->value = userp; /* this isn't strictly true but we derive a value from this later on and we need this non-NULL to be accepted as a fine form part */ } else return_value = CURL_FORMADD_NULL; } break; case CURLFORM_CONTENTTYPE: { const char *contenttype = array_state?array_value:va_arg(params, char *); if(current_form->contenttype) { if(current_form->flags & HTTPPOST_FILENAME) { if(contenttype) { char *type = strdup(contenttype); if(!type) return_value = CURL_FORMADD_MEMORY; else { form = AddFormInfo(NULL, type, current_form); if(!form) { free(type); return_value = CURL_FORMADD_MEMORY; } else { form->contenttype_alloc = TRUE; current_form = form; form = NULL; } } } else return_value = CURL_FORMADD_NULL; } else return_value = CURL_FORMADD_OPTION_TWICE; } else { if(contenttype) { current_form->contenttype = strdup(contenttype); if(!current_form->contenttype) return_value = CURL_FORMADD_MEMORY; else current_form->contenttype_alloc = TRUE; } else return_value = CURL_FORMADD_NULL; } break; } case CURLFORM_CONTENTHEADER: { /* this "cast increases required alignment of target type" but we consider it OK anyway */ struct curl_slist *list = array_state? (struct curl_slist *)(void *)array_value: va_arg(params, struct curl_slist *); if(current_form->contentheader) return_value = CURL_FORMADD_OPTION_TWICE; else current_form->contentheader = list; break; } case CURLFORM_FILENAME: case CURLFORM_BUFFER: { const char *filename = array_state?array_value: va_arg(params, char *); if(current_form->showfilename) return_value = CURL_FORMADD_OPTION_TWICE; else { current_form->showfilename = strdup(filename); if(!current_form->showfilename) return_value = CURL_FORMADD_MEMORY; else current_form->showfilename_alloc = TRUE; } break; } default: return_value = CURL_FORMADD_UNKNOWN_OPTION; break; } } if(CURL_FORMADD_OK != return_value) { /* On error, free allocated fields for all nodes of the FormInfo linked list without deallocating nodes. List nodes are deallocated later on */ FormInfo *ptr; for(ptr = first_form; ptr != NULL; ptr = ptr->more) { if(ptr->name_alloc) { Curl_safefree(ptr->name); ptr->name_alloc = FALSE; } if(ptr->value_alloc) { Curl_safefree(ptr->value); ptr->value_alloc = FALSE; } if(ptr->contenttype_alloc) { Curl_safefree(ptr->contenttype); ptr->contenttype_alloc = FALSE; } if(ptr->showfilename_alloc) { Curl_safefree(ptr->showfilename); ptr->showfilename_alloc = FALSE; } } } if(CURL_FORMADD_OK == return_value) { /* go through the list, check for completeness and if everything is * alright add the HttpPost item otherwise set return_value accordingly */ post = NULL; for(form = first_form; form != NULL; form = form->more) { if(((!form->name || !form->value) && !post) || ( (form->contentslength) && (form->flags & HTTPPOST_FILENAME) ) || ( (form->flags & HTTPPOST_FILENAME) && (form->flags & HTTPPOST_PTRCONTENTS) ) || ( (!form->buffer) && (form->flags & HTTPPOST_BUFFER) && (form->flags & HTTPPOST_PTRBUFFER) ) || ( (form->flags & HTTPPOST_READFILE) && (form->flags & HTTPPOST_PTRCONTENTS) ) ) { return_value = CURL_FORMADD_INCOMPLETE; break; } if(((form->flags & HTTPPOST_FILENAME) || (form->flags & HTTPPOST_BUFFER)) && !form->contenttype) { char *f = form->flags & HTTPPOST_BUFFER? form->showfilename : form->value; /* our contenttype is missing */ form->contenttype = strdup(ContentTypeForFilename(f, prevtype)); if(!form->contenttype) { return_value = CURL_FORMADD_MEMORY; break; } form->contenttype_alloc = TRUE; } if(form->name && form->namelength) { /* Name should not contain nul bytes. */ size_t i; for(i = 0; i < form->namelength; i++) if(!form->name[i]) { return_value = CURL_FORMADD_NULL; break; } if(return_value != CURL_FORMADD_OK) break; } if(!(form->flags & HTTPPOST_PTRNAME) && (form == first_form) ) { /* Note that there's small risk that form->name is NULL here if the app passed in a bad combo, so we better check for that first. */ if(form->name) { /* copy name (without strdup; possibly not nul-terminated) */ form->name = Curl_memdup(form->name, form->namelength? form->namelength: strlen(form->name) + 1); } if(!form->name) { return_value = CURL_FORMADD_MEMORY; break; } form->name_alloc = TRUE; } if(!(form->flags & (HTTPPOST_FILENAME | HTTPPOST_READFILE | HTTPPOST_PTRCONTENTS | HTTPPOST_PTRBUFFER | HTTPPOST_CALLBACK)) && form->value) { /* copy value (without strdup; possibly contains null characters) */ size_t clen = (size_t) form->contentslength; if(!clen) clen = strlen(form->value) + 1; form->value = Curl_memdup(form->value, clen); if(!form->value) { return_value = CURL_FORMADD_MEMORY; break; } form->value_alloc = TRUE; } post = AddHttpPost(form->name, form->namelength, form->value, form->contentslength, form->buffer, form->bufferlength, form->contenttype, form->flags, form->contentheader, form->showfilename, form->userp, post, httppost, last_post); if(!post) { return_value = CURL_FORMADD_MEMORY; break; } if(form->contenttype) prevtype = form->contenttype; } if(CURL_FORMADD_OK != return_value) { /* On error, free allocated fields for nodes of the FormInfo linked list which are not already owned by the httppost linked list without deallocating nodes. List nodes are deallocated later on */ FormInfo *ptr; for(ptr = form; ptr != NULL; ptr = ptr->more) { if(ptr->name_alloc) { Curl_safefree(ptr->name); ptr->name_alloc = FALSE; } if(ptr->value_alloc) { Curl_safefree(ptr->value); ptr->value_alloc = FALSE; } if(ptr->contenttype_alloc) { Curl_safefree(ptr->contenttype); ptr->contenttype_alloc = FALSE; } if(ptr->showfilename_alloc) { Curl_safefree(ptr->showfilename); ptr->showfilename_alloc = FALSE; } } } } /* Always deallocate FormInfo linked list nodes without touching node fields given that these have either been deallocated or are owned now by the httppost linked list */ while(first_form) { FormInfo *ptr = first_form->more; free(first_form); first_form = ptr; } return return_value; } /* * curl_formadd() is a public API to add a section to the multipart formpost. * * @unittest: 1308 */ CURLFORMcode curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post, ...) { va_list arg; CURLFORMcode result; va_start(arg, last_post); result = FormAdd(httppost, last_post, arg); va_end(arg); return result; } /* * curl_formget() * Serialize a curl_httppost struct. * Returns 0 on success. * * @unittest: 1308 */ int curl_formget(struct curl_httppost *form, void *arg, curl_formget_callback append) { CURLcode result; curl_mimepart toppart; Curl_mime_initpart(&toppart, NULL); /* default form is empty */ result = Curl_getformdata(NULL, &toppart, form, NULL); if(!result) result = Curl_mime_prepare_headers(&toppart, "multipart/form-data", NULL, MIMESTRATEGY_FORM); while(!result) { char buffer[8192]; size_t nread = Curl_mime_read(buffer, 1, sizeof buffer, &toppart); if(!nread) break; switch(nread) { default: if(append(arg, buffer, nread) != nread) result = CURLE_READ_ERROR; break; case CURL_READFUNC_ABORT: case CURL_READFUNC_PAUSE: break; } } Curl_mime_cleanpart(&toppart); return (int) result; } /* * curl_formfree() is an external function to free up a whole form post * chain */ void curl_formfree(struct curl_httppost *form) { struct curl_httppost *next; if(!form) /* no form to free, just get out of this */ return; do { next = form->next; /* the following form line */ /* recurse to sub-contents */ curl_formfree(form->more); if(!(form->flags & HTTPPOST_PTRNAME)) free(form->name); /* free the name */ if(!(form->flags & (HTTPPOST_PTRCONTENTS|HTTPPOST_BUFFER|HTTPPOST_CALLBACK)) ) free(form->contents); /* free the contents */ free(form->contenttype); /* free the content type */ free(form->showfilename); /* free the faked file name */ free(form); /* free the struct */ form = next; } while(form); /* continue */ } /* Set mime part name, taking care of non nul-terminated name string. */ static CURLcode setname(curl_mimepart *part, const char *name, size_t len) { char *zname; CURLcode res; if(!name || !len) return curl_mime_name(part, name); zname = malloc(len + 1); if(!zname) return CURLE_OUT_OF_MEMORY; memcpy(zname, name, len); zname[len] = '\0'; res = curl_mime_name(part, zname); free(zname); return res; } /* * Curl_getformdata() converts a linked list of "meta data" into a mime * structure. The input list is in 'post', while the output is stored in * mime part at '*finalform'. * * This function will not do a failf() for the potential memory failures but * should for all other errors it spots. Just note that this function MAY get * a NULL pointer in the 'data' argument. */ CURLcode Curl_getformdata(struct Curl_easy *data, curl_mimepart *finalform, struct curl_httppost *post, curl_read_callback fread_func) { CURLcode result = CURLE_OK; curl_mime *form = NULL; curl_mime *multipart; curl_mimepart *part; struct curl_httppost *file; Curl_mime_cleanpart(finalform); /* default form is empty */ if(!post) return result; /* no input => no output! */ form = curl_mime_init(data); if(!form) result = CURLE_OUT_OF_MEMORY; if(!result) result = curl_mime_subparts(finalform, form); /* Process each top part. */ for(; !result && post; post = post->next) { /* If we have more than a file here, create a mime subpart and fill it. */ multipart = form; if(post->more) { part = curl_mime_addpart(form); if(!part) result = CURLE_OUT_OF_MEMORY; if(!result) result = setname(part, post->name, post->namelength); if(!result) { multipart = curl_mime_init(data); if(!multipart) result = CURLE_OUT_OF_MEMORY; } if(!result) result = curl_mime_subparts(part, multipart); } /* Generate all the part contents. */ for(file = post; !result && file; file = file->more) { /* Create the part. */ part = curl_mime_addpart(multipart); if(!part) result = CURLE_OUT_OF_MEMORY; /* Set the headers. */ if(!result) result = curl_mime_headers(part, file->contentheader, 0); /* Set the content type. */ if(!result &&file->contenttype) result = curl_mime_type(part, file->contenttype); /* Set field name. */ if(!result && !post->more) result = setname(part, post->name, post->namelength); /* Process contents. */ if(!result) { curl_off_t clen = post->contentslength; if(post->flags & CURL_HTTPPOST_LARGE) clen = post->contentlen; if(!clen) clen = -1; if(post->flags & (HTTPPOST_FILENAME | HTTPPOST_READFILE)) { if(!strcmp(file->contents, "-")) { /* There are a few cases where the code below won't work; in particular, freopen(stdin) by the caller is not guaranteed to result as expected. This feature has been kept for backward compatibility: use of "-" pseudo file name should be avoided. */ result = curl_mime_data_cb(part, (curl_off_t) -1, (curl_read_callback) fread, (curl_seek_callback) fseek, NULL, (void *) stdin); } else result = curl_mime_filedata(part, file->contents); if(!result && (post->flags & HTTPPOST_READFILE)) result = curl_mime_filename(part, NULL); } else if(post->flags & HTTPPOST_BUFFER) result = curl_mime_data(part, post->buffer, post->bufferlength? post->bufferlength: -1); else if(post->flags & HTTPPOST_CALLBACK) /* the contents should be read with the callback and the size is set with the contentslength */ result = curl_mime_data_cb(part, clen, fread_func, NULL, NULL, post->userp); else { result = curl_mime_data(part, post->contents, (ssize_t) clen); #ifdef CURL_DOES_CONVERSIONS /* Convert textual contents now. */ if(!result && data && part->datasize) result = Curl_convert_to_network(data, part->data, part->datasize); #endif } } /* Set fake file name. */ if(!result && post->showfilename) if(post->more || (post->flags & (HTTPPOST_FILENAME | HTTPPOST_BUFFER | HTTPPOST_CALLBACK))) result = curl_mime_filename(part, post->showfilename); } } if(result) Curl_mime_cleanpart(finalform); return result; } #else /* CURL_DISABLE_HTTP */ CURLFORMcode curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post, ...) { (void)httppost; (void)last_post; return CURL_FORMADD_DISABLED; } int curl_formget(struct curl_httppost *form, void *arg, curl_formget_callback append) { (void) form; (void) arg; (void) append; return CURL_FORMADD_DISABLED; } void curl_formfree(struct curl_httppost *form) { (void)form; /* does nothing HTTP is disabled */ } #endif /* !defined(CURL_DISABLE_HTTP) */
435166.c
/* * Copyright (c) 2018, Alliance for Open Media. All rights reserved * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent. */ #include "synonyms.h" #include <assert.h> #include <immintrin.h> #include "aom_dsp_rtcd.h" //////////////////////////////////////////////////////////////////////////////// // 8 bit //////////////////////////////////////////////////////////////////////////////// static INLINE int32_t xx_hsum_epi32_si32(__m128i v_d) { v_d = _mm_hadd_epi32(v_d, v_d); v_d = _mm_hadd_epi32(v_d, v_d); return _mm_cvtsi128_si32(v_d); } static INLINE void obmc_variance_w4(const uint8_t *pre, const int pre_stride, const int32_t *wsrc, const int32_t *mask, unsigned int *const sse, int *const sum, const int h) { const int pre_step = pre_stride - 4; int n = 0; __m128i v_sum_d = _mm_setzero_si128(); __m128i v_sse_d = _mm_setzero_si128(); assert(IS_POWER_OF_TWO(h)); do { const __m128i v_p_b = _mm_cvtsi32_si128(*(const uint32_t *)(pre + n)); const __m128i v_m_d = _mm_load_si128((const __m128i *)(mask + n)); const __m128i v_w_d = _mm_load_si128((const __m128i *)(wsrc + n)); const __m128i v_p_d = _mm_cvtepu8_epi32(v_p_b); // Values in both pre and mask fit in 15 bits, and are packed at 32 bit // boundaries. We use pmaddwd, as it has lower latency on Haswell // than pmulld but produces the same result with these inputs. const __m128i v_pm_d = _mm_madd_epi16(v_p_d, v_m_d); const __m128i v_diff_d = _mm_sub_epi32(v_w_d, v_pm_d); const __m128i v_rdiff_d = xx_roundn_epi32(v_diff_d, 12); const __m128i v_sqrdiff_d = _mm_mullo_epi32(v_rdiff_d, v_rdiff_d); v_sum_d = _mm_add_epi32(v_sum_d, v_rdiff_d); v_sse_d = _mm_add_epi32(v_sse_d, v_sqrdiff_d); n += 4; if (n % 4 == 0) pre += pre_step; } while (n < 4 * h); *sum = xx_hsum_epi32_si32(v_sum_d); *sse = xx_hsum_epi32_si32(v_sse_d); } static INLINE void obmc_variance_w8n(const uint8_t *pre, const int pre_stride, const int32_t *wsrc, const int32_t *mask, unsigned int *const sse, int *const sum, const int w, const int h) { int n = 0, width, height = h; __m128i v_sum_d = _mm_setzero_si128(); __m128i v_sse_d = _mm_setzero_si128(); const __m256i v_bias_d = _mm256_set1_epi32((1 << 12) >> 1); __m128i v_d; const uint8_t *pre_temp; assert(w >= 8); assert(IS_POWER_OF_TWO(w)); assert(IS_POWER_OF_TWO(h)); do { width = w; pre_temp = pre; do { const __m128i v_p_b = _mm_loadl_epi64((const __m128i *)pre_temp); const __m256i v_m_d = _mm256_loadu_si256((__m256i const *)(mask + n)); const __m256i v_w_d = _mm256_loadu_si256((__m256i const *)(wsrc + n)); const __m256i v_p0_d = _mm256_cvtepu8_epi32(v_p_b); // Values in both pre and mask fit in 15 bits, and are packed at 32 bit // boundaries. We use pmaddwd, as it has lower latency on Haswell // than pmulld but produces the same result with these inputs. const __m256i v_pm_d = _mm256_madd_epi16(v_p0_d, v_m_d); const __m256i v_diff0_d = _mm256_sub_epi32(v_w_d, v_pm_d); const __m256i v_sign_d = _mm256_srai_epi32(v_diff0_d, 31); const __m256i v_tmp_d = _mm256_add_epi32(_mm256_add_epi32(v_diff0_d, v_bias_d), v_sign_d); const __m256i v_rdiff0_d = _mm256_srai_epi32(v_tmp_d, 12); const __m128i v_rdiff_d = _mm256_castsi256_si128(v_rdiff0_d); const __m128i v_rdiff1_d = _mm256_extracti128_si256(v_rdiff0_d, 1); const __m128i v_rdiff01_w = _mm_packs_epi32(v_rdiff_d, v_rdiff1_d); const __m128i v_sqrdiff_d = _mm_madd_epi16(v_rdiff01_w, v_rdiff01_w); v_sum_d = _mm_add_epi32(v_sum_d, v_rdiff_d); v_sum_d = _mm_add_epi32(v_sum_d, v_rdiff1_d); v_sse_d = _mm_add_epi32(v_sse_d, v_sqrdiff_d); pre_temp += 8; n += 8; width -= 8; } while (width > 0); pre += pre_stride; height -= 1; } while (height > 0); v_d = _mm_hadd_epi32(v_sum_d, v_sse_d); v_d = _mm_hadd_epi32(v_d, v_d); *sum = _mm_cvtsi128_si32(v_d); *sse = _mm_cvtsi128_si32(_mm_srli_si128(v_d, 4)); } static INLINE void obmc_variance_w16n(const uint8_t *pre, const int pre_stride, const int32_t *wsrc, const int32_t *mask, unsigned int *const sse, int *const sum, const int w, const int h) { int n = 0, width, height = h; __m256i v_d; __m128i res0; const uint8_t *pre_temp; const __m256i v_bias_d = _mm256_set1_epi32((1 << 12) >> 1); __m256i v_sum_d = _mm256_setzero_si256(); __m256i v_sse_d = _mm256_setzero_si256(); assert(w >= 16); assert(IS_POWER_OF_TWO(w)); assert(IS_POWER_OF_TWO(h)); do { width = w; pre_temp = pre; do { const __m128i v_p_b = _mm_loadu_si128((__m128i *)pre_temp); const __m256i v_m0_d = _mm256_loadu_si256((__m256i const *)(mask + n)); const __m256i v_w0_d = _mm256_loadu_si256((__m256i const *)(wsrc + n)); const __m256i v_m1_d = _mm256_loadu_si256((__m256i const *)(mask + n + 8)); const __m256i v_w1_d = _mm256_loadu_si256((__m256i const *)(wsrc + n + 8)); const __m256i v_p0_d = _mm256_cvtepu8_epi32(v_p_b); const __m256i v_p1_d = _mm256_cvtepu8_epi32(_mm_srli_si128(v_p_b, 8)); const __m256i v_pm0_d = _mm256_madd_epi16(v_p0_d, v_m0_d); const __m256i v_pm1_d = _mm256_madd_epi16(v_p1_d, v_m1_d); const __m256i v_diff0_d = _mm256_sub_epi32(v_w0_d, v_pm0_d); const __m256i v_diff1_d = _mm256_sub_epi32(v_w1_d, v_pm1_d); const __m256i v_sign0_d = _mm256_srai_epi32(v_diff0_d, 31); const __m256i v_sign1_d = _mm256_srai_epi32(v_diff1_d, 31); const __m256i v_tmp0_d = _mm256_add_epi32(_mm256_add_epi32(v_diff0_d, v_bias_d), v_sign0_d); const __m256i v_tmp1_d = _mm256_add_epi32(_mm256_add_epi32(v_diff1_d, v_bias_d), v_sign1_d); const __m256i v_rdiff0_d = _mm256_srai_epi32(v_tmp0_d, 12); const __m256i v_rdiff2_d = _mm256_srai_epi32(v_tmp1_d, 12); const __m256i v_rdiff1_d = _mm256_add_epi32(v_rdiff0_d, v_rdiff2_d); const __m256i v_rdiff01_w = _mm256_packs_epi32(v_rdiff0_d, v_rdiff2_d); const __m256i v_sqrdiff_d = _mm256_madd_epi16(v_rdiff01_w, v_rdiff01_w); v_sum_d = _mm256_add_epi32(v_sum_d, v_rdiff1_d); v_sse_d = _mm256_add_epi32(v_sse_d, v_sqrdiff_d); pre_temp += 16; n += 16; width -= 16; } while (width > 0); pre += pre_stride; height -= 1; } while (height > 0); v_d = _mm256_hadd_epi32(v_sum_d, v_sse_d); v_d = _mm256_hadd_epi32(v_d, v_d); res0 = _mm256_castsi256_si128(v_d); res0 = _mm_add_epi32(res0, _mm256_extractf128_si256(v_d, 1)); *sum = _mm_cvtsi128_si32(res0); *sse = _mm_cvtsi128_si32(_mm_srli_si128(res0, 4)); } #define OBMCVARWXH(W, H) \ unsigned int aom_obmc_variance##W##x##H##_avx2(const uint8_t *pre, \ int pre_stride, \ const int32_t *wsrc, \ const int32_t *mask, \ unsigned int * sse) { \ int sum; \ if (W == 4) { \ obmc_variance_w4(pre, pre_stride, wsrc, mask, sse, &sum, H); \ } else if (W == 8) { \ obmc_variance_w8n(pre, pre_stride, wsrc, mask, sse, &sum, W, H); \ } else { \ obmc_variance_w16n(pre, pre_stride, wsrc, mask, sse, &sum, W, H); \ } \ \ return *sse - (unsigned int)(((int64_t)sum * sum) / (W * H)); \ } OBMCVARWXH(128, 128) OBMCVARWXH(128, 64) OBMCVARWXH(64, 128) OBMCVARWXH(64, 64) OBMCVARWXH(64, 32) OBMCVARWXH(32, 64) OBMCVARWXH(32, 32) OBMCVARWXH(32, 16) OBMCVARWXH(16, 32) OBMCVARWXH(16, 16) OBMCVARWXH(16, 8) OBMCVARWXH(8, 16) OBMCVARWXH(8, 8) OBMCVARWXH(8, 4) OBMCVARWXH(4, 8) OBMCVARWXH(4, 4) OBMCVARWXH(4, 16) OBMCVARWXH(16, 4) OBMCVARWXH(8, 32) OBMCVARWXH(32, 8) OBMCVARWXH(16, 64) OBMCVARWXH(64, 16)
593951.c
/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2019-07-23 tyustli first version */ #include <rtthread.h> #include <rtdevice.h> int main(int argc, char *argv[]) { return RT_EOK; } /******************** end of file *******************/
233618.c
/* * Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Redis nor the names of its contributors may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include "server.h" #include <math.h> /* isnan(), isinf() */ /* Forward declarations */ int getGenericCommand(client *c); /*----------------------------------------------------------------------------- * String Commands *----------------------------------------------------------------------------*/ static int checkStringLength(client *c, long long size) { if (!(c->flags & CLIENT_MASTER) && size > server.proto_max_bulk_len) { addReplyError(c,"string exceeds maximum allowed size (proto-max-bulk-len)"); return C_ERR; } return C_OK; } /* The setGenericCommand() function implements the SET operation with different * options and variants. This function is called in order to implement the * following commands: SET, SETEX, PSETEX, SETNX, GETSET. * * 'flags' changes the behavior of the command (NX, XX or GET, see below). * * 'expire' represents an expire to set in form of a Redis object as passed * by the user. It is interpreted according to the specified 'unit'. * * 'ok_reply' and 'abort_reply' is what the function will reply to the client * if the operation is performed, or when it is not because of NX or * XX flags. * * If ok_reply is NULL "+OK" is used. * If abort_reply is NULL, "$-1" is used. */ #define OBJ_NO_FLAGS 0 #define OBJ_SET_NX (1<<0) /* Set if key not exists. */ #define OBJ_SET_XX (1<<1) /* Set if key exists. */ #define OBJ_EX (1<<2) /* Set if time in seconds is given */ #define OBJ_PX (1<<3) /* Set if time in ms in given */ #define OBJ_KEEPTTL (1<<4) /* Set and keep the ttl */ #define OBJ_SET_GET (1<<5) /* Set if want to get key before set */ #define OBJ_EXAT (1<<6) /* Set if timestamp in second is given */ #define OBJ_PXAT (1<<7) /* Set if timestamp in ms is given */ #define OBJ_PERSIST (1<<8) /* Set if we need to remove the ttl */ /* Forward declaration */ static int getExpireMillisecondsOrReply(client *c, robj *expire, int flags, int unit, long long *milliseconds); void setGenericCommand(client *c, int flags, robj *key, robj *val, robj *expire, int unit, robj *ok_reply, robj *abort_reply) { long long milliseconds = 0; /* initialized to avoid any harmness warning */ if (expire && getExpireMillisecondsOrReply(c, expire, flags, unit, &milliseconds) != C_OK) { return; } if (flags & OBJ_SET_GET) { if (getGenericCommand(c) == C_ERR) return; } if ((flags & OBJ_SET_NX && lookupKeyWrite(c->db,key) != NULL) || (flags & OBJ_SET_XX && lookupKeyWrite(c->db,key) == NULL)) { if (!(flags & OBJ_SET_GET)) { addReply(c, abort_reply ? abort_reply : shared.null[c->resp]); } return; } genericSetKey(c,c->db,key, val,flags & OBJ_KEEPTTL,1); server.dirty++; notifyKeyspaceEvent(NOTIFY_STRING,"set",key,c->db->id); if (expire) { setExpire(c,c->db,key,milliseconds); /* Propagate as SET Key Value PXAT millisecond-timestamp if there is * EX/PX/EXAT/PXAT flag. */ robj *milliseconds_obj = createStringObjectFromLongLong(milliseconds); rewriteClientCommandVector(c, 5, shared.set, key, val, shared.pxat, milliseconds_obj); decrRefCount(milliseconds_obj); notifyKeyspaceEvent(NOTIFY_GENERIC,"expire",key,c->db->id); } if (!(flags & OBJ_SET_GET)) { addReply(c, ok_reply ? ok_reply : shared.ok); } /* Propagate without the GET argument (Isn't needed if we had expire since in that case we completely re-written the command argv) */ if ((flags & OBJ_SET_GET) && !expire) { int argc = 0; int j; robj **argv = zmalloc((c->argc-1)*sizeof(robj*)); for (j=0; j < c->argc; j++) { char *a = c->argv[j]->ptr; /* Skip GET which may be repeated multiple times. */ if (j >= 3 && (a[0] == 'g' || a[0] == 'G') && (a[1] == 'e' || a[1] == 'E') && (a[2] == 't' || a[2] == 'T') && a[3] == '\0') continue; argv[argc++] = c->argv[j]; incrRefCount(c->argv[j]); } replaceClientCommandVector(c, argc, argv); } } /* * Extract the `expire` argument of a given GET/SET command as an absolute timestamp in milliseconds. * * "client" is the client that sent the `expire` argument. * "expire" is the `expire` argument to be extracted. * "flags" represents the behavior of the command (e.g. PX or EX). * "unit" is the original unit of the given `expire` argument (e.g. UNIT_SECONDS). * "milliseconds" is output argument. * * If return C_OK, "milliseconds" output argument will be set to the resulting absolute timestamp. * If return C_ERR, an error reply has been added to the given client. */ static int getExpireMillisecondsOrReply(client *c, robj *expire, int flags, int unit, long long *milliseconds) { int ret = getLongLongFromObjectOrReply(c, expire, milliseconds, NULL); if (ret != C_OK) { return ret; } if (*milliseconds <= 0 || (unit == UNIT_SECONDS && *milliseconds > LLONG_MAX / 1000)) { /* Negative value provided or multiplication is gonna overflow. */ addReplyErrorFormat(c, "invalid expire time in %s", c->cmd->name); return C_ERR; } if (unit == UNIT_SECONDS) *milliseconds *= 1000; if ((flags & OBJ_PX) || (flags & OBJ_EX)) { *milliseconds += mstime(); } if (*milliseconds <= 0) { /* Overflow detected. */ addReplyErrorFormat(c,"invalid expire time in %s",c->cmd->name); return C_ERR; } return C_OK; } #define COMMAND_GET 0 #define COMMAND_SET 1 /* * The parseExtendedStringArgumentsOrReply() function performs the common validation for extended * string arguments used in SET and GET command. * * Get specific commands - PERSIST/DEL * Set specific commands - XX/NX/GET * Common commands - EX/EXAT/PX/PXAT/KEEPTTL * * Function takes pointers to client, flags, unit, pointer to pointer of expire obj if needed * to be determined and command_type which can be COMMAND_GET or COMMAND_SET. * * If there are any syntax violations C_ERR is returned else C_OK is returned. * * Input flags are updated upon parsing the arguments. Unit and expire are updated if there are any * EX/EXAT/PX/PXAT arguments. Unit is updated to millisecond if PX/PXAT is set. */ int parseExtendedStringArgumentsOrReply(client *c, int *flags, int *unit, robj **expire, int command_type) { int j = command_type == COMMAND_GET ? 2 : 3; for (; j < c->argc; j++) { char *opt = c->argv[j]->ptr; robj *next = (j == c->argc-1) ? NULL : c->argv[j+1]; if ((opt[0] == 'n' || opt[0] == 'N') && (opt[1] == 'x' || opt[1] == 'X') && opt[2] == '\0' && !(*flags & OBJ_SET_XX) && (command_type == COMMAND_SET)) { *flags |= OBJ_SET_NX; } else if ((opt[0] == 'x' || opt[0] == 'X') && (opt[1] == 'x' || opt[1] == 'X') && opt[2] == '\0' && !(*flags & OBJ_SET_NX) && (command_type == COMMAND_SET)) { *flags |= OBJ_SET_XX; } else if ((opt[0] == 'g' || opt[0] == 'G') && (opt[1] == 'e' || opt[1] == 'E') && (opt[2] == 't' || opt[2] == 'T') && opt[3] == '\0' && (command_type == COMMAND_SET)) { *flags |= OBJ_SET_GET; } else if (!strcasecmp(opt, "KEEPTTL") && !(*flags & OBJ_PERSIST) && !(*flags & OBJ_EX) && !(*flags & OBJ_EXAT) && !(*flags & OBJ_PX) && !(*flags & OBJ_PXAT) && (command_type == COMMAND_SET)) { *flags |= OBJ_KEEPTTL; } else if (!strcasecmp(opt,"PERSIST") && (command_type == COMMAND_GET) && !(*flags & OBJ_EX) && !(*flags & OBJ_EXAT) && !(*flags & OBJ_PX) && !(*flags & OBJ_PXAT) && !(*flags & OBJ_KEEPTTL)) { *flags |= OBJ_PERSIST; } else if ((opt[0] == 'e' || opt[0] == 'E') && (opt[1] == 'x' || opt[1] == 'X') && opt[2] == '\0' && !(*flags & OBJ_KEEPTTL) && !(*flags & OBJ_PERSIST) && !(*flags & OBJ_EXAT) && !(*flags & OBJ_PX) && !(*flags & OBJ_PXAT) && next) { *flags |= OBJ_EX; *expire = next; j++; } else if ((opt[0] == 'p' || opt[0] == 'P') && (opt[1] == 'x' || opt[1] == 'X') && opt[2] == '\0' && !(*flags & OBJ_KEEPTTL) && !(*flags & OBJ_PERSIST) && !(*flags & OBJ_EX) && !(*flags & OBJ_EXAT) && !(*flags & OBJ_PXAT) && next) { *flags |= OBJ_PX; *unit = UNIT_MILLISECONDS; *expire = next; j++; } else if ((opt[0] == 'e' || opt[0] == 'E') && (opt[1] == 'x' || opt[1] == 'X') && (opt[2] == 'a' || opt[2] == 'A') && (opt[3] == 't' || opt[3] == 'T') && opt[4] == '\0' && !(*flags & OBJ_KEEPTTL) && !(*flags & OBJ_PERSIST) && !(*flags & OBJ_EX) && !(*flags & OBJ_PX) && !(*flags & OBJ_PXAT) && next) { *flags |= OBJ_EXAT; *expire = next; j++; } else if ((opt[0] == 'p' || opt[0] == 'P') && (opt[1] == 'x' || opt[1] == 'X') && (opt[2] == 'a' || opt[2] == 'A') && (opt[3] == 't' || opt[3] == 'T') && opt[4] == '\0' && !(*flags & OBJ_KEEPTTL) && !(*flags & OBJ_PERSIST) && !(*flags & OBJ_EX) && !(*flags & OBJ_EXAT) && !(*flags & OBJ_PX) && next) { *flags |= OBJ_PXAT; *unit = UNIT_MILLISECONDS; *expire = next; j++; } else { addReplyErrorObject(c,shared.syntaxerr); return C_ERR; } } return C_OK; } /* SET key value [NX] [XX] [KEEPTTL] [GET] [EX <seconds>] [PX <milliseconds>] * [EXAT <seconds-timestamp>][PXAT <milliseconds-timestamp>] */ void setCommand(client *c) { robj *expire = NULL; int unit = UNIT_SECONDS; int flags = OBJ_NO_FLAGS; if (parseExtendedStringArgumentsOrReply(c,&flags,&unit,&expire,COMMAND_SET) != C_OK) { return; } c->argv[2] = tryObjectEncoding(c->argv[2]); setGenericCommand(c,flags,c->argv[1],c->argv[2],expire,unit,NULL,NULL); } void setnxCommand(client *c) { c->argv[2] = tryObjectEncoding(c->argv[2]); setGenericCommand(c,OBJ_SET_NX,c->argv[1],c->argv[2],NULL,0,shared.cone,shared.czero); } void setexCommand(client *c) { c->argv[3] = tryObjectEncoding(c->argv[3]); setGenericCommand(c,OBJ_EX,c->argv[1],c->argv[3],c->argv[2],UNIT_SECONDS,NULL,NULL); } void psetexCommand(client *c) { c->argv[3] = tryObjectEncoding(c->argv[3]); setGenericCommand(c,OBJ_PX,c->argv[1],c->argv[3],c->argv[2],UNIT_MILLISECONDS,NULL,NULL); } int getGenericCommand(client *c) { robj *o; if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp])) == NULL) return C_OK; if (checkType(c,o,OBJ_STRING)) { return C_ERR; } addReplyBulk(c,o); return C_OK; } void getCommand(client *c) { getGenericCommand(c); } /* * GETEX <key> [PERSIST][EX seconds][PX milliseconds][EXAT seconds-timestamp][PXAT milliseconds-timestamp] * * The getexCommand() function implements extended options and variants of the GET command. Unlike GET * command this command is not read-only. * * The default behavior when no options are specified is same as GET and does not alter any TTL. * * Only one of the below options can be used at a given time. * * 1. PERSIST removes any TTL associated with the key. * 2. EX Set expiry TTL in seconds. * 3. PX Set expiry TTL in milliseconds. * 4. EXAT Same like EX instead of specifying the number of seconds representing the TTL * (time to live), it takes an absolute Unix timestamp * 5. PXAT Same like PX instead of specifying the number of milliseconds representing the TTL * (time to live), it takes an absolute Unix timestamp * * Command would either return the bulk string, error or nil. */ void getexCommand(client *c) { robj *expire = NULL; int unit = UNIT_SECONDS; int flags = OBJ_NO_FLAGS; if (parseExtendedStringArgumentsOrReply(c,&flags,&unit,&expire,COMMAND_GET) != C_OK) { return; } robj *o; if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp])) == NULL) return; if (checkType(c,o,OBJ_STRING)) { return; } /* Validate the expiration time value first */ long long milliseconds = 0; if (expire && getExpireMillisecondsOrReply(c, expire, flags, unit, &milliseconds) != C_OK) { return; } /* We need to do this before we expire the key or delete it */ addReplyBulk(c,o); /* This command is never propagated as is. It is either propagated as PEXPIRE[AT],DEL,UNLINK or PERSIST. * This why it doesn't need special handling in feedAppendOnlyFile to convert relative expire time to absolute one. */ if (((flags & OBJ_PXAT) || (flags & OBJ_EXAT)) && checkAlreadyExpired(milliseconds)) { /* When PXAT/EXAT absolute timestamp is specified, there can be a chance that timestamp * has already elapsed so delete the key in that case. */ int deleted = server.lazyfree_lazy_expire ? dbAsyncDelete(c->db, c->argv[1]) : dbSyncDelete(c->db, c->argv[1]); serverAssert(deleted); robj *aux = server.lazyfree_lazy_expire ? shared.unlink : shared.del; rewriteClientCommandVector(c,2,aux,c->argv[1]); signalModifiedKey(c, c->db, c->argv[1]); notifyKeyspaceEvent(NOTIFY_GENERIC, "del", c->argv[1], c->db->id); server.dirty++; } else if (expire) { setExpire(c,c->db,c->argv[1],milliseconds); /* Propagate as PXEXPIREAT millisecond-timestamp if there is * EX/PX/EXAT/PXAT flag and the key has not expired. */ robj *milliseconds_obj = createStringObjectFromLongLong(milliseconds); rewriteClientCommandVector(c,3,shared.pexpireat,c->argv[1],milliseconds_obj); decrRefCount(milliseconds_obj); signalModifiedKey(c, c->db, c->argv[1]); notifyKeyspaceEvent(NOTIFY_GENERIC,"expire",c->argv[1],c->db->id); server.dirty++; } else if (flags & OBJ_PERSIST) { if (removeExpire(c->db, c->argv[1])) { signalModifiedKey(c, c->db, c->argv[1]); rewriteClientCommandVector(c, 2, shared.persist, c->argv[1]); notifyKeyspaceEvent(NOTIFY_GENERIC,"persist",c->argv[1],c->db->id); server.dirty++; } } } void getdelCommand(client *c) { if (getGenericCommand(c) == C_ERR) return; int deleted = server.lazyfree_lazy_user_del ? dbAsyncDelete(c->db, c->argv[1]) : dbSyncDelete(c->db, c->argv[1]); if (deleted) { /* Propagate as DEL/UNLINK command */ robj *aux = server.lazyfree_lazy_user_del ? shared.unlink : shared.del; rewriteClientCommandVector(c,2,aux,c->argv[1]); signalModifiedKey(c, c->db, c->argv[1]); notifyKeyspaceEvent(NOTIFY_GENERIC, "del", c->argv[1], c->db->id); server.dirty++; } } void getsetCommand(client *c) { if (getGenericCommand(c) == C_ERR) return; c->argv[2] = tryObjectEncoding(c->argv[2]); setKey(c,c->db,c->argv[1],c->argv[2]); notifyKeyspaceEvent(NOTIFY_STRING,"set",c->argv[1],c->db->id); server.dirty++; /* Propagate as SET command */ rewriteClientCommandArgument(c,0,shared.set); } void setrangeCommand(client *c) { robj *o; long offset; sds value = c->argv[3]->ptr; if (getLongFromObjectOrReply(c,c->argv[2],&offset,NULL) != C_OK) return; if (offset < 0) { addReplyError(c,"offset is out of range"); return; } o = lookupKeyWrite(c->db,c->argv[1]); if (o == NULL) { /* Return 0 when setting nothing on a non-existing string */ if (sdslen(value) == 0) { addReply(c,shared.czero); return; } /* Return when the resulting string exceeds allowed size */ if (checkStringLength(c,offset+sdslen(value)) != C_OK) return; o = createObject(OBJ_STRING,sdsnewlen(NULL, offset+sdslen(value))); dbAdd(c->db,c->argv[1],o); } else { size_t olen; /* Key exists, check type */ if (checkType(c,o,OBJ_STRING)) return; /* Return existing string length when setting nothing */ olen = stringObjectLen(o); if (sdslen(value) == 0) { addReplyLongLong(c,olen); return; } /* Return when the resulting string exceeds allowed size */ if (checkStringLength(c,offset+sdslen(value)) != C_OK) return; /* Create a copy when the object is shared or encoded. */ o = dbUnshareStringValue(c->db,c->argv[1],o); } if (sdslen(value) > 0) { o->ptr = sdsgrowzero(o->ptr,offset+sdslen(value)); memcpy((char*)o->ptr+offset,value,sdslen(value)); signalModifiedKey(c,c->db,c->argv[1]); notifyKeyspaceEvent(NOTIFY_STRING, "setrange",c->argv[1],c->db->id); server.dirty++; } addReplyLongLong(c,sdslen(o->ptr)); } void getrangeCommand(client *c) { robj *o; long long start, end; char *str, llbuf[32]; size_t strlen; if (getLongLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK) return; if (getLongLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK) return; if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.emptybulk)) == NULL || checkType(c,o,OBJ_STRING)) return; if (o->encoding == OBJ_ENCODING_INT) { str = llbuf; strlen = ll2string(llbuf,sizeof(llbuf),(long)o->ptr); } else { str = o->ptr; strlen = sdslen(str); } /* Convert negative indexes */ if (start < 0 && end < 0 && start > end) { addReply(c,shared.emptybulk); return; } if (start < 0) start = strlen+start; if (end < 0) end = strlen+end; if (start < 0) start = 0; if (end < 0) end = 0; if ((unsigned long long)end >= strlen) end = strlen-1; /* Precondition: end >= 0 && end < strlen, so the only condition where * nothing can be returned is: start > end. */ if (start > end || strlen == 0) { addReply(c,shared.emptybulk); } else { addReplyBulkCBuffer(c,(char*)str+start,end-start+1); } } void mgetCommand(client *c) { int j; addReplyArrayLen(c,c->argc-1); for (j = 1; j < c->argc; j++) { robj *o = lookupKeyRead(c->db,c->argv[j]); if (o == NULL) { addReplyNull(c); } else { if (o->type != OBJ_STRING) { addReplyNull(c); } else { addReplyBulk(c,o); } } } } void msetGenericCommand(client *c, int nx) { int j; if ((c->argc % 2) == 0) { addReplyErrorFormat(c,"wrong number of arguments for '%s' command", c->cmd->name); return; } /* Handle the NX flag. The MSETNX semantic is to return zero and don't * set anything if at least one key already exists. */ if (nx) { for (j = 1; j < c->argc; j += 2) { if (lookupKeyWrite(c->db,c->argv[j]) != NULL) { addReply(c, shared.czero); return; } } } for (j = 1; j < c->argc; j += 2) { c->argv[j+1] = tryObjectEncoding(c->argv[j+1]); setKey(c,c->db,c->argv[j],c->argv[j+1]); notifyKeyspaceEvent(NOTIFY_STRING,"set",c->argv[j],c->db->id); } server.dirty += (c->argc-1)/2; addReply(c, nx ? shared.cone : shared.ok); } void msetCommand(client *c) { msetGenericCommand(c,0); } void msetnxCommand(client *c) { msetGenericCommand(c,1); } void incrDecrCommand(client *c, long long incr) { long long value, oldvalue; robj *o, *new; o = lookupKeyWrite(c->db,c->argv[1]); if (checkType(c,o,OBJ_STRING)) return; if (getLongLongFromObjectOrReply(c,o,&value,NULL) != C_OK) return; oldvalue = value; if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) || (incr > 0 && oldvalue > 0 && incr > (LLONG_MAX-oldvalue))) { addReplyError(c,"increment or decrement would overflow"); return; } value += incr; if (o && o->refcount == 1 && o->encoding == OBJ_ENCODING_INT && (value < 0 || value >= OBJ_SHARED_INTEGERS) && value >= LONG_MIN && value <= LONG_MAX) { new = o; o->ptr = (void*)((long)value); } else { new = createStringObjectFromLongLongForValue(value); if (o) { dbOverwrite(c->db,c->argv[1],new); } else { dbAdd(c->db,c->argv[1],new); } } signalModifiedKey(c,c->db,c->argv[1]); notifyKeyspaceEvent(NOTIFY_STRING,"incrby",c->argv[1],c->db->id); server.dirty++; addReply(c,shared.colon); addReply(c,new); addReply(c,shared.crlf); } void incrCommand(client *c) { incrDecrCommand(c,1); } void decrCommand(client *c) { incrDecrCommand(c,-1); } void incrbyCommand(client *c) { long long incr; if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != C_OK) return; incrDecrCommand(c,incr); } void decrbyCommand(client *c) { long long incr; if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != C_OK) return; incrDecrCommand(c,-incr); } void incrbyfloatCommand(client *c) { long double incr, value; robj *o, *new; o = lookupKeyWrite(c->db,c->argv[1]); if (checkType(c,o,OBJ_STRING)) return; if (getLongDoubleFromObjectOrReply(c,o,&value,NULL) != C_OK || getLongDoubleFromObjectOrReply(c,c->argv[2],&incr,NULL) != C_OK) return; value += incr; if (isnan(value) || isinf(value)) { addReplyError(c,"increment would produce NaN or Infinity"); return; } new = createStringObjectFromLongDouble(value,1); if (o) dbOverwrite(c->db,c->argv[1],new); else dbAdd(c->db,c->argv[1],new); signalModifiedKey(c,c->db,c->argv[1]); notifyKeyspaceEvent(NOTIFY_STRING,"incrbyfloat",c->argv[1],c->db->id); server.dirty++; addReplyBulk(c,new); /* Always replicate INCRBYFLOAT as a SET command with the final value * in order to make sure that differences in float precision or formatting * will not create differences in replicas or after an AOF restart. */ rewriteClientCommandArgument(c,0,shared.set); rewriteClientCommandArgument(c,2,new); rewriteClientCommandArgument(c,3,shared.keepttl); } void appendCommand(client *c) { size_t totlen; robj *o, *append; o = lookupKeyWrite(c->db,c->argv[1]); if (o == NULL) { /* Create the key */ c->argv[2] = tryObjectEncoding(c->argv[2]); dbAdd(c->db,c->argv[1],c->argv[2]); incrRefCount(c->argv[2]); totlen = stringObjectLen(c->argv[2]); } else { /* Key exists, check type */ if (checkType(c,o,OBJ_STRING)) return; /* "append" is an argument, so always an sds */ append = c->argv[2]; totlen = stringObjectLen(o)+sdslen(append->ptr); if (checkStringLength(c,totlen) != C_OK) return; /* Append the value */ o = dbUnshareStringValue(c->db,c->argv[1],o); o->ptr = sdscatlen(o->ptr,append->ptr,sdslen(append->ptr)); totlen = sdslen(o->ptr); } signalModifiedKey(c,c->db,c->argv[1]); notifyKeyspaceEvent(NOTIFY_STRING,"append",c->argv[1],c->db->id); server.dirty++; addReplyLongLong(c,totlen); } void strlenCommand(client *c) { robj *o; if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL || checkType(c,o,OBJ_STRING)) return; addReplyLongLong(c,stringObjectLen(o)); } /* STRALGO -- Implement complex algorithms on strings. * * STRALGO <algorithm> ... arguments ... */ void stralgoLCS(client *c); /* This implements the LCS algorithm. */ void stralgoCommand(client *c) { /* Select the algorithm. */ if (!strcasecmp(c->argv[1]->ptr,"lcs")) { stralgoLCS(c); } else { addReplyErrorObject(c,shared.syntaxerr); } } /* STRALGO <algo> [IDX] [LEN] [MINMATCHLEN <len>] [WITHMATCHLEN] * STRINGS <string> <string> | KEYS <keya> <keyb> */ void stralgoLCS(client *c) { uint32_t i, j; long long minmatchlen = 0; sds a = NULL, b = NULL; int getlen = 0, getidx = 0, withmatchlen = 0; robj *obja = NULL, *objb = NULL; for (j = 2; j < (uint32_t)c->argc; j++) { char *opt = c->argv[j]->ptr; int moreargs = (c->argc-1) - j; if (!strcasecmp(opt,"IDX")) { getidx = 1; } else if (!strcasecmp(opt,"LEN")) { getlen = 1; } else if (!strcasecmp(opt,"WITHMATCHLEN")) { withmatchlen = 1; } else if (!strcasecmp(opt,"MINMATCHLEN") && moreargs) { if (getLongLongFromObjectOrReply(c,c->argv[j+1],&minmatchlen,NULL) != C_OK) goto cleanup; if (minmatchlen < 0) minmatchlen = 0; j++; } else if (!strcasecmp(opt,"STRINGS") && moreargs > 1) { if (a != NULL) { addReplyError(c,"Either use STRINGS or KEYS"); goto cleanup; } a = c->argv[j+1]->ptr; b = c->argv[j+2]->ptr; j += 2; } else if (!strcasecmp(opt,"KEYS") && moreargs > 1) { if (a != NULL) { addReplyError(c,"Either use STRINGS or KEYS"); goto cleanup; } obja = lookupKeyRead(c->db,c->argv[j+1]); objb = lookupKeyRead(c->db,c->argv[j+2]); if ((obja && obja->type != OBJ_STRING) || (objb && objb->type != OBJ_STRING)) { addReplyError(c, "The specified keys must contain string values"); /* Don't cleanup the objects, we need to do that * only after calling getDecodedObject(). */ obja = NULL; objb = NULL; goto cleanup; } obja = obja ? getDecodedObject(obja) : createStringObject("",0); objb = objb ? getDecodedObject(objb) : createStringObject("",0); a = obja->ptr; b = objb->ptr; j += 2; } else { addReplyErrorObject(c,shared.syntaxerr); goto cleanup; } } /* Complain if the user passed ambiguous parameters. */ if (a == NULL) { addReplyError(c,"Please specify two strings: " "STRINGS or KEYS options are mandatory"); goto cleanup; } else if (getlen && getidx) { addReplyError(c, "If you want both the length and indexes, please " "just use IDX."); goto cleanup; } /* Detect string truncation or later overflows. */ if (sdslen(a) >= UINT32_MAX-1 || sdslen(b) >= UINT32_MAX-1) { addReplyError(c, "String too long for LCS"); goto cleanup; } /* Compute the LCS using the vanilla dynamic programming technique of * building a table of LCS(x,y) substrings. */ uint32_t alen = sdslen(a); uint32_t blen = sdslen(b); /* Setup an uint32_t array to store at LCS[i,j] the length of the * LCS A0..i-1, B0..j-1. Note that we have a linear array here, so * we index it as LCS[j+(blen+1)*j] */ #define LCS(A,B) lcs[(B)+((A)*(blen+1))] /* Try to allocate the LCS table, and abort on overflow or insufficient memory. */ unsigned long long lcssize = (unsigned long long)(alen+1)*(blen+1); /* Can't overflow due to the size limits above. */ unsigned long long lcsalloc = lcssize * sizeof(uint32_t); uint32_t *lcs = NULL; if (lcsalloc < SIZE_MAX && lcsalloc / lcssize == sizeof(uint32_t)) lcs = ztrymalloc(lcsalloc); if (!lcs) { addReplyError(c, "Insufficient memory"); goto cleanup; } /* Start building the LCS table. */ for (uint32_t i = 0; i <= alen; i++) { for (uint32_t j = 0; j <= blen; j++) { if (i == 0 || j == 0) { /* If one substring has length of zero, the * LCS length is zero. */ LCS(i,j) = 0; } else if (a[i-1] == b[j-1]) { /* The len LCS (and the LCS itself) of two * sequences with the same final character, is the * LCS of the two sequences without the last char * plus that last char. */ LCS(i,j) = LCS(i-1,j-1)+1; } else { /* If the last character is different, take the longest * between the LCS of the first string and the second * minus the last char, and the reverse. */ uint32_t lcs1 = LCS(i-1,j); uint32_t lcs2 = LCS(i,j-1); LCS(i,j) = lcs1 > lcs2 ? lcs1 : lcs2; } } } /* Store the actual LCS string in "result" if needed. We create * it backward, but the length is already known, we store it into idx. */ uint32_t idx = LCS(alen,blen); sds result = NULL; /* Resulting LCS string. */ void *arraylenptr = NULL; /* Deferred length of the array for IDX. */ uint32_t arange_start = alen, /* alen signals that values are not set. */ arange_end = 0, brange_start = 0, brange_end = 0; /* Do we need to compute the actual LCS string? Allocate it in that case. */ int computelcs = getidx || !getlen; if (computelcs) result = sdsnewlen(SDS_NOINIT,idx); /* Start with a deferred array if we have to emit the ranges. */ uint32_t arraylen = 0; /* Number of ranges emitted in the array. */ if (getidx) { addReplyMapLen(c,2); addReplyBulkCString(c,"matches"); arraylenptr = addReplyDeferredLen(c); } i = alen, j = blen; while (computelcs && i > 0 && j > 0) { int emit_range = 0; if (a[i-1] == b[j-1]) { /* If there is a match, store the character and reduce * the indexes to look for a new match. */ result[idx-1] = a[i-1]; /* Track the current range. */ if (arange_start == alen) { arange_start = i-1; arange_end = i-1; brange_start = j-1; brange_end = j-1; } else { /* Let's see if we can extend the range backward since * it is contiguous. */ if (arange_start == i && brange_start == j) { arange_start--; brange_start--; } else { emit_range = 1; } } /* Emit the range if we matched with the first byte of * one of the two strings. We'll exit the loop ASAP. */ if (arange_start == 0 || brange_start == 0) emit_range = 1; idx--; i--; j--; } else { /* Otherwise reduce i and j depending on the largest * LCS between, to understand what direction we need to go. */ uint32_t lcs1 = LCS(i-1,j); uint32_t lcs2 = LCS(i,j-1); if (lcs1 > lcs2) i--; else j--; if (arange_start != alen) emit_range = 1; } /* Emit the current range if needed. */ uint32_t match_len = arange_end - arange_start + 1; if (emit_range) { if (minmatchlen == 0 || match_len >= minmatchlen) { if (arraylenptr) { addReplyArrayLen(c,2+withmatchlen); addReplyArrayLen(c,2); addReplyLongLong(c,arange_start); addReplyLongLong(c,arange_end); addReplyArrayLen(c,2); addReplyLongLong(c,brange_start); addReplyLongLong(c,brange_end); if (withmatchlen) addReplyLongLong(c,match_len); arraylen++; } } arange_start = alen; /* Restart at the next match. */ } } /* Signal modified key, increment dirty, ... */ /* Reply depending on the given options. */ if (arraylenptr) { addReplyBulkCString(c,"len"); addReplyLongLong(c,LCS(alen,blen)); setDeferredArrayLen(c,arraylenptr,arraylen); } else if (getlen) { addReplyLongLong(c,LCS(alen,blen)); } else { addReplyBulkSds(c,result); result = NULL; } /* Cleanup. */ sdsfree(result); zfree(lcs); cleanup: if (obja) decrRefCount(obja); if (objb) decrRefCount(objb); return; }
185035.c
#define CBLAS #define ASMNAME cblas_csyrk #define ASMFNAME cblas_csyrk_ #define NAME cblas_csyrk_ #define CNAME cblas_csyrk #define CHAR_NAME "cblas_csyrk_" #define CHAR_CNAME "cblas_csyrk" #define COMPLEX #include "/lustre/scratch3/turquoise/rvangara/RD100/distnnmfkcpp_Src/install_dependencies/xianyi-OpenBLAS-6d2da63/interface/syrk.c"
978652.c
/** Produto escalar de dois vetores de N posições. A.B = axbx + ayby + ... + anbn. */ #include <stdio.h> int produtoEscalar(int sizes, int *v1, int *v2){ int i; int escalar = 0; for (i = 0; i < sizes; i++){ escalar += v1[i] * v2[i]; } return escalar; } int main(){ int n; printf("Dimensão dos vetores: "); scanf("%d", &n); int v1[n]; int v2[n]; printf("Escreva os %d elementos inteiros de cada um dos DOIS vetores.\n", n); int i; for(i = 0; i < n; i++){ scanf("%d", &v1[i]); } for(i = 0; i < n; i++){ scanf("%d", &v2[i]); } printf("Produto escalar: %d\n", produtoEscalar(n, v1, v2)); return 0; }
871627.c
/* * Copyright 2015 Amazon.com, Inc. or its affiliates. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include "ena_com.h" /*****************************************************************************/ /*****************************************************************************/ /* Timeout in micro-sec */ #define ADMIN_CMD_TIMEOUT_US (3000000) #define ENA_ASYNC_QUEUE_DEPTH 16 #define ENA_ADMIN_QUEUE_DEPTH 32 #define ENA_CTRL_MAJOR 0 #define ENA_CTRL_MINOR 0 #define ENA_CTRL_SUB_MINOR 1 #define MIN_ENA_CTRL_VER \ (((ENA_CTRL_MAJOR) << \ (ENA_REGS_CONTROLLER_VERSION_MAJOR_VERSION_SHIFT)) | \ ((ENA_CTRL_MINOR) << \ (ENA_REGS_CONTROLLER_VERSION_MINOR_VERSION_SHIFT)) | \ (ENA_CTRL_SUB_MINOR)) #define ENA_DMA_ADDR_TO_UINT32_LOW(x) ((u32)((u64)(x))) #define ENA_DMA_ADDR_TO_UINT32_HIGH(x) ((u32)(((u64)(x)) >> 32)) #define ENA_MMIO_READ_TIMEOUT 0xFFFFFFFF #define ENA_COM_BOUNCE_BUFFER_CNTRL_CNT 4 #define ENA_REGS_ADMIN_INTR_MASK 1 #define ENA_POLL_MS 5 /*****************************************************************************/ /*****************************************************************************/ /*****************************************************************************/ enum ena_cmd_status { ENA_CMD_SUBMITTED, ENA_CMD_COMPLETED, /* Abort - canceled by the driver */ ENA_CMD_ABORTED, }; struct ena_comp_ctx { struct completion wait_event; struct ena_admin_acq_entry *user_cqe; u32 comp_size; enum ena_cmd_status status; /* status from the device */ u8 comp_status; u8 cmd_opcode; bool occupied; }; struct ena_com_stats_ctx { struct ena_admin_aq_get_stats_cmd get_cmd; struct ena_admin_acq_get_stats_resp get_resp; }; static inline int ena_com_mem_addr_set(struct ena_com_dev *ena_dev, struct ena_common_mem_addr *ena_addr, dma_addr_t addr) { if ((addr & GENMASK_ULL(ena_dev->dma_addr_bits - 1, 0)) != addr) { pr_err("dma address has more bits that the device supports\n"); return -EINVAL; } ena_addr->mem_addr_low = lower_32_bits(addr); ena_addr->mem_addr_high = (u16)upper_32_bits(addr); return 0; } static int ena_com_admin_init_sq(struct ena_com_admin_queue *queue) { struct ena_com_admin_sq *sq = &queue->sq; u16 size = ADMIN_SQ_SIZE(queue->q_depth); sq->entries = dma_zalloc_coherent(queue->q_dmadev, size, &sq->dma_addr, GFP_KERNEL); if (!sq->entries) { pr_err("memory allocation failed"); return -ENOMEM; } sq->head = 0; sq->tail = 0; sq->phase = 1; sq->db_addr = NULL; return 0; } static int ena_com_admin_init_cq(struct ena_com_admin_queue *queue) { struct ena_com_admin_cq *cq = &queue->cq; u16 size = ADMIN_CQ_SIZE(queue->q_depth); cq->entries = dma_zalloc_coherent(queue->q_dmadev, size, &cq->dma_addr, GFP_KERNEL); if (!cq->entries) { pr_err("memory allocation failed"); return -ENOMEM; } cq->head = 0; cq->phase = 1; return 0; } static int ena_com_admin_init_aenq(struct ena_com_dev *dev, struct ena_aenq_handlers *aenq_handlers) { struct ena_com_aenq *aenq = &dev->aenq; u32 addr_low, addr_high, aenq_caps; u16 size; dev->aenq.q_depth = ENA_ASYNC_QUEUE_DEPTH; size = ADMIN_AENQ_SIZE(ENA_ASYNC_QUEUE_DEPTH); aenq->entries = dma_zalloc_coherent(dev->dmadev, size, &aenq->dma_addr, GFP_KERNEL); if (!aenq->entries) { pr_err("memory allocation failed"); return -ENOMEM; } aenq->head = aenq->q_depth; aenq->phase = 1; addr_low = ENA_DMA_ADDR_TO_UINT32_LOW(aenq->dma_addr); addr_high = ENA_DMA_ADDR_TO_UINT32_HIGH(aenq->dma_addr); writel(addr_low, dev->reg_bar + ENA_REGS_AENQ_BASE_LO_OFF); writel(addr_high, dev->reg_bar + ENA_REGS_AENQ_BASE_HI_OFF); aenq_caps = 0; aenq_caps |= dev->aenq.q_depth & ENA_REGS_AENQ_CAPS_AENQ_DEPTH_MASK; aenq_caps |= (sizeof(struct ena_admin_aenq_entry) << ENA_REGS_AENQ_CAPS_AENQ_ENTRY_SIZE_SHIFT) & ENA_REGS_AENQ_CAPS_AENQ_ENTRY_SIZE_MASK; writel(aenq_caps, dev->reg_bar + ENA_REGS_AENQ_CAPS_OFF); if (unlikely(!aenq_handlers)) { pr_err("aenq handlers pointer is NULL\n"); return -EINVAL; } aenq->aenq_handlers = aenq_handlers; return 0; } static inline void comp_ctxt_release(struct ena_com_admin_queue *queue, struct ena_comp_ctx *comp_ctx) { comp_ctx->occupied = false; atomic_dec(&queue->outstanding_cmds); } static struct ena_comp_ctx *get_comp_ctxt(struct ena_com_admin_queue *queue, u16 command_id, bool capture) { if (unlikely(command_id >= queue->q_depth)) { pr_err("command id is larger than the queue size. cmd_id: %u queue size %d\n", command_id, queue->q_depth); return NULL; } if (unlikely(queue->comp_ctx[command_id].occupied && capture)) { pr_err("Completion context is occupied\n"); return NULL; } if (capture) { atomic_inc(&queue->outstanding_cmds); queue->comp_ctx[command_id].occupied = true; } return &queue->comp_ctx[command_id]; } static struct ena_comp_ctx *__ena_com_submit_admin_cmd(struct ena_com_admin_queue *admin_queue, struct ena_admin_aq_entry *cmd, size_t cmd_size_in_bytes, struct ena_admin_acq_entry *comp, size_t comp_size_in_bytes) { struct ena_comp_ctx *comp_ctx; u16 tail_masked, cmd_id; u16 queue_size_mask; u16 cnt; queue_size_mask = admin_queue->q_depth - 1; tail_masked = admin_queue->sq.tail & queue_size_mask; /* In case of queue FULL */ cnt = (u16)atomic_read(&admin_queue->outstanding_cmds); if (cnt >= admin_queue->q_depth) { pr_debug("admin queue is full.\n"); admin_queue->stats.out_of_space++; return ERR_PTR(-ENOSPC); } cmd_id = admin_queue->curr_cmd_id; cmd->aq_common_descriptor.flags |= admin_queue->sq.phase & ENA_ADMIN_AQ_COMMON_DESC_PHASE_MASK; cmd->aq_common_descriptor.command_id |= cmd_id & ENA_ADMIN_AQ_COMMON_DESC_COMMAND_ID_MASK; comp_ctx = get_comp_ctxt(admin_queue, cmd_id, true); if (unlikely(!comp_ctx)) return ERR_PTR(-EINVAL); comp_ctx->status = ENA_CMD_SUBMITTED; comp_ctx->comp_size = (u32)comp_size_in_bytes; comp_ctx->user_cqe = comp; comp_ctx->cmd_opcode = cmd->aq_common_descriptor.opcode; reinit_completion(&comp_ctx->wait_event); memcpy(&admin_queue->sq.entries[tail_masked], cmd, cmd_size_in_bytes); admin_queue->curr_cmd_id = (admin_queue->curr_cmd_id + 1) & queue_size_mask; admin_queue->sq.tail++; admin_queue->stats.submitted_cmd++; if (unlikely((admin_queue->sq.tail & queue_size_mask) == 0)) admin_queue->sq.phase = !admin_queue->sq.phase; writel(admin_queue->sq.tail, admin_queue->sq.db_addr); return comp_ctx; } static inline int ena_com_init_comp_ctxt(struct ena_com_admin_queue *queue) { size_t size = queue->q_depth * sizeof(struct ena_comp_ctx); struct ena_comp_ctx *comp_ctx; u16 i; queue->comp_ctx = devm_kzalloc(queue->q_dmadev, size, GFP_KERNEL); if (unlikely(!queue->comp_ctx)) { pr_err("memory allocation failed"); return -ENOMEM; } for (i = 0; i < queue->q_depth; i++) { comp_ctx = get_comp_ctxt(queue, i, false); if (comp_ctx) init_completion(&comp_ctx->wait_event); } return 0; } static struct ena_comp_ctx *ena_com_submit_admin_cmd(struct ena_com_admin_queue *admin_queue, struct ena_admin_aq_entry *cmd, size_t cmd_size_in_bytes, struct ena_admin_acq_entry *comp, size_t comp_size_in_bytes) { unsigned long flags = 0; struct ena_comp_ctx *comp_ctx; spin_lock_irqsave(&admin_queue->q_lock, flags); if (unlikely(!admin_queue->running_state)) { spin_unlock_irqrestore(&admin_queue->q_lock, flags); return ERR_PTR(-ENODEV); } comp_ctx = __ena_com_submit_admin_cmd(admin_queue, cmd, cmd_size_in_bytes, comp, comp_size_in_bytes); if (IS_ERR(comp_ctx)) admin_queue->running_state = false; spin_unlock_irqrestore(&admin_queue->q_lock, flags); return comp_ctx; } static int ena_com_init_io_sq(struct ena_com_dev *ena_dev, struct ena_com_create_io_ctx *ctx, struct ena_com_io_sq *io_sq) { size_t size; int dev_node = 0; memset(&io_sq->desc_addr, 0x0, sizeof(io_sq->desc_addr)); io_sq->dma_addr_bits = (u8)ena_dev->dma_addr_bits; io_sq->desc_entry_size = (io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX) ? sizeof(struct ena_eth_io_tx_desc) : sizeof(struct ena_eth_io_rx_desc); size = io_sq->desc_entry_size * io_sq->q_depth; if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST) { dev_node = dev_to_node(ena_dev->dmadev); set_dev_node(ena_dev->dmadev, ctx->numa_node); io_sq->desc_addr.virt_addr = dma_zalloc_coherent(ena_dev->dmadev, size, &io_sq->desc_addr.phys_addr, GFP_KERNEL); set_dev_node(ena_dev->dmadev, dev_node); if (!io_sq->desc_addr.virt_addr) { io_sq->desc_addr.virt_addr = dma_zalloc_coherent(ena_dev->dmadev, size, &io_sq->desc_addr.phys_addr, GFP_KERNEL); } if (!io_sq->desc_addr.virt_addr) { pr_err("memory allocation failed"); return -ENOMEM; } } if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV) { /* Allocate bounce buffers */ io_sq->bounce_buf_ctrl.buffer_size = ena_dev->llq_info.desc_list_entry_size; io_sq->bounce_buf_ctrl.buffers_num = ENA_COM_BOUNCE_BUFFER_CNTRL_CNT; io_sq->bounce_buf_ctrl.next_to_use = 0; size = io_sq->bounce_buf_ctrl.buffer_size * io_sq->bounce_buf_ctrl.buffers_num; dev_node = dev_to_node(ena_dev->dmadev); set_dev_node(ena_dev->dmadev, ctx->numa_node); io_sq->bounce_buf_ctrl.base_buffer = devm_kzalloc(ena_dev->dmadev, size, GFP_KERNEL); set_dev_node(ena_dev->dmadev, dev_node); if (!io_sq->bounce_buf_ctrl.base_buffer) io_sq->bounce_buf_ctrl.base_buffer = devm_kzalloc(ena_dev->dmadev, size, GFP_KERNEL); if (!io_sq->bounce_buf_ctrl.base_buffer) { pr_err("bounce buffer memory allocation failed"); return -ENOMEM; } memcpy(&io_sq->llq_info, &ena_dev->llq_info, sizeof(io_sq->llq_info)); /* Initiate the first bounce buffer */ io_sq->llq_buf_ctrl.curr_bounce_buf = ena_com_get_next_bounce_buffer(&io_sq->bounce_buf_ctrl); memset(io_sq->llq_buf_ctrl.curr_bounce_buf, 0x0, io_sq->llq_info.desc_list_entry_size); io_sq->llq_buf_ctrl.descs_left_in_line = io_sq->llq_info.descs_num_before_header; } io_sq->tail = 0; io_sq->next_to_comp = 0; io_sq->phase = 1; return 0; } static int ena_com_init_io_cq(struct ena_com_dev *ena_dev, struct ena_com_create_io_ctx *ctx, struct ena_com_io_cq *io_cq) { size_t size; int prev_node = 0; memset(&io_cq->cdesc_addr, 0x0, sizeof(io_cq->cdesc_addr)); /* Use the basic completion descriptor for Rx */ io_cq->cdesc_entry_size_in_bytes = (io_cq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX) ? sizeof(struct ena_eth_io_tx_cdesc) : sizeof(struct ena_eth_io_rx_cdesc_base); size = io_cq->cdesc_entry_size_in_bytes * io_cq->q_depth; prev_node = dev_to_node(ena_dev->dmadev); set_dev_node(ena_dev->dmadev, ctx->numa_node); io_cq->cdesc_addr.virt_addr = dma_zalloc_coherent(ena_dev->dmadev, size, &io_cq->cdesc_addr.phys_addr, GFP_KERNEL); set_dev_node(ena_dev->dmadev, prev_node); if (!io_cq->cdesc_addr.virt_addr) { io_cq->cdesc_addr.virt_addr = dma_zalloc_coherent(ena_dev->dmadev, size, &io_cq->cdesc_addr.phys_addr, GFP_KERNEL); } if (!io_cq->cdesc_addr.virt_addr) { pr_err("memory allocation failed"); return -ENOMEM; } io_cq->phase = 1; io_cq->head = 0; return 0; } static void ena_com_handle_single_admin_completion(struct ena_com_admin_queue *admin_queue, struct ena_admin_acq_entry *cqe) { struct ena_comp_ctx *comp_ctx; u16 cmd_id; cmd_id = cqe->acq_common_descriptor.command & ENA_ADMIN_ACQ_COMMON_DESC_COMMAND_ID_MASK; comp_ctx = get_comp_ctxt(admin_queue, cmd_id, false); if (unlikely(!comp_ctx)) { pr_err("comp_ctx is NULL. Changing the admin queue running state\n"); admin_queue->running_state = false; return; } comp_ctx->status = ENA_CMD_COMPLETED; comp_ctx->comp_status = cqe->acq_common_descriptor.status; if (comp_ctx->user_cqe) memcpy(comp_ctx->user_cqe, (void *)cqe, comp_ctx->comp_size); if (!admin_queue->polling) complete(&comp_ctx->wait_event); } static void ena_com_handle_admin_completion(struct ena_com_admin_queue *admin_queue) { struct ena_admin_acq_entry *cqe = NULL; u16 comp_num = 0; u16 head_masked; u8 phase; head_masked = admin_queue->cq.head & (admin_queue->q_depth - 1); phase = admin_queue->cq.phase; cqe = &admin_queue->cq.entries[head_masked]; /* Go over all the completions */ while ((READ_ONCE(cqe->acq_common_descriptor.flags) & ENA_ADMIN_ACQ_COMMON_DESC_PHASE_MASK) == phase) { /* Do not read the rest of the completion entry before the * phase bit was validated */ dma_rmb(); ena_com_handle_single_admin_completion(admin_queue, cqe); head_masked++; comp_num++; if (unlikely(head_masked == admin_queue->q_depth)) { head_masked = 0; phase = !phase; } cqe = &admin_queue->cq.entries[head_masked]; } admin_queue->cq.head += comp_num; admin_queue->cq.phase = phase; admin_queue->sq.head += comp_num; admin_queue->stats.completed_cmd += comp_num; } static int ena_com_comp_status_to_errno(u8 comp_status) { if (unlikely(comp_status != 0)) pr_err("admin command failed[%u]\n", comp_status); if (unlikely(comp_status > ENA_ADMIN_UNKNOWN_ERROR)) return -EINVAL; switch (comp_status) { case ENA_ADMIN_SUCCESS: return 0; case ENA_ADMIN_RESOURCE_ALLOCATION_FAILURE: return -ENOMEM; case ENA_ADMIN_UNSUPPORTED_OPCODE: return -EOPNOTSUPP; case ENA_ADMIN_BAD_OPCODE: case ENA_ADMIN_MALFORMED_REQUEST: case ENA_ADMIN_ILLEGAL_PARAMETER: case ENA_ADMIN_UNKNOWN_ERROR: return -EINVAL; } return 0; } static int ena_com_wait_and_process_admin_cq_polling(struct ena_comp_ctx *comp_ctx, struct ena_com_admin_queue *admin_queue) { unsigned long flags = 0; unsigned long timeout; int ret; timeout = jiffies + usecs_to_jiffies(admin_queue->completion_timeout); while (1) { spin_lock_irqsave(&admin_queue->q_lock, flags); ena_com_handle_admin_completion(admin_queue); spin_unlock_irqrestore(&admin_queue->q_lock, flags); if (comp_ctx->status != ENA_CMD_SUBMITTED) break; if (time_is_before_jiffies(timeout)) { pr_err("Wait for completion (polling) timeout\n"); /* ENA didn't have any completion */ spin_lock_irqsave(&admin_queue->q_lock, flags); admin_queue->stats.no_completion++; admin_queue->running_state = false; spin_unlock_irqrestore(&admin_queue->q_lock, flags); ret = -ETIME; goto err; } msleep(ENA_POLL_MS); } if (unlikely(comp_ctx->status == ENA_CMD_ABORTED)) { pr_err("Command was aborted\n"); spin_lock_irqsave(&admin_queue->q_lock, flags); admin_queue->stats.aborted_cmd++; spin_unlock_irqrestore(&admin_queue->q_lock, flags); ret = -ENODEV; goto err; } WARN(comp_ctx->status != ENA_CMD_COMPLETED, "Invalid comp status %d\n", comp_ctx->status); ret = ena_com_comp_status_to_errno(comp_ctx->comp_status); err: comp_ctxt_release(admin_queue, comp_ctx); return ret; } /** * Set the LLQ configurations of the firmware * * The driver provides only the enabled feature values to the device, * which in turn, checks if they are supported. */ static int ena_com_set_llq(struct ena_com_dev *ena_dev) { struct ena_com_admin_queue *admin_queue; struct ena_admin_set_feat_cmd cmd; struct ena_admin_set_feat_resp resp; struct ena_com_llq_info *llq_info = &ena_dev->llq_info; int ret; memset(&cmd, 0x0, sizeof(cmd)); admin_queue = &ena_dev->admin_queue; cmd.aq_common_descriptor.opcode = ENA_ADMIN_SET_FEATURE; cmd.feat_common.feature_id = ENA_ADMIN_LLQ; cmd.u.llq.header_location_ctrl_enabled = llq_info->header_location_ctrl; cmd.u.llq.entry_size_ctrl_enabled = llq_info->desc_list_entry_size_ctrl; cmd.u.llq.desc_num_before_header_enabled = llq_info->descs_num_before_header; cmd.u.llq.descriptors_stride_ctrl_enabled = llq_info->desc_stride_ctrl; ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&cmd, sizeof(cmd), (struct ena_admin_acq_entry *)&resp, sizeof(resp)); if (unlikely(ret)) pr_err("Failed to set LLQ configurations: %d\n", ret); return ret; } static int ena_com_config_llq_info(struct ena_com_dev *ena_dev, struct ena_admin_feature_llq_desc *llq_features, struct ena_llq_configurations *llq_default_cfg) { struct ena_com_llq_info *llq_info = &ena_dev->llq_info; u16 supported_feat; int rc; memset(llq_info, 0, sizeof(*llq_info)); supported_feat = llq_features->header_location_ctrl_supported; if (likely(supported_feat & llq_default_cfg->llq_header_location)) { llq_info->header_location_ctrl = llq_default_cfg->llq_header_location; } else { pr_err("Invalid header location control, supported: 0x%x\n", supported_feat); return -EINVAL; } if (likely(llq_info->header_location_ctrl == ENA_ADMIN_INLINE_HEADER)) { supported_feat = llq_features->descriptors_stride_ctrl_supported; if (likely(supported_feat & llq_default_cfg->llq_stride_ctrl)) { llq_info->desc_stride_ctrl = llq_default_cfg->llq_stride_ctrl; } else { if (supported_feat & ENA_ADMIN_MULTIPLE_DESCS_PER_ENTRY) { llq_info->desc_stride_ctrl = ENA_ADMIN_MULTIPLE_DESCS_PER_ENTRY; } else if (supported_feat & ENA_ADMIN_SINGLE_DESC_PER_ENTRY) { llq_info->desc_stride_ctrl = ENA_ADMIN_SINGLE_DESC_PER_ENTRY; } else { pr_err("Invalid desc_stride_ctrl, supported: 0x%x\n", supported_feat); return -EINVAL; } pr_err("Default llq stride ctrl is not supported, performing fallback, default: 0x%x, supported: 0x%x, used: 0x%x\n", llq_default_cfg->llq_stride_ctrl, supported_feat, llq_info->desc_stride_ctrl); } } else { llq_info->desc_stride_ctrl = 0; } supported_feat = llq_features->entry_size_ctrl_supported; if (likely(supported_feat & llq_default_cfg->llq_ring_entry_size)) { llq_info->desc_list_entry_size_ctrl = llq_default_cfg->llq_ring_entry_size; llq_info->desc_list_entry_size = llq_default_cfg->llq_ring_entry_size_value; } else { if (supported_feat & ENA_ADMIN_LIST_ENTRY_SIZE_128B) { llq_info->desc_list_entry_size_ctrl = ENA_ADMIN_LIST_ENTRY_SIZE_128B; llq_info->desc_list_entry_size = 128; } else if (supported_feat & ENA_ADMIN_LIST_ENTRY_SIZE_192B) { llq_info->desc_list_entry_size_ctrl = ENA_ADMIN_LIST_ENTRY_SIZE_192B; llq_info->desc_list_entry_size = 192; } else if (supported_feat & ENA_ADMIN_LIST_ENTRY_SIZE_256B) { llq_info->desc_list_entry_size_ctrl = ENA_ADMIN_LIST_ENTRY_SIZE_256B; llq_info->desc_list_entry_size = 256; } else { pr_err("Invalid entry_size_ctrl, supported: 0x%x\n", supported_feat); return -EINVAL; } pr_err("Default llq ring entry size is not supported, performing fallback, default: 0x%x, supported: 0x%x, used: 0x%x\n", llq_default_cfg->llq_ring_entry_size, supported_feat, llq_info->desc_list_entry_size); } if (unlikely(llq_info->desc_list_entry_size & 0x7)) { /* The desc list entry size should be whole multiply of 8 * This requirement comes from __iowrite64_copy() */ pr_err("illegal entry size %d\n", llq_info->desc_list_entry_size); return -EINVAL; } if (llq_info->desc_stride_ctrl == ENA_ADMIN_MULTIPLE_DESCS_PER_ENTRY) llq_info->descs_per_entry = llq_info->desc_list_entry_size / sizeof(struct ena_eth_io_tx_desc); else llq_info->descs_per_entry = 1; supported_feat = llq_features->desc_num_before_header_supported; if (likely(supported_feat & llq_default_cfg->llq_num_decs_before_header)) { llq_info->descs_num_before_header = llq_default_cfg->llq_num_decs_before_header; } else { if (supported_feat & ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_2) { llq_info->descs_num_before_header = ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_2; } else if (supported_feat & ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_1) { llq_info->descs_num_before_header = ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_1; } else if (supported_feat & ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_4) { llq_info->descs_num_before_header = ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_4; } else if (supported_feat & ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_8) { llq_info->descs_num_before_header = ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_8; } else { pr_err("Invalid descs_num_before_header, supported: 0x%x\n", supported_feat); return -EINVAL; } pr_err("Default llq num descs before header is not supported, performing fallback, default: 0x%x, supported: 0x%x, used: 0x%x\n", llq_default_cfg->llq_num_decs_before_header, supported_feat, llq_info->descs_num_before_header); } rc = ena_com_set_llq(ena_dev); if (rc) pr_err("Cannot set LLQ configuration: %d\n", rc); return 0; } static int ena_com_wait_and_process_admin_cq_interrupts(struct ena_comp_ctx *comp_ctx, struct ena_com_admin_queue *admin_queue) { unsigned long flags = 0; int ret; wait_for_completion_timeout(&comp_ctx->wait_event, usecs_to_jiffies( admin_queue->completion_timeout)); /* In case the command wasn't completed find out the root cause. * There might be 2 kinds of errors * 1) No completion (timeout reached) * 2) There is completion but the device didn't get any msi-x interrupt. */ if (unlikely(comp_ctx->status == ENA_CMD_SUBMITTED)) { spin_lock_irqsave(&admin_queue->q_lock, flags); ena_com_handle_admin_completion(admin_queue); admin_queue->stats.no_completion++; spin_unlock_irqrestore(&admin_queue->q_lock, flags); if (comp_ctx->status == ENA_CMD_COMPLETED) pr_err("The ena device have completion but the driver didn't receive any MSI-X interrupt (cmd %d)\n", comp_ctx->cmd_opcode); else pr_err("The ena device doesn't send any completion for the admin cmd %d status %d\n", comp_ctx->cmd_opcode, comp_ctx->status); admin_queue->running_state = false; ret = -ETIME; goto err; } ret = ena_com_comp_status_to_errno(comp_ctx->comp_status); err: comp_ctxt_release(admin_queue, comp_ctx); return ret; } /* This method read the hardware device register through posting writes * and waiting for response * On timeout the function will return ENA_MMIO_READ_TIMEOUT */ static u32 ena_com_reg_bar_read32(struct ena_com_dev *ena_dev, u16 offset) { struct ena_com_mmio_read *mmio_read = &ena_dev->mmio_read; volatile struct ena_admin_ena_mmio_req_read_less_resp *read_resp = mmio_read->read_resp; u32 mmio_read_reg, ret, i; unsigned long flags = 0; u32 timeout = mmio_read->reg_read_to; might_sleep(); if (timeout == 0) timeout = ENA_REG_READ_TIMEOUT; /* If readless is disabled, perform regular read */ if (!mmio_read->readless_supported) return readl(ena_dev->reg_bar + offset); spin_lock_irqsave(&mmio_read->lock, flags); mmio_read->seq_num++; read_resp->req_id = mmio_read->seq_num + 0xDEAD; mmio_read_reg = (offset << ENA_REGS_MMIO_REG_READ_REG_OFF_SHIFT) & ENA_REGS_MMIO_REG_READ_REG_OFF_MASK; mmio_read_reg |= mmio_read->seq_num & ENA_REGS_MMIO_REG_READ_REQ_ID_MASK; writel(mmio_read_reg, ena_dev->reg_bar + ENA_REGS_MMIO_REG_READ_OFF); for (i = 0; i < timeout; i++) { if (READ_ONCE(read_resp->req_id) == mmio_read->seq_num) break; udelay(1); } if (unlikely(i == timeout)) { pr_err("reading reg failed for timeout. expected: req id[%hu] offset[%hu] actual: req id[%hu] offset[%hu]\n", mmio_read->seq_num, offset, read_resp->req_id, read_resp->reg_off); ret = ENA_MMIO_READ_TIMEOUT; goto err; } if (read_resp->reg_off != offset) { pr_err("Read failure: wrong offset provided"); ret = ENA_MMIO_READ_TIMEOUT; } else { ret = read_resp->reg_val; } err: spin_unlock_irqrestore(&mmio_read->lock, flags); return ret; } /* There are two types to wait for completion. * Polling mode - wait until the completion is available. * Async mode - wait on wait queue until the completion is ready * (or the timeout expired). * It is expected that the IRQ called ena_com_handle_admin_completion * to mark the completions. */ static int ena_com_wait_and_process_admin_cq(struct ena_comp_ctx *comp_ctx, struct ena_com_admin_queue *admin_queue) { if (admin_queue->polling) return ena_com_wait_and_process_admin_cq_polling(comp_ctx, admin_queue); return ena_com_wait_and_process_admin_cq_interrupts(comp_ctx, admin_queue); } static int ena_com_destroy_io_sq(struct ena_com_dev *ena_dev, struct ena_com_io_sq *io_sq) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; struct ena_admin_aq_destroy_sq_cmd destroy_cmd; struct ena_admin_acq_destroy_sq_resp_desc destroy_resp; u8 direction; int ret; memset(&destroy_cmd, 0x0, sizeof(destroy_cmd)); if (io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX) direction = ENA_ADMIN_SQ_DIRECTION_TX; else direction = ENA_ADMIN_SQ_DIRECTION_RX; destroy_cmd.sq.sq_identity |= (direction << ENA_ADMIN_SQ_SQ_DIRECTION_SHIFT) & ENA_ADMIN_SQ_SQ_DIRECTION_MASK; destroy_cmd.sq.sq_idx = io_sq->idx; destroy_cmd.aq_common_descriptor.opcode = ENA_ADMIN_DESTROY_SQ; ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&destroy_cmd, sizeof(destroy_cmd), (struct ena_admin_acq_entry *)&destroy_resp, sizeof(destroy_resp)); if (unlikely(ret && (ret != -ENODEV))) pr_err("failed to destroy io sq error: %d\n", ret); return ret; } static void ena_com_io_queue_free(struct ena_com_dev *ena_dev, struct ena_com_io_sq *io_sq, struct ena_com_io_cq *io_cq) { size_t size; if (io_cq->cdesc_addr.virt_addr) { size = io_cq->cdesc_entry_size_in_bytes * io_cq->q_depth; dma_free_coherent(ena_dev->dmadev, size, io_cq->cdesc_addr.virt_addr, io_cq->cdesc_addr.phys_addr); io_cq->cdesc_addr.virt_addr = NULL; } if (io_sq->desc_addr.virt_addr) { size = io_sq->desc_entry_size * io_sq->q_depth; dma_free_coherent(ena_dev->dmadev, size, io_sq->desc_addr.virt_addr, io_sq->desc_addr.phys_addr); io_sq->desc_addr.virt_addr = NULL; } if (io_sq->bounce_buf_ctrl.base_buffer) { devm_kfree(ena_dev->dmadev, io_sq->bounce_buf_ctrl.base_buffer); io_sq->bounce_buf_ctrl.base_buffer = NULL; } } static int wait_for_reset_state(struct ena_com_dev *ena_dev, u32 timeout, u16 exp_state) { u32 val, i; /* Convert timeout from resolution of 100ms to ENA_POLL_MS */ timeout = (timeout * 100) / ENA_POLL_MS; for (i = 0; i < timeout; i++) { val = ena_com_reg_bar_read32(ena_dev, ENA_REGS_DEV_STS_OFF); if (unlikely(val == ENA_MMIO_READ_TIMEOUT)) { pr_err("Reg read timeout occurred\n"); return -ETIME; } if ((val & ENA_REGS_DEV_STS_RESET_IN_PROGRESS_MASK) == exp_state) return 0; msleep(ENA_POLL_MS); } return -ETIME; } static bool ena_com_check_supported_feature_id(struct ena_com_dev *ena_dev, enum ena_admin_aq_feature_id feature_id) { u32 feature_mask = 1 << feature_id; /* Device attributes is always supported */ if ((feature_id != ENA_ADMIN_DEVICE_ATTRIBUTES) && !(ena_dev->supported_features & feature_mask)) return false; return true; } static int ena_com_get_feature_ex(struct ena_com_dev *ena_dev, struct ena_admin_get_feat_resp *get_resp, enum ena_admin_aq_feature_id feature_id, dma_addr_t control_buf_dma_addr, u32 control_buff_size) { struct ena_com_admin_queue *admin_queue; struct ena_admin_get_feat_cmd get_cmd; int ret; if (!ena_com_check_supported_feature_id(ena_dev, feature_id)) { pr_debug("Feature %d isn't supported\n", feature_id); return -EOPNOTSUPP; } memset(&get_cmd, 0x0, sizeof(get_cmd)); admin_queue = &ena_dev->admin_queue; get_cmd.aq_common_descriptor.opcode = ENA_ADMIN_GET_FEATURE; if (control_buff_size) get_cmd.aq_common_descriptor.flags = ENA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK; else get_cmd.aq_common_descriptor.flags = 0; ret = ena_com_mem_addr_set(ena_dev, &get_cmd.control_buffer.address, control_buf_dma_addr); if (unlikely(ret)) { pr_err("memory address set failed\n"); return ret; } get_cmd.control_buffer.length = control_buff_size; get_cmd.feat_common.feature_id = feature_id; ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *) &get_cmd, sizeof(get_cmd), (struct ena_admin_acq_entry *) get_resp, sizeof(*get_resp)); if (unlikely(ret)) pr_err("Failed to submit get_feature command %d error: %d\n", feature_id, ret); return ret; } static int ena_com_get_feature(struct ena_com_dev *ena_dev, struct ena_admin_get_feat_resp *get_resp, enum ena_admin_aq_feature_id feature_id) { return ena_com_get_feature_ex(ena_dev, get_resp, feature_id, 0, 0); } static int ena_com_hash_key_allocate(struct ena_com_dev *ena_dev) { struct ena_rss *rss = &ena_dev->rss; rss->hash_key = dma_zalloc_coherent(ena_dev->dmadev, sizeof(*rss->hash_key), &rss->hash_key_dma_addr, GFP_KERNEL); if (unlikely(!rss->hash_key)) return -ENOMEM; return 0; } static void ena_com_hash_key_destroy(struct ena_com_dev *ena_dev) { struct ena_rss *rss = &ena_dev->rss; if (rss->hash_key) dma_free_coherent(ena_dev->dmadev, sizeof(*rss->hash_key), rss->hash_key, rss->hash_key_dma_addr); rss->hash_key = NULL; } static int ena_com_hash_ctrl_init(struct ena_com_dev *ena_dev) { struct ena_rss *rss = &ena_dev->rss; rss->hash_ctrl = dma_zalloc_coherent(ena_dev->dmadev, sizeof(*rss->hash_ctrl), &rss->hash_ctrl_dma_addr, GFP_KERNEL); if (unlikely(!rss->hash_ctrl)) return -ENOMEM; return 0; } static void ena_com_hash_ctrl_destroy(struct ena_com_dev *ena_dev) { struct ena_rss *rss = &ena_dev->rss; if (rss->hash_ctrl) dma_free_coherent(ena_dev->dmadev, sizeof(*rss->hash_ctrl), rss->hash_ctrl, rss->hash_ctrl_dma_addr); rss->hash_ctrl = NULL; } static int ena_com_indirect_table_allocate(struct ena_com_dev *ena_dev, u16 log_size) { struct ena_rss *rss = &ena_dev->rss; struct ena_admin_get_feat_resp get_resp; size_t tbl_size; int ret; ret = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG); if (unlikely(ret)) return ret; if ((get_resp.u.ind_table.min_size > log_size) || (get_resp.u.ind_table.max_size < log_size)) { pr_err("indirect table size doesn't fit. requested size: %d while min is:%d and max %d\n", 1 << log_size, 1 << get_resp.u.ind_table.min_size, 1 << get_resp.u.ind_table.max_size); return -EINVAL; } tbl_size = (1ULL << log_size) * sizeof(struct ena_admin_rss_ind_table_entry); rss->rss_ind_tbl = dma_zalloc_coherent(ena_dev->dmadev, tbl_size, &rss->rss_ind_tbl_dma_addr, GFP_KERNEL); if (unlikely(!rss->rss_ind_tbl)) goto mem_err1; tbl_size = (1ULL << log_size) * sizeof(u16); rss->host_rss_ind_tbl = devm_kzalloc(ena_dev->dmadev, tbl_size, GFP_KERNEL); if (unlikely(!rss->host_rss_ind_tbl)) goto mem_err2; rss->tbl_log_size = log_size; return 0; mem_err2: tbl_size = (1ULL << log_size) * sizeof(struct ena_admin_rss_ind_table_entry); dma_free_coherent(ena_dev->dmadev, tbl_size, rss->rss_ind_tbl, rss->rss_ind_tbl_dma_addr); rss->rss_ind_tbl = NULL; mem_err1: rss->tbl_log_size = 0; return -ENOMEM; } static void ena_com_indirect_table_destroy(struct ena_com_dev *ena_dev) { struct ena_rss *rss = &ena_dev->rss; size_t tbl_size = (1ULL << rss->tbl_log_size) * sizeof(struct ena_admin_rss_ind_table_entry); if (rss->rss_ind_tbl) dma_free_coherent(ena_dev->dmadev, tbl_size, rss->rss_ind_tbl, rss->rss_ind_tbl_dma_addr); rss->rss_ind_tbl = NULL; if (rss->host_rss_ind_tbl) devm_kfree(ena_dev->dmadev, rss->host_rss_ind_tbl); rss->host_rss_ind_tbl = NULL; } static int ena_com_create_io_sq(struct ena_com_dev *ena_dev, struct ena_com_io_sq *io_sq, u16 cq_idx) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; struct ena_admin_aq_create_sq_cmd create_cmd; struct ena_admin_acq_create_sq_resp_desc cmd_completion; u8 direction; int ret; memset(&create_cmd, 0x0, sizeof(create_cmd)); create_cmd.aq_common_descriptor.opcode = ENA_ADMIN_CREATE_SQ; if (io_sq->direction == ENA_COM_IO_QUEUE_DIRECTION_TX) direction = ENA_ADMIN_SQ_DIRECTION_TX; else direction = ENA_ADMIN_SQ_DIRECTION_RX; create_cmd.sq_identity |= (direction << ENA_ADMIN_AQ_CREATE_SQ_CMD_SQ_DIRECTION_SHIFT) & ENA_ADMIN_AQ_CREATE_SQ_CMD_SQ_DIRECTION_MASK; create_cmd.sq_caps_2 |= io_sq->mem_queue_type & ENA_ADMIN_AQ_CREATE_SQ_CMD_PLACEMENT_POLICY_MASK; create_cmd.sq_caps_2 |= (ENA_ADMIN_COMPLETION_POLICY_DESC << ENA_ADMIN_AQ_CREATE_SQ_CMD_COMPLETION_POLICY_SHIFT) & ENA_ADMIN_AQ_CREATE_SQ_CMD_COMPLETION_POLICY_MASK; create_cmd.sq_caps_3 |= ENA_ADMIN_AQ_CREATE_SQ_CMD_IS_PHYSICALLY_CONTIGUOUS_MASK; create_cmd.cq_idx = cq_idx; create_cmd.sq_depth = io_sq->q_depth; if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST) { ret = ena_com_mem_addr_set(ena_dev, &create_cmd.sq_ba, io_sq->desc_addr.phys_addr); if (unlikely(ret)) { pr_err("memory address set failed\n"); return ret; } } ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&create_cmd, sizeof(create_cmd), (struct ena_admin_acq_entry *)&cmd_completion, sizeof(cmd_completion)); if (unlikely(ret)) { pr_err("Failed to create IO SQ. error: %d\n", ret); return ret; } io_sq->idx = cmd_completion.sq_idx; io_sq->db_addr = (u32 __iomem *)((uintptr_t)ena_dev->reg_bar + (uintptr_t)cmd_completion.sq_doorbell_offset); if (io_sq->mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV) { io_sq->header_addr = (u8 __iomem *)((uintptr_t)ena_dev->mem_bar + cmd_completion.llq_headers_offset); io_sq->desc_addr.pbuf_dev_addr = (u8 __iomem *)((uintptr_t)ena_dev->mem_bar + cmd_completion.llq_descriptors_offset); } pr_debug("created sq[%u], depth[%u]\n", io_sq->idx, io_sq->q_depth); return ret; } static int ena_com_ind_tbl_convert_to_device(struct ena_com_dev *ena_dev) { struct ena_rss *rss = &ena_dev->rss; struct ena_com_io_sq *io_sq; u16 qid; int i; for (i = 0; i < 1 << rss->tbl_log_size; i++) { qid = rss->host_rss_ind_tbl[i]; if (qid >= ENA_TOTAL_NUM_QUEUES) return -EINVAL; io_sq = &ena_dev->io_sq_queues[qid]; if (io_sq->direction != ENA_COM_IO_QUEUE_DIRECTION_RX) return -EINVAL; rss->rss_ind_tbl[i].cq_idx = io_sq->idx; } return 0; } static int ena_com_ind_tbl_convert_from_device(struct ena_com_dev *ena_dev) { u16 dev_idx_to_host_tbl[ENA_TOTAL_NUM_QUEUES] = { (u16)-1 }; struct ena_rss *rss = &ena_dev->rss; u8 idx; u16 i; for (i = 0; i < ENA_TOTAL_NUM_QUEUES; i++) dev_idx_to_host_tbl[ena_dev->io_sq_queues[i].idx] = i; for (i = 0; i < 1 << rss->tbl_log_size; i++) { if (rss->rss_ind_tbl[i].cq_idx > ENA_TOTAL_NUM_QUEUES) return -EINVAL; idx = (u8)rss->rss_ind_tbl[i].cq_idx; if (dev_idx_to_host_tbl[idx] > ENA_TOTAL_NUM_QUEUES) return -EINVAL; rss->host_rss_ind_tbl[i] = dev_idx_to_host_tbl[idx]; } return 0; } static int ena_com_init_interrupt_moderation_table(struct ena_com_dev *ena_dev) { size_t size; size = sizeof(struct ena_intr_moder_entry) * ENA_INTR_MAX_NUM_OF_LEVELS; ena_dev->intr_moder_tbl = devm_kzalloc(ena_dev->dmadev, size, GFP_KERNEL); if (!ena_dev->intr_moder_tbl) return -ENOMEM; ena_com_config_default_interrupt_moderation_table(ena_dev); return 0; } static void ena_com_update_intr_delay_resolution(struct ena_com_dev *ena_dev, u16 intr_delay_resolution) { struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl; unsigned int i; if (!intr_delay_resolution) { pr_err("Illegal intr_delay_resolution provided. Going to use default 1 usec resolution\n"); intr_delay_resolution = 1; } ena_dev->intr_delay_resolution = intr_delay_resolution; /* update Rx */ for (i = 0; i < ENA_INTR_MAX_NUM_OF_LEVELS; i++) intr_moder_tbl[i].intr_moder_interval /= intr_delay_resolution; /* update Tx */ ena_dev->intr_moder_tx_interval /= intr_delay_resolution; } /*****************************************************************************/ /******************************* API ******************************/ /*****************************************************************************/ int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue, struct ena_admin_aq_entry *cmd, size_t cmd_size, struct ena_admin_acq_entry *comp, size_t comp_size) { struct ena_comp_ctx *comp_ctx; int ret; comp_ctx = ena_com_submit_admin_cmd(admin_queue, cmd, cmd_size, comp, comp_size); if (IS_ERR(comp_ctx)) { if (comp_ctx == ERR_PTR(-ENODEV)) pr_debug("Failed to submit command [%ld]\n", PTR_ERR(comp_ctx)); else pr_err("Failed to submit command [%ld]\n", PTR_ERR(comp_ctx)); return PTR_ERR(comp_ctx); } ret = ena_com_wait_and_process_admin_cq(comp_ctx, admin_queue); if (unlikely(ret)) { if (admin_queue->running_state) pr_err("Failed to process command. ret = %d\n", ret); else pr_debug("Failed to process command. ret = %d\n", ret); } return ret; } int ena_com_create_io_cq(struct ena_com_dev *ena_dev, struct ena_com_io_cq *io_cq) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; struct ena_admin_aq_create_cq_cmd create_cmd; struct ena_admin_acq_create_cq_resp_desc cmd_completion; int ret; memset(&create_cmd, 0x0, sizeof(create_cmd)); create_cmd.aq_common_descriptor.opcode = ENA_ADMIN_CREATE_CQ; create_cmd.cq_caps_2 |= (io_cq->cdesc_entry_size_in_bytes / 4) & ENA_ADMIN_AQ_CREATE_CQ_CMD_CQ_ENTRY_SIZE_WORDS_MASK; create_cmd.cq_caps_1 |= ENA_ADMIN_AQ_CREATE_CQ_CMD_INTERRUPT_MODE_ENABLED_MASK; create_cmd.msix_vector = io_cq->msix_vector; create_cmd.cq_depth = io_cq->q_depth; ret = ena_com_mem_addr_set(ena_dev, &create_cmd.cq_ba, io_cq->cdesc_addr.phys_addr); if (unlikely(ret)) { pr_err("memory address set failed\n"); return ret; } ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&create_cmd, sizeof(create_cmd), (struct ena_admin_acq_entry *)&cmd_completion, sizeof(cmd_completion)); if (unlikely(ret)) { pr_err("Failed to create IO CQ. error: %d\n", ret); return ret; } io_cq->idx = cmd_completion.cq_idx; io_cq->unmask_reg = (u32 __iomem *)((uintptr_t)ena_dev->reg_bar + cmd_completion.cq_interrupt_unmask_register_offset); if (cmd_completion.cq_head_db_register_offset) io_cq->cq_head_db_reg = (u32 __iomem *)((uintptr_t)ena_dev->reg_bar + cmd_completion.cq_head_db_register_offset); if (cmd_completion.numa_node_register_offset) io_cq->numa_node_cfg_reg = (u32 __iomem *)((uintptr_t)ena_dev->reg_bar + cmd_completion.numa_node_register_offset); pr_debug("created cq[%u], depth[%u]\n", io_cq->idx, io_cq->q_depth); return ret; } int ena_com_get_io_handlers(struct ena_com_dev *ena_dev, u16 qid, struct ena_com_io_sq **io_sq, struct ena_com_io_cq **io_cq) { if (qid >= ENA_TOTAL_NUM_QUEUES) { pr_err("Invalid queue number %d but the max is %d\n", qid, ENA_TOTAL_NUM_QUEUES); return -EINVAL; } *io_sq = &ena_dev->io_sq_queues[qid]; *io_cq = &ena_dev->io_cq_queues[qid]; return 0; } void ena_com_abort_admin_commands(struct ena_com_dev *ena_dev) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; struct ena_comp_ctx *comp_ctx; u16 i; if (!admin_queue->comp_ctx) return; for (i = 0; i < admin_queue->q_depth; i++) { comp_ctx = get_comp_ctxt(admin_queue, i, false); if (unlikely(!comp_ctx)) break; comp_ctx->status = ENA_CMD_ABORTED; complete(&comp_ctx->wait_event); } } void ena_com_wait_for_abort_completion(struct ena_com_dev *ena_dev) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; unsigned long flags = 0; spin_lock_irqsave(&admin_queue->q_lock, flags); while (atomic_read(&admin_queue->outstanding_cmds) != 0) { spin_unlock_irqrestore(&admin_queue->q_lock, flags); msleep(ENA_POLL_MS); spin_lock_irqsave(&admin_queue->q_lock, flags); } spin_unlock_irqrestore(&admin_queue->q_lock, flags); } int ena_com_destroy_io_cq(struct ena_com_dev *ena_dev, struct ena_com_io_cq *io_cq) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; struct ena_admin_aq_destroy_cq_cmd destroy_cmd; struct ena_admin_acq_destroy_cq_resp_desc destroy_resp; int ret; memset(&destroy_cmd, 0x0, sizeof(destroy_cmd)); destroy_cmd.cq_idx = io_cq->idx; destroy_cmd.aq_common_descriptor.opcode = ENA_ADMIN_DESTROY_CQ; ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&destroy_cmd, sizeof(destroy_cmd), (struct ena_admin_acq_entry *)&destroy_resp, sizeof(destroy_resp)); if (unlikely(ret && (ret != -ENODEV))) pr_err("Failed to destroy IO CQ. error: %d\n", ret); return ret; } bool ena_com_get_admin_running_state(struct ena_com_dev *ena_dev) { return ena_dev->admin_queue.running_state; } void ena_com_set_admin_running_state(struct ena_com_dev *ena_dev, bool state) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; unsigned long flags = 0; spin_lock_irqsave(&admin_queue->q_lock, flags); ena_dev->admin_queue.running_state = state; spin_unlock_irqrestore(&admin_queue->q_lock, flags); } void ena_com_admin_aenq_enable(struct ena_com_dev *ena_dev) { u16 depth = ena_dev->aenq.q_depth; WARN(ena_dev->aenq.head != depth, "Invalid AENQ state\n"); /* Init head_db to mark that all entries in the queue * are initially available */ writel(depth, ena_dev->reg_bar + ENA_REGS_AENQ_HEAD_DB_OFF); } int ena_com_set_aenq_config(struct ena_com_dev *ena_dev, u32 groups_flag) { struct ena_com_admin_queue *admin_queue; struct ena_admin_set_feat_cmd cmd; struct ena_admin_set_feat_resp resp; struct ena_admin_get_feat_resp get_resp; int ret; ret = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_AENQ_CONFIG); if (ret) { pr_info("Can't get aenq configuration\n"); return ret; } if ((get_resp.u.aenq.supported_groups & groups_flag) != groups_flag) { pr_warn("Trying to set unsupported aenq events. supported flag: 0x%x asked flag: 0x%x\n", get_resp.u.aenq.supported_groups, groups_flag); return -EOPNOTSUPP; } memset(&cmd, 0x0, sizeof(cmd)); admin_queue = &ena_dev->admin_queue; cmd.aq_common_descriptor.opcode = ENA_ADMIN_SET_FEATURE; cmd.aq_common_descriptor.flags = 0; cmd.feat_common.feature_id = ENA_ADMIN_AENQ_CONFIG; cmd.u.aenq.enabled_groups = groups_flag; ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&cmd, sizeof(cmd), (struct ena_admin_acq_entry *)&resp, sizeof(resp)); if (unlikely(ret)) pr_err("Failed to config AENQ ret: %d\n", ret); return ret; } int ena_com_get_dma_width(struct ena_com_dev *ena_dev) { u32 caps = ena_com_reg_bar_read32(ena_dev, ENA_REGS_CAPS_OFF); int width; if (unlikely(caps == ENA_MMIO_READ_TIMEOUT)) { pr_err("Reg read timeout occurred\n"); return -ETIME; } width = (caps & ENA_REGS_CAPS_DMA_ADDR_WIDTH_MASK) >> ENA_REGS_CAPS_DMA_ADDR_WIDTH_SHIFT; pr_debug("ENA dma width: %d\n", width); if ((width < 32) || width > ENA_MAX_PHYS_ADDR_SIZE_BITS) { pr_err("DMA width illegal value: %d\n", width); return -EINVAL; } ena_dev->dma_addr_bits = width; return width; } int ena_com_validate_version(struct ena_com_dev *ena_dev) { u32 ver; u32 ctrl_ver; u32 ctrl_ver_masked; /* Make sure the ENA version and the controller version are at least * as the driver expects */ ver = ena_com_reg_bar_read32(ena_dev, ENA_REGS_VERSION_OFF); ctrl_ver = ena_com_reg_bar_read32(ena_dev, ENA_REGS_CONTROLLER_VERSION_OFF); if (unlikely((ver == ENA_MMIO_READ_TIMEOUT) || (ctrl_ver == ENA_MMIO_READ_TIMEOUT))) { pr_err("Reg read timeout occurred\n"); return -ETIME; } pr_info("ena device version: %d.%d\n", (ver & ENA_REGS_VERSION_MAJOR_VERSION_MASK) >> ENA_REGS_VERSION_MAJOR_VERSION_SHIFT, ver & ENA_REGS_VERSION_MINOR_VERSION_MASK); pr_info("ena controller version: %d.%d.%d implementation version %d\n", (ctrl_ver & ENA_REGS_CONTROLLER_VERSION_MAJOR_VERSION_MASK) >> ENA_REGS_CONTROLLER_VERSION_MAJOR_VERSION_SHIFT, (ctrl_ver & ENA_REGS_CONTROLLER_VERSION_MINOR_VERSION_MASK) >> ENA_REGS_CONTROLLER_VERSION_MINOR_VERSION_SHIFT, (ctrl_ver & ENA_REGS_CONTROLLER_VERSION_SUBMINOR_VERSION_MASK), (ctrl_ver & ENA_REGS_CONTROLLER_VERSION_IMPL_ID_MASK) >> ENA_REGS_CONTROLLER_VERSION_IMPL_ID_SHIFT); ctrl_ver_masked = (ctrl_ver & ENA_REGS_CONTROLLER_VERSION_MAJOR_VERSION_MASK) | (ctrl_ver & ENA_REGS_CONTROLLER_VERSION_MINOR_VERSION_MASK) | (ctrl_ver & ENA_REGS_CONTROLLER_VERSION_SUBMINOR_VERSION_MASK); /* Validate the ctrl version without the implementation ID */ if (ctrl_ver_masked < MIN_ENA_CTRL_VER) { pr_err("ENA ctrl version is lower than the minimal ctrl version the driver supports\n"); return -1; } return 0; } void ena_com_admin_destroy(struct ena_com_dev *ena_dev) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; struct ena_com_admin_cq *cq = &admin_queue->cq; struct ena_com_admin_sq *sq = &admin_queue->sq; struct ena_com_aenq *aenq = &ena_dev->aenq; u16 size; if (admin_queue->comp_ctx) devm_kfree(ena_dev->dmadev, admin_queue->comp_ctx); admin_queue->comp_ctx = NULL; size = ADMIN_SQ_SIZE(admin_queue->q_depth); if (sq->entries) dma_free_coherent(ena_dev->dmadev, size, sq->entries, sq->dma_addr); sq->entries = NULL; size = ADMIN_CQ_SIZE(admin_queue->q_depth); if (cq->entries) dma_free_coherent(ena_dev->dmadev, size, cq->entries, cq->dma_addr); cq->entries = NULL; size = ADMIN_AENQ_SIZE(aenq->q_depth); if (ena_dev->aenq.entries) dma_free_coherent(ena_dev->dmadev, size, aenq->entries, aenq->dma_addr); aenq->entries = NULL; } void ena_com_set_admin_polling_mode(struct ena_com_dev *ena_dev, bool polling) { u32 mask_value = 0; if (polling) mask_value = ENA_REGS_ADMIN_INTR_MASK; writel(mask_value, ena_dev->reg_bar + ENA_REGS_INTR_MASK_OFF); ena_dev->admin_queue.polling = polling; } int ena_com_mmio_reg_read_request_init(struct ena_com_dev *ena_dev) { struct ena_com_mmio_read *mmio_read = &ena_dev->mmio_read; spin_lock_init(&mmio_read->lock); mmio_read->read_resp = dma_zalloc_coherent(ena_dev->dmadev, sizeof(*mmio_read->read_resp), &mmio_read->read_resp_dma_addr, GFP_KERNEL); if (unlikely(!mmio_read->read_resp)) goto err; ena_com_mmio_reg_read_request_write_dev_addr(ena_dev); mmio_read->read_resp->req_id = 0x0; mmio_read->seq_num = 0x0; mmio_read->readless_supported = true; return 0; err: return -ENOMEM; } void ena_com_set_mmio_read_mode(struct ena_com_dev *ena_dev, bool readless_supported) { struct ena_com_mmio_read *mmio_read = &ena_dev->mmio_read; mmio_read->readless_supported = readless_supported; } void ena_com_mmio_reg_read_request_destroy(struct ena_com_dev *ena_dev) { struct ena_com_mmio_read *mmio_read = &ena_dev->mmio_read; writel(0x0, ena_dev->reg_bar + ENA_REGS_MMIO_RESP_LO_OFF); writel(0x0, ena_dev->reg_bar + ENA_REGS_MMIO_RESP_HI_OFF); dma_free_coherent(ena_dev->dmadev, sizeof(*mmio_read->read_resp), mmio_read->read_resp, mmio_read->read_resp_dma_addr); mmio_read->read_resp = NULL; } void ena_com_mmio_reg_read_request_write_dev_addr(struct ena_com_dev *ena_dev) { struct ena_com_mmio_read *mmio_read = &ena_dev->mmio_read; u32 addr_low, addr_high; addr_low = ENA_DMA_ADDR_TO_UINT32_LOW(mmio_read->read_resp_dma_addr); addr_high = ENA_DMA_ADDR_TO_UINT32_HIGH(mmio_read->read_resp_dma_addr); writel(addr_low, ena_dev->reg_bar + ENA_REGS_MMIO_RESP_LO_OFF); writel(addr_high, ena_dev->reg_bar + ENA_REGS_MMIO_RESP_HI_OFF); } int ena_com_admin_init(struct ena_com_dev *ena_dev, struct ena_aenq_handlers *aenq_handlers) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; u32 aq_caps, acq_caps, dev_sts, addr_low, addr_high; int ret; dev_sts = ena_com_reg_bar_read32(ena_dev, ENA_REGS_DEV_STS_OFF); if (unlikely(dev_sts == ENA_MMIO_READ_TIMEOUT)) { pr_err("Reg read timeout occurred\n"); return -ETIME; } if (!(dev_sts & ENA_REGS_DEV_STS_READY_MASK)) { pr_err("Device isn't ready, abort com init\n"); return -ENODEV; } admin_queue->q_depth = ENA_ADMIN_QUEUE_DEPTH; admin_queue->q_dmadev = ena_dev->dmadev; admin_queue->polling = false; admin_queue->curr_cmd_id = 0; atomic_set(&admin_queue->outstanding_cmds, 0); spin_lock_init(&admin_queue->q_lock); ret = ena_com_init_comp_ctxt(admin_queue); if (ret) goto error; ret = ena_com_admin_init_sq(admin_queue); if (ret) goto error; ret = ena_com_admin_init_cq(admin_queue); if (ret) goto error; admin_queue->sq.db_addr = (u32 __iomem *)((uintptr_t)ena_dev->reg_bar + ENA_REGS_AQ_DB_OFF); addr_low = ENA_DMA_ADDR_TO_UINT32_LOW(admin_queue->sq.dma_addr); addr_high = ENA_DMA_ADDR_TO_UINT32_HIGH(admin_queue->sq.dma_addr); writel(addr_low, ena_dev->reg_bar + ENA_REGS_AQ_BASE_LO_OFF); writel(addr_high, ena_dev->reg_bar + ENA_REGS_AQ_BASE_HI_OFF); addr_low = ENA_DMA_ADDR_TO_UINT32_LOW(admin_queue->cq.dma_addr); addr_high = ENA_DMA_ADDR_TO_UINT32_HIGH(admin_queue->cq.dma_addr); writel(addr_low, ena_dev->reg_bar + ENA_REGS_ACQ_BASE_LO_OFF); writel(addr_high, ena_dev->reg_bar + ENA_REGS_ACQ_BASE_HI_OFF); aq_caps = 0; aq_caps |= admin_queue->q_depth & ENA_REGS_AQ_CAPS_AQ_DEPTH_MASK; aq_caps |= (sizeof(struct ena_admin_aq_entry) << ENA_REGS_AQ_CAPS_AQ_ENTRY_SIZE_SHIFT) & ENA_REGS_AQ_CAPS_AQ_ENTRY_SIZE_MASK; acq_caps = 0; acq_caps |= admin_queue->q_depth & ENA_REGS_ACQ_CAPS_ACQ_DEPTH_MASK; acq_caps |= (sizeof(struct ena_admin_acq_entry) << ENA_REGS_ACQ_CAPS_ACQ_ENTRY_SIZE_SHIFT) & ENA_REGS_ACQ_CAPS_ACQ_ENTRY_SIZE_MASK; writel(aq_caps, ena_dev->reg_bar + ENA_REGS_AQ_CAPS_OFF); writel(acq_caps, ena_dev->reg_bar + ENA_REGS_ACQ_CAPS_OFF); ret = ena_com_admin_init_aenq(ena_dev, aenq_handlers); if (ret) goto error; admin_queue->running_state = true; return 0; error: ena_com_admin_destroy(ena_dev); return ret; } int ena_com_create_io_queue(struct ena_com_dev *ena_dev, struct ena_com_create_io_ctx *ctx) { struct ena_com_io_sq *io_sq; struct ena_com_io_cq *io_cq; int ret; if (ctx->qid >= ENA_TOTAL_NUM_QUEUES) { pr_err("Qid (%d) is bigger than max num of queues (%d)\n", ctx->qid, ENA_TOTAL_NUM_QUEUES); return -EINVAL; } io_sq = &ena_dev->io_sq_queues[ctx->qid]; io_cq = &ena_dev->io_cq_queues[ctx->qid]; memset(io_sq, 0x0, sizeof(*io_sq)); memset(io_cq, 0x0, sizeof(*io_cq)); /* Init CQ */ io_cq->q_depth = ctx->queue_size; io_cq->direction = ctx->direction; io_cq->qid = ctx->qid; io_cq->msix_vector = ctx->msix_vector; io_sq->q_depth = ctx->queue_size; io_sq->direction = ctx->direction; io_sq->qid = ctx->qid; io_sq->mem_queue_type = ctx->mem_queue_type; if (ctx->direction == ENA_COM_IO_QUEUE_DIRECTION_TX) /* header length is limited to 8 bits */ io_sq->tx_max_header_size = min_t(u32, ena_dev->tx_max_header_size, SZ_256); ret = ena_com_init_io_sq(ena_dev, ctx, io_sq); if (ret) goto error; ret = ena_com_init_io_cq(ena_dev, ctx, io_cq); if (ret) goto error; ret = ena_com_create_io_cq(ena_dev, io_cq); if (ret) goto error; ret = ena_com_create_io_sq(ena_dev, io_sq, io_cq->idx); if (ret) goto destroy_io_cq; return 0; destroy_io_cq: ena_com_destroy_io_cq(ena_dev, io_cq); error: ena_com_io_queue_free(ena_dev, io_sq, io_cq); return ret; } void ena_com_destroy_io_queue(struct ena_com_dev *ena_dev, u16 qid) { struct ena_com_io_sq *io_sq; struct ena_com_io_cq *io_cq; if (qid >= ENA_TOTAL_NUM_QUEUES) { pr_err("Qid (%d) is bigger than max num of queues (%d)\n", qid, ENA_TOTAL_NUM_QUEUES); return; } io_sq = &ena_dev->io_sq_queues[qid]; io_cq = &ena_dev->io_cq_queues[qid]; ena_com_destroy_io_sq(ena_dev, io_sq); ena_com_destroy_io_cq(ena_dev, io_cq); ena_com_io_queue_free(ena_dev, io_sq, io_cq); } int ena_com_get_link_params(struct ena_com_dev *ena_dev, struct ena_admin_get_feat_resp *resp) { return ena_com_get_feature(ena_dev, resp, ENA_ADMIN_LINK_CONFIG); } int ena_com_get_dev_attr_feat(struct ena_com_dev *ena_dev, struct ena_com_dev_get_features_ctx *get_feat_ctx) { struct ena_admin_get_feat_resp get_resp; int rc; rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_DEVICE_ATTRIBUTES); if (rc) return rc; memcpy(&get_feat_ctx->dev_attr, &get_resp.u.dev_attr, sizeof(get_resp.u.dev_attr)); ena_dev->supported_features = get_resp.u.dev_attr.supported_features; rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_MAX_QUEUES_NUM); if (rc) return rc; memcpy(&get_feat_ctx->max_queues, &get_resp.u.max_queue, sizeof(get_resp.u.max_queue)); ena_dev->tx_max_header_size = get_resp.u.max_queue.max_header_size; rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_AENQ_CONFIG); if (rc) return rc; memcpy(&get_feat_ctx->aenq, &get_resp.u.aenq, sizeof(get_resp.u.aenq)); rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_STATELESS_OFFLOAD_CONFIG); if (rc) return rc; memcpy(&get_feat_ctx->offload, &get_resp.u.offload, sizeof(get_resp.u.offload)); /* Driver hints isn't mandatory admin command. So in case the * command isn't supported set driver hints to 0 */ rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_HW_HINTS); if (!rc) memcpy(&get_feat_ctx->hw_hints, &get_resp.u.hw_hints, sizeof(get_resp.u.hw_hints)); else if (rc == -EOPNOTSUPP) memset(&get_feat_ctx->hw_hints, 0x0, sizeof(get_feat_ctx->hw_hints)); else return rc; rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_LLQ); if (!rc) memcpy(&get_feat_ctx->llq, &get_resp.u.llq, sizeof(get_resp.u.llq)); else if (rc == -EOPNOTSUPP) memset(&get_feat_ctx->llq, 0x0, sizeof(get_feat_ctx->llq)); else return rc; return 0; } void ena_com_admin_q_comp_intr_handler(struct ena_com_dev *ena_dev) { ena_com_handle_admin_completion(&ena_dev->admin_queue); } /* ena_handle_specific_aenq_event: * return the handler that is relevant to the specific event group */ static ena_aenq_handler ena_com_get_specific_aenq_cb(struct ena_com_dev *dev, u16 group) { struct ena_aenq_handlers *aenq_handlers = dev->aenq.aenq_handlers; if ((group < ENA_MAX_HANDLERS) && aenq_handlers->handlers[group]) return aenq_handlers->handlers[group]; return aenq_handlers->unimplemented_handler; } /* ena_aenq_intr_handler: * handles the aenq incoming events. * pop events from the queue and apply the specific handler */ void ena_com_aenq_intr_handler(struct ena_com_dev *dev, void *data) { struct ena_admin_aenq_entry *aenq_e; struct ena_admin_aenq_common_desc *aenq_common; struct ena_com_aenq *aenq = &dev->aenq; unsigned long long timestamp; ena_aenq_handler handler_cb; u16 masked_head, processed = 0; u8 phase; masked_head = aenq->head & (aenq->q_depth - 1); phase = aenq->phase; aenq_e = &aenq->entries[masked_head]; /* Get first entry */ aenq_common = &aenq_e->aenq_common_desc; /* Go over all the events */ while ((READ_ONCE(aenq_common->flags) & ENA_ADMIN_AENQ_COMMON_DESC_PHASE_MASK) == phase) { /* Make sure the phase bit (ownership) is as expected before * reading the rest of the descriptor. */ dma_rmb(); timestamp = (unsigned long long)aenq_common->timestamp_low | ((unsigned long long)aenq_common->timestamp_high << 32); pr_debug("AENQ! Group[%x] Syndrom[%x] timestamp: [%llus]\n", aenq_common->group, aenq_common->syndrom, timestamp); /* Handle specific event*/ handler_cb = ena_com_get_specific_aenq_cb(dev, aenq_common->group); handler_cb(data, aenq_e); /* call the actual event handler*/ /* Get next event entry */ masked_head++; processed++; if (unlikely(masked_head == aenq->q_depth)) { masked_head = 0; phase = !phase; } aenq_e = &aenq->entries[masked_head]; aenq_common = &aenq_e->aenq_common_desc; } aenq->head += processed; aenq->phase = phase; /* Don't update aenq doorbell if there weren't any processed events */ if (!processed) return; /* write the aenq doorbell after all AENQ descriptors were read */ mb(); writel_relaxed((u32)aenq->head, dev->reg_bar + ENA_REGS_AENQ_HEAD_DB_OFF); mmiowb(); } int ena_com_dev_reset(struct ena_com_dev *ena_dev, enum ena_regs_reset_reason_types reset_reason) { u32 stat, timeout, cap, reset_val; int rc; stat = ena_com_reg_bar_read32(ena_dev, ENA_REGS_DEV_STS_OFF); cap = ena_com_reg_bar_read32(ena_dev, ENA_REGS_CAPS_OFF); if (unlikely((stat == ENA_MMIO_READ_TIMEOUT) || (cap == ENA_MMIO_READ_TIMEOUT))) { pr_err("Reg read32 timeout occurred\n"); return -ETIME; } if ((stat & ENA_REGS_DEV_STS_READY_MASK) == 0) { pr_err("Device isn't ready, can't reset device\n"); return -EINVAL; } timeout = (cap & ENA_REGS_CAPS_RESET_TIMEOUT_MASK) >> ENA_REGS_CAPS_RESET_TIMEOUT_SHIFT; if (timeout == 0) { pr_err("Invalid timeout value\n"); return -EINVAL; } /* start reset */ reset_val = ENA_REGS_DEV_CTL_DEV_RESET_MASK; reset_val |= (reset_reason << ENA_REGS_DEV_CTL_RESET_REASON_SHIFT) & ENA_REGS_DEV_CTL_RESET_REASON_MASK; writel(reset_val, ena_dev->reg_bar + ENA_REGS_DEV_CTL_OFF); /* Write again the MMIO read request address */ ena_com_mmio_reg_read_request_write_dev_addr(ena_dev); rc = wait_for_reset_state(ena_dev, timeout, ENA_REGS_DEV_STS_RESET_IN_PROGRESS_MASK); if (rc != 0) { pr_err("Reset indication didn't turn on\n"); return rc; } /* reset done */ writel(0, ena_dev->reg_bar + ENA_REGS_DEV_CTL_OFF); rc = wait_for_reset_state(ena_dev, timeout, 0); if (rc != 0) { pr_err("Reset indication didn't turn off\n"); return rc; } timeout = (cap & ENA_REGS_CAPS_ADMIN_CMD_TO_MASK) >> ENA_REGS_CAPS_ADMIN_CMD_TO_SHIFT; if (timeout) /* the resolution of timeout reg is 100ms */ ena_dev->admin_queue.completion_timeout = timeout * 100000; else ena_dev->admin_queue.completion_timeout = ADMIN_CMD_TIMEOUT_US; return 0; } static int ena_get_dev_stats(struct ena_com_dev *ena_dev, struct ena_com_stats_ctx *ctx, enum ena_admin_get_stats_type type) { struct ena_admin_aq_get_stats_cmd *get_cmd = &ctx->get_cmd; struct ena_admin_acq_get_stats_resp *get_resp = &ctx->get_resp; struct ena_com_admin_queue *admin_queue; int ret; admin_queue = &ena_dev->admin_queue; get_cmd->aq_common_descriptor.opcode = ENA_ADMIN_GET_STATS; get_cmd->aq_common_descriptor.flags = 0; get_cmd->type = type; ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)get_cmd, sizeof(*get_cmd), (struct ena_admin_acq_entry *)get_resp, sizeof(*get_resp)); if (unlikely(ret)) pr_err("Failed to get stats. error: %d\n", ret); return ret; } int ena_com_get_dev_basic_stats(struct ena_com_dev *ena_dev, struct ena_admin_basic_stats *stats) { struct ena_com_stats_ctx ctx; int ret; memset(&ctx, 0x0, sizeof(ctx)); ret = ena_get_dev_stats(ena_dev, &ctx, ENA_ADMIN_GET_STATS_TYPE_BASIC); if (likely(ret == 0)) memcpy(stats, &ctx.get_resp.basic_stats, sizeof(ctx.get_resp.basic_stats)); return ret; } int ena_com_set_dev_mtu(struct ena_com_dev *ena_dev, int mtu) { struct ena_com_admin_queue *admin_queue; struct ena_admin_set_feat_cmd cmd; struct ena_admin_set_feat_resp resp; int ret; if (!ena_com_check_supported_feature_id(ena_dev, ENA_ADMIN_MTU)) { pr_debug("Feature %d isn't supported\n", ENA_ADMIN_MTU); return -EOPNOTSUPP; } memset(&cmd, 0x0, sizeof(cmd)); admin_queue = &ena_dev->admin_queue; cmd.aq_common_descriptor.opcode = ENA_ADMIN_SET_FEATURE; cmd.aq_common_descriptor.flags = 0; cmd.feat_common.feature_id = ENA_ADMIN_MTU; cmd.u.mtu.mtu = mtu; ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&cmd, sizeof(cmd), (struct ena_admin_acq_entry *)&resp, sizeof(resp)); if (unlikely(ret)) pr_err("Failed to set mtu %d. error: %d\n", mtu, ret); return ret; } int ena_com_get_offload_settings(struct ena_com_dev *ena_dev, struct ena_admin_feature_offload_desc *offload) { int ret; struct ena_admin_get_feat_resp resp; ret = ena_com_get_feature(ena_dev, &resp, ENA_ADMIN_STATELESS_OFFLOAD_CONFIG); if (unlikely(ret)) { pr_err("Failed to get offload capabilities %d\n", ret); return ret; } memcpy(offload, &resp.u.offload, sizeof(resp.u.offload)); return 0; } int ena_com_set_hash_function(struct ena_com_dev *ena_dev) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; struct ena_rss *rss = &ena_dev->rss; struct ena_admin_set_feat_cmd cmd; struct ena_admin_set_feat_resp resp; struct ena_admin_get_feat_resp get_resp; int ret; if (!ena_com_check_supported_feature_id(ena_dev, ENA_ADMIN_RSS_HASH_FUNCTION)) { pr_debug("Feature %d isn't supported\n", ENA_ADMIN_RSS_HASH_FUNCTION); return -EOPNOTSUPP; } /* Validate hash function is supported */ ret = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_RSS_HASH_FUNCTION); if (unlikely(ret)) return ret; if (get_resp.u.flow_hash_func.supported_func & (1 << rss->hash_func)) { pr_err("Func hash %d isn't supported by device, abort\n", rss->hash_func); return -EOPNOTSUPP; } memset(&cmd, 0x0, sizeof(cmd)); cmd.aq_common_descriptor.opcode = ENA_ADMIN_SET_FEATURE; cmd.aq_common_descriptor.flags = ENA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK; cmd.feat_common.feature_id = ENA_ADMIN_RSS_HASH_FUNCTION; cmd.u.flow_hash_func.init_val = rss->hash_init_val; cmd.u.flow_hash_func.selected_func = 1 << rss->hash_func; ret = ena_com_mem_addr_set(ena_dev, &cmd.control_buffer.address, rss->hash_key_dma_addr); if (unlikely(ret)) { pr_err("memory address set failed\n"); return ret; } cmd.control_buffer.length = sizeof(*rss->hash_key); ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&cmd, sizeof(cmd), (struct ena_admin_acq_entry *)&resp, sizeof(resp)); if (unlikely(ret)) { pr_err("Failed to set hash function %d. error: %d\n", rss->hash_func, ret); return -EINVAL; } return 0; } int ena_com_fill_hash_function(struct ena_com_dev *ena_dev, enum ena_admin_hash_functions func, const u8 *key, u16 key_len, u32 init_val) { struct ena_rss *rss = &ena_dev->rss; struct ena_admin_get_feat_resp get_resp; struct ena_admin_feature_rss_flow_hash_control *hash_key = rss->hash_key; int rc; /* Make sure size is a mult of DWs */ if (unlikely(key_len & 0x3)) return -EINVAL; rc = ena_com_get_feature_ex(ena_dev, &get_resp, ENA_ADMIN_RSS_HASH_FUNCTION, rss->hash_key_dma_addr, sizeof(*rss->hash_key)); if (unlikely(rc)) return rc; if (!((1 << func) & get_resp.u.flow_hash_func.supported_func)) { pr_err("Flow hash function %d isn't supported\n", func); return -EOPNOTSUPP; } switch (func) { case ENA_ADMIN_TOEPLITZ: if (key_len > sizeof(hash_key->key)) { pr_err("key len (%hu) is bigger than the max supported (%zu)\n", key_len, sizeof(hash_key->key)); return -EINVAL; } memcpy(hash_key->key, key, key_len); rss->hash_init_val = init_val; hash_key->keys_num = key_len >> 2; break; case ENA_ADMIN_CRC32: rss->hash_init_val = init_val; break; default: pr_err("Invalid hash function (%d)\n", func); return -EINVAL; } rc = ena_com_set_hash_function(ena_dev); /* Restore the old function */ if (unlikely(rc)) ena_com_get_hash_function(ena_dev, NULL, NULL); return rc; } int ena_com_get_hash_function(struct ena_com_dev *ena_dev, enum ena_admin_hash_functions *func, u8 *key) { struct ena_rss *rss = &ena_dev->rss; struct ena_admin_get_feat_resp get_resp; struct ena_admin_feature_rss_flow_hash_control *hash_key = rss->hash_key; int rc; rc = ena_com_get_feature_ex(ena_dev, &get_resp, ENA_ADMIN_RSS_HASH_FUNCTION, rss->hash_key_dma_addr, sizeof(*rss->hash_key)); if (unlikely(rc)) return rc; rss->hash_func = get_resp.u.flow_hash_func.selected_func; if (func) *func = rss->hash_func; if (key) memcpy(key, hash_key->key, (size_t)(hash_key->keys_num) << 2); return 0; } int ena_com_get_hash_ctrl(struct ena_com_dev *ena_dev, enum ena_admin_flow_hash_proto proto, u16 *fields) { struct ena_rss *rss = &ena_dev->rss; struct ena_admin_get_feat_resp get_resp; int rc; rc = ena_com_get_feature_ex(ena_dev, &get_resp, ENA_ADMIN_RSS_HASH_INPUT, rss->hash_ctrl_dma_addr, sizeof(*rss->hash_ctrl)); if (unlikely(rc)) return rc; if (fields) *fields = rss->hash_ctrl->selected_fields[proto].fields; return 0; } int ena_com_set_hash_ctrl(struct ena_com_dev *ena_dev) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; struct ena_rss *rss = &ena_dev->rss; struct ena_admin_feature_rss_hash_control *hash_ctrl = rss->hash_ctrl; struct ena_admin_set_feat_cmd cmd; struct ena_admin_set_feat_resp resp; int ret; if (!ena_com_check_supported_feature_id(ena_dev, ENA_ADMIN_RSS_HASH_INPUT)) { pr_debug("Feature %d isn't supported\n", ENA_ADMIN_RSS_HASH_INPUT); return -EOPNOTSUPP; } memset(&cmd, 0x0, sizeof(cmd)); cmd.aq_common_descriptor.opcode = ENA_ADMIN_SET_FEATURE; cmd.aq_common_descriptor.flags = ENA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK; cmd.feat_common.feature_id = ENA_ADMIN_RSS_HASH_INPUT; cmd.u.flow_hash_input.enabled_input_sort = ENA_ADMIN_FEATURE_RSS_FLOW_HASH_INPUT_L3_SORT_MASK | ENA_ADMIN_FEATURE_RSS_FLOW_HASH_INPUT_L4_SORT_MASK; ret = ena_com_mem_addr_set(ena_dev, &cmd.control_buffer.address, rss->hash_ctrl_dma_addr); if (unlikely(ret)) { pr_err("memory address set failed\n"); return ret; } cmd.control_buffer.length = sizeof(*hash_ctrl); ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&cmd, sizeof(cmd), (struct ena_admin_acq_entry *)&resp, sizeof(resp)); if (unlikely(ret)) pr_err("Failed to set hash input. error: %d\n", ret); return ret; } int ena_com_set_default_hash_ctrl(struct ena_com_dev *ena_dev) { struct ena_rss *rss = &ena_dev->rss; struct ena_admin_feature_rss_hash_control *hash_ctrl = rss->hash_ctrl; u16 available_fields = 0; int rc, i; /* Get the supported hash input */ rc = ena_com_get_hash_ctrl(ena_dev, 0, NULL); if (unlikely(rc)) return rc; hash_ctrl->selected_fields[ENA_ADMIN_RSS_TCP4].fields = ENA_ADMIN_RSS_L3_SA | ENA_ADMIN_RSS_L3_DA | ENA_ADMIN_RSS_L4_DP | ENA_ADMIN_RSS_L4_SP; hash_ctrl->selected_fields[ENA_ADMIN_RSS_UDP4].fields = ENA_ADMIN_RSS_L3_SA | ENA_ADMIN_RSS_L3_DA | ENA_ADMIN_RSS_L4_DP | ENA_ADMIN_RSS_L4_SP; hash_ctrl->selected_fields[ENA_ADMIN_RSS_TCP6].fields = ENA_ADMIN_RSS_L3_SA | ENA_ADMIN_RSS_L3_DA | ENA_ADMIN_RSS_L4_DP | ENA_ADMIN_RSS_L4_SP; hash_ctrl->selected_fields[ENA_ADMIN_RSS_UDP6].fields = ENA_ADMIN_RSS_L3_SA | ENA_ADMIN_RSS_L3_DA | ENA_ADMIN_RSS_L4_DP | ENA_ADMIN_RSS_L4_SP; hash_ctrl->selected_fields[ENA_ADMIN_RSS_IP4].fields = ENA_ADMIN_RSS_L3_SA | ENA_ADMIN_RSS_L3_DA; hash_ctrl->selected_fields[ENA_ADMIN_RSS_IP6].fields = ENA_ADMIN_RSS_L3_SA | ENA_ADMIN_RSS_L3_DA; hash_ctrl->selected_fields[ENA_ADMIN_RSS_IP4_FRAG].fields = ENA_ADMIN_RSS_L3_SA | ENA_ADMIN_RSS_L3_DA; hash_ctrl->selected_fields[ENA_ADMIN_RSS_NOT_IP].fields = ENA_ADMIN_RSS_L2_DA | ENA_ADMIN_RSS_L2_SA; for (i = 0; i < ENA_ADMIN_RSS_PROTO_NUM; i++) { available_fields = hash_ctrl->selected_fields[i].fields & hash_ctrl->supported_fields[i].fields; if (available_fields != hash_ctrl->selected_fields[i].fields) { pr_err("hash control doesn't support all the desire configuration. proto %x supported %x selected %x\n", i, hash_ctrl->supported_fields[i].fields, hash_ctrl->selected_fields[i].fields); return -EOPNOTSUPP; } } rc = ena_com_set_hash_ctrl(ena_dev); /* In case of failure, restore the old hash ctrl */ if (unlikely(rc)) ena_com_get_hash_ctrl(ena_dev, 0, NULL); return rc; } int ena_com_fill_hash_ctrl(struct ena_com_dev *ena_dev, enum ena_admin_flow_hash_proto proto, u16 hash_fields) { struct ena_rss *rss = &ena_dev->rss; struct ena_admin_feature_rss_hash_control *hash_ctrl = rss->hash_ctrl; u16 supported_fields; int rc; if (proto >= ENA_ADMIN_RSS_PROTO_NUM) { pr_err("Invalid proto num (%u)\n", proto); return -EINVAL; } /* Get the ctrl table */ rc = ena_com_get_hash_ctrl(ena_dev, proto, NULL); if (unlikely(rc)) return rc; /* Make sure all the fields are supported */ supported_fields = hash_ctrl->supported_fields[proto].fields; if ((hash_fields & supported_fields) != hash_fields) { pr_err("proto %d doesn't support the required fields %x. supports only: %x\n", proto, hash_fields, supported_fields); } hash_ctrl->selected_fields[proto].fields = hash_fields; rc = ena_com_set_hash_ctrl(ena_dev); /* In case of failure, restore the old hash ctrl */ if (unlikely(rc)) ena_com_get_hash_ctrl(ena_dev, 0, NULL); return 0; } int ena_com_indirect_table_fill_entry(struct ena_com_dev *ena_dev, u16 entry_idx, u16 entry_value) { struct ena_rss *rss = &ena_dev->rss; if (unlikely(entry_idx >= (1 << rss->tbl_log_size))) return -EINVAL; if (unlikely((entry_value > ENA_TOTAL_NUM_QUEUES))) return -EINVAL; rss->host_rss_ind_tbl[entry_idx] = entry_value; return 0; } int ena_com_indirect_table_set(struct ena_com_dev *ena_dev) { struct ena_com_admin_queue *admin_queue = &ena_dev->admin_queue; struct ena_rss *rss = &ena_dev->rss; struct ena_admin_set_feat_cmd cmd; struct ena_admin_set_feat_resp resp; int ret; if (!ena_com_check_supported_feature_id( ena_dev, ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG)) { pr_debug("Feature %d isn't supported\n", ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG); return -EOPNOTSUPP; } ret = ena_com_ind_tbl_convert_to_device(ena_dev); if (ret) { pr_err("Failed to convert host indirection table to device table\n"); return ret; } memset(&cmd, 0x0, sizeof(cmd)); cmd.aq_common_descriptor.opcode = ENA_ADMIN_SET_FEATURE; cmd.aq_common_descriptor.flags = ENA_ADMIN_AQ_COMMON_DESC_CTRL_DATA_INDIRECT_MASK; cmd.feat_common.feature_id = ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG; cmd.u.ind_table.size = rss->tbl_log_size; cmd.u.ind_table.inline_index = 0xFFFFFFFF; ret = ena_com_mem_addr_set(ena_dev, &cmd.control_buffer.address, rss->rss_ind_tbl_dma_addr); if (unlikely(ret)) { pr_err("memory address set failed\n"); return ret; } cmd.control_buffer.length = (1ULL << rss->tbl_log_size) * sizeof(struct ena_admin_rss_ind_table_entry); ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&cmd, sizeof(cmd), (struct ena_admin_acq_entry *)&resp, sizeof(resp)); if (unlikely(ret)) pr_err("Failed to set indirect table. error: %d\n", ret); return ret; } int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl) { struct ena_rss *rss = &ena_dev->rss; struct ena_admin_get_feat_resp get_resp; u32 tbl_size; int i, rc; tbl_size = (1ULL << rss->tbl_log_size) * sizeof(struct ena_admin_rss_ind_table_entry); rc = ena_com_get_feature_ex(ena_dev, &get_resp, ENA_ADMIN_RSS_REDIRECTION_TABLE_CONFIG, rss->rss_ind_tbl_dma_addr, tbl_size); if (unlikely(rc)) return rc; if (!ind_tbl) return 0; rc = ena_com_ind_tbl_convert_from_device(ena_dev); if (unlikely(rc)) return rc; for (i = 0; i < (1 << rss->tbl_log_size); i++) ind_tbl[i] = rss->host_rss_ind_tbl[i]; return 0; } int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 indr_tbl_log_size) { int rc; memset(&ena_dev->rss, 0x0, sizeof(ena_dev->rss)); rc = ena_com_indirect_table_allocate(ena_dev, indr_tbl_log_size); if (unlikely(rc)) goto err_indr_tbl; rc = ena_com_hash_key_allocate(ena_dev); if (unlikely(rc)) goto err_hash_key; rc = ena_com_hash_ctrl_init(ena_dev); if (unlikely(rc)) goto err_hash_ctrl; return 0; err_hash_ctrl: ena_com_hash_key_destroy(ena_dev); err_hash_key: ena_com_indirect_table_destroy(ena_dev); err_indr_tbl: return rc; } void ena_com_rss_destroy(struct ena_com_dev *ena_dev) { ena_com_indirect_table_destroy(ena_dev); ena_com_hash_key_destroy(ena_dev); ena_com_hash_ctrl_destroy(ena_dev); memset(&ena_dev->rss, 0x0, sizeof(ena_dev->rss)); } int ena_com_allocate_host_info(struct ena_com_dev *ena_dev) { struct ena_host_attribute *host_attr = &ena_dev->host_attr; host_attr->host_info = dma_zalloc_coherent(ena_dev->dmadev, SZ_4K, &host_attr->host_info_dma_addr, GFP_KERNEL); if (unlikely(!host_attr->host_info)) return -ENOMEM; host_attr->host_info->ena_spec_version = ((ENA_COMMON_SPEC_VERSION_MAJOR << ENA_REGS_VERSION_MAJOR_VERSION_SHIFT) | (ENA_COMMON_SPEC_VERSION_MINOR)); return 0; } int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev, u32 debug_area_size) { struct ena_host_attribute *host_attr = &ena_dev->host_attr; host_attr->debug_area_virt_addr = dma_zalloc_coherent(ena_dev->dmadev, debug_area_size, &host_attr->debug_area_dma_addr, GFP_KERNEL); if (unlikely(!host_attr->debug_area_virt_addr)) { host_attr->debug_area_size = 0; return -ENOMEM; } host_attr->debug_area_size = debug_area_size; return 0; } void ena_com_delete_host_info(struct ena_com_dev *ena_dev) { struct ena_host_attribute *host_attr = &ena_dev->host_attr; if (host_attr->host_info) { dma_free_coherent(ena_dev->dmadev, SZ_4K, host_attr->host_info, host_attr->host_info_dma_addr); host_attr->host_info = NULL; } } void ena_com_delete_debug_area(struct ena_com_dev *ena_dev) { struct ena_host_attribute *host_attr = &ena_dev->host_attr; if (host_attr->debug_area_virt_addr) { dma_free_coherent(ena_dev->dmadev, host_attr->debug_area_size, host_attr->debug_area_virt_addr, host_attr->debug_area_dma_addr); host_attr->debug_area_virt_addr = NULL; } } int ena_com_set_host_attributes(struct ena_com_dev *ena_dev) { struct ena_host_attribute *host_attr = &ena_dev->host_attr; struct ena_com_admin_queue *admin_queue; struct ena_admin_set_feat_cmd cmd; struct ena_admin_set_feat_resp resp; int ret; /* Host attribute config is called before ena_com_get_dev_attr_feat * so ena_com can't check if the feature is supported. */ memset(&cmd, 0x0, sizeof(cmd)); admin_queue = &ena_dev->admin_queue; cmd.aq_common_descriptor.opcode = ENA_ADMIN_SET_FEATURE; cmd.feat_common.feature_id = ENA_ADMIN_HOST_ATTR_CONFIG; ret = ena_com_mem_addr_set(ena_dev, &cmd.u.host_attr.debug_ba, host_attr->debug_area_dma_addr); if (unlikely(ret)) { pr_err("memory address set failed\n"); return ret; } ret = ena_com_mem_addr_set(ena_dev, &cmd.u.host_attr.os_info_ba, host_attr->host_info_dma_addr); if (unlikely(ret)) { pr_err("memory address set failed\n"); return ret; } cmd.u.host_attr.debug_area_size = host_attr->debug_area_size; ret = ena_com_execute_admin_command(admin_queue, (struct ena_admin_aq_entry *)&cmd, sizeof(cmd), (struct ena_admin_acq_entry *)&resp, sizeof(resp)); if (unlikely(ret)) pr_err("Failed to set host attributes: %d\n", ret); return ret; } /* Interrupt moderation */ bool ena_com_interrupt_moderation_supported(struct ena_com_dev *ena_dev) { return ena_com_check_supported_feature_id(ena_dev, ENA_ADMIN_INTERRUPT_MODERATION); } int ena_com_update_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev, u32 tx_coalesce_usecs) { if (!ena_dev->intr_delay_resolution) { pr_err("Illegal interrupt delay granularity value\n"); return -EFAULT; } ena_dev->intr_moder_tx_interval = tx_coalesce_usecs / ena_dev->intr_delay_resolution; return 0; } int ena_com_update_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev, u32 rx_coalesce_usecs) { if (!ena_dev->intr_delay_resolution) { pr_err("Illegal interrupt delay granularity value\n"); return -EFAULT; } /* We use LOWEST entry of moderation table for storing * nonadaptive interrupt coalescing values */ ena_dev->intr_moder_tbl[ENA_INTR_MODER_LOWEST].intr_moder_interval = rx_coalesce_usecs / ena_dev->intr_delay_resolution; return 0; } void ena_com_destroy_interrupt_moderation(struct ena_com_dev *ena_dev) { if (ena_dev->intr_moder_tbl) devm_kfree(ena_dev->dmadev, ena_dev->intr_moder_tbl); ena_dev->intr_moder_tbl = NULL; } int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev) { struct ena_admin_get_feat_resp get_resp; u16 delay_resolution; int rc; rc = ena_com_get_feature(ena_dev, &get_resp, ENA_ADMIN_INTERRUPT_MODERATION); if (rc) { if (rc == -EOPNOTSUPP) { pr_debug("Feature %d isn't supported\n", ENA_ADMIN_INTERRUPT_MODERATION); rc = 0; } else { pr_err("Failed to get interrupt moderation admin cmd. rc: %d\n", rc); } /* no moderation supported, disable adaptive support */ ena_com_disable_adaptive_moderation(ena_dev); return rc; } rc = ena_com_init_interrupt_moderation_table(ena_dev); if (rc) goto err; /* if moderation is supported by device we set adaptive moderation */ delay_resolution = get_resp.u.intr_moderation.intr_delay_resolution; ena_com_update_intr_delay_resolution(ena_dev, delay_resolution); ena_com_enable_adaptive_moderation(ena_dev); return 0; err: ena_com_destroy_interrupt_moderation(ena_dev); return rc; } void ena_com_config_default_interrupt_moderation_table(struct ena_com_dev *ena_dev) { struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl; if (!intr_moder_tbl) return; intr_moder_tbl[ENA_INTR_MODER_LOWEST].intr_moder_interval = ENA_INTR_LOWEST_USECS; intr_moder_tbl[ENA_INTR_MODER_LOWEST].pkts_per_interval = ENA_INTR_LOWEST_PKTS; intr_moder_tbl[ENA_INTR_MODER_LOWEST].bytes_per_interval = ENA_INTR_LOWEST_BYTES; intr_moder_tbl[ENA_INTR_MODER_LOW].intr_moder_interval = ENA_INTR_LOW_USECS; intr_moder_tbl[ENA_INTR_MODER_LOW].pkts_per_interval = ENA_INTR_LOW_PKTS; intr_moder_tbl[ENA_INTR_MODER_LOW].bytes_per_interval = ENA_INTR_LOW_BYTES; intr_moder_tbl[ENA_INTR_MODER_MID].intr_moder_interval = ENA_INTR_MID_USECS; intr_moder_tbl[ENA_INTR_MODER_MID].pkts_per_interval = ENA_INTR_MID_PKTS; intr_moder_tbl[ENA_INTR_MODER_MID].bytes_per_interval = ENA_INTR_MID_BYTES; intr_moder_tbl[ENA_INTR_MODER_HIGH].intr_moder_interval = ENA_INTR_HIGH_USECS; intr_moder_tbl[ENA_INTR_MODER_HIGH].pkts_per_interval = ENA_INTR_HIGH_PKTS; intr_moder_tbl[ENA_INTR_MODER_HIGH].bytes_per_interval = ENA_INTR_HIGH_BYTES; intr_moder_tbl[ENA_INTR_MODER_HIGHEST].intr_moder_interval = ENA_INTR_HIGHEST_USECS; intr_moder_tbl[ENA_INTR_MODER_HIGHEST].pkts_per_interval = ENA_INTR_HIGHEST_PKTS; intr_moder_tbl[ENA_INTR_MODER_HIGHEST].bytes_per_interval = ENA_INTR_HIGHEST_BYTES; } unsigned int ena_com_get_nonadaptive_moderation_interval_tx(struct ena_com_dev *ena_dev) { return ena_dev->intr_moder_tx_interval; } unsigned int ena_com_get_nonadaptive_moderation_interval_rx(struct ena_com_dev *ena_dev) { struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl; if (intr_moder_tbl) return intr_moder_tbl[ENA_INTR_MODER_LOWEST].intr_moder_interval; return 0; } void ena_com_init_intr_moderation_entry(struct ena_com_dev *ena_dev, enum ena_intr_moder_level level, struct ena_intr_moder_entry *entry) { struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl; if (level >= ENA_INTR_MAX_NUM_OF_LEVELS) return; intr_moder_tbl[level].intr_moder_interval = entry->intr_moder_interval; if (ena_dev->intr_delay_resolution) intr_moder_tbl[level].intr_moder_interval /= ena_dev->intr_delay_resolution; intr_moder_tbl[level].pkts_per_interval = entry->pkts_per_interval; /* use hardcoded value until ethtool supports bytecount parameter */ if (entry->bytes_per_interval != ENA_INTR_BYTE_COUNT_NOT_SUPPORTED) intr_moder_tbl[level].bytes_per_interval = entry->bytes_per_interval; } void ena_com_get_intr_moderation_entry(struct ena_com_dev *ena_dev, enum ena_intr_moder_level level, struct ena_intr_moder_entry *entry) { struct ena_intr_moder_entry *intr_moder_tbl = ena_dev->intr_moder_tbl; if (level >= ENA_INTR_MAX_NUM_OF_LEVELS) return; entry->intr_moder_interval = intr_moder_tbl[level].intr_moder_interval; if (ena_dev->intr_delay_resolution) entry->intr_moder_interval *= ena_dev->intr_delay_resolution; entry->pkts_per_interval = intr_moder_tbl[level].pkts_per_interval; entry->bytes_per_interval = intr_moder_tbl[level].bytes_per_interval; } int ena_com_config_dev_mode(struct ena_com_dev *ena_dev, struct ena_admin_feature_llq_desc *llq_features, struct ena_llq_configurations *llq_default_cfg) { int rc; int size; if (!llq_features->max_llq_num) { ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST; return 0; } rc = ena_com_config_llq_info(ena_dev, llq_features, llq_default_cfg); if (rc) return rc; /* Validate the descriptor is not too big */ size = ena_dev->tx_max_header_size; size += ena_dev->llq_info.descs_num_before_header * sizeof(struct ena_eth_io_tx_desc); if (unlikely(ena_dev->llq_info.desc_list_entry_size < size)) { pr_err("the size of the LLQ entry is smaller than needed\n"); return -EINVAL; } ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_DEV; return 0; }
856161.c
/* * Copyright 2015, Sam Bobroff, IBM Corp. * Licensed under GPLv2. * * Test the kernel's system call code to ensure that a system call * made from within an active HTM transaction is aborted with the * correct failure code. * Conversely, ensure that a system call made from within a * suspended transaction can succeed. */ #include <stdio.h> #include <unistd.h> #include <sys/syscall.h> #include <asm/tm.h> #include <asm/cputable.h> #include <linux/auxvec.h> #include <sys/time.h> #include <stdlib.h> #include "utils.h" extern int getppid_tm_active(void); extern int getppid_tm_suspended(void); unsigned retries = 0; #define TEST_DURATION 10 /* seconds */ #define TM_RETRIES 100 long failure_code(void) { return __builtin_get_texasru() >> 24; } bool failure_is_persistent(void) { return (failure_code() & TM_CAUSE_PERSISTENT) == TM_CAUSE_PERSISTENT; } bool failure_is_syscall(void) { return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL; } pid_t getppid_tm(bool suspend) { int i; pid_t pid; for (i = 0; i < TM_RETRIES; i++) { if (suspend) pid = getppid_tm_suspended(); else pid = getppid_tm_active(); if (pid >= 0) return pid; if (failure_is_persistent()) { if (failure_is_syscall()) return -1; printf("Unexpected persistent transaction failure.\n"); printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n", __builtin_get_texasr(), __builtin_get_tfiar()); exit(-1); } retries++; } printf("Exceeded limit of %d temporary transaction failures.\n", TM_RETRIES); printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n", __builtin_get_texasr(), __builtin_get_tfiar()); exit(-1); } int tm_syscall(void) { unsigned count = 0; struct timeval end, now; SKIP_IF(!((long)get_auxv_entry(AT_HWCAP2) & PPC_FEATURE2_HTM_NOSC)); setbuf(stdout, NULL); printf("Testing transactional syscalls for %d seconds...\n", TEST_DURATION); gettimeofday(&end, NULL); now.tv_sec = TEST_DURATION; now.tv_usec = 0; timeradd(&end, &now, &end); for (count = 0; timercmp(&now, &end, <); count++) { /* * Test a syscall within a suspended transaction and verify * that it succeeds. */ FAIL_IF(getppid_tm(true) == -1); /* Should succeed. */ /* * Test a syscall within an active transaction and verify that * it fails with the correct failure code. */ FAIL_IF(getppid_tm(false) != -1); /* Should fail... */ FAIL_IF(!failure_is_persistent()); /* ...persistently... */ FAIL_IF(!failure_is_syscall()); /* ...with code syscall. */ gettimeofday(&now, 0); } printf("%d active and suspended transactions behaved correctly.\n", count); printf("(There were %d transaction retries.)\n", retries); return 0; } int main(void) { return test_harness(tm_syscall, "tm_syscall"); }
762185.c
/**************************************************************************** * arch/sim/src/sim/up_testset.c * * Copyright (C) 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <[email protected]> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ /**************************************************************************** * Included Files ****************************************************************************/ #include <stdint.h> #include <pthread.h> /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ /* Must match definitions in arch/sim/include/spinlock.h */ #define SP_UNLOCKED 0 /* The Un-locked state */ #define SP_LOCKED 1 /* The Locked state */ /**************************************************************************** * Public Types ****************************************************************************/ /* Must match definitions in arch/sim/include/spinlock.h */ typedef uint8_t spinlock_t; /**************************************************************************** * Private Data ****************************************************************************/ #ifdef CONFIG_SMP static pthread_mutex_t g_tsmutex = PTHREAD_MUTEX_INITIALIZER; #endif /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** * Name: up_testset * * Description: * Perform an atomic test and set operation on the provided spinlock. * * This function must be provided via the architecture-specific logic. * * Input Parameters: * lock - The address of spinlock object. * * Returned Value: * The spinlock is always locked upon return. The value of previous value * of the spinlock variable is returned, either SP_LOCKED if the spinlock * as previously locked (meaning that the test-and-set operation failed to * obtain the lock) or SP_UNLOCKED if the spinlock was previously unlocked * (meaning that we successfully obtained the lock) * ****************************************************************************/ spinlock_t up_testset(volatile spinlock_t *lock) { #ifdef CONFIG_SMP /* In the multi-CPU SMP case, we use a mutex to assure that the following * test and set is atomic. */ pthread_mutex_lock(&g_tsmutex); #endif /* In the non-SMP case, the simulation is implemented with a single thread * the test-and-set operation is inherently atomic. */ spinlock_t ret = *lock; *lock = SP_LOCKED; #ifdef CONFIG_SMP pthread_mutex_unlock(&g_tsmutex); #endif return ret; }
505491.c
/*! \file gd32f20x_cau_aes.c \brief CAU_AES driver \version 2015-07-15, V1.0.0, firmware for GD32F20x \version 2017-06-05, V2.0.0, firmware for GD32F20x \version 2018-10-31, V2.1.0, firmware for GD32F20x */ /* Copyright (c) 2018, GigaDevice Semiconductor Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "gd32f20x_cau.h" #define AESBSY_TIMEOUT ((uint32_t)0x00010000U) /* AES key structure parameter config */ static void cau_aes_key_config(uint8_t *key, uint16_t keysize, cau_key_parameter_struct* cau_key_initpara); /* AES calculate process */ static ErrStatus cau_aes_calculate(uint8_t *input, uint32_t in_length, uint8_t *output); /*! \brief encrypt and decrypt using AES in ECB mode \param[in] algo_dir: algorithm direction only one parameter can be selected which is shown as below \arg CAU_ENCRYPT: encrypt \arg CAU_DECRYPT: decrypt \param[in] key: key used for AES algorithm \param[in] keysize: length of the key, must be a 128, 192 or 256 \param[in] text: pointer to the text information struct input: pointer to the input buffer in_length: length of the input buffer, must be a multiple of 16 output: pointer to the returned buffer \param[out] none \retval ErrStatus: SUCCESS or ERROR */ ErrStatus cau_aes_ecb(uint32_t algo_dir, uint8_t *key, uint16_t keysize, cau_text_struct *text) { ErrStatus ret = ERROR; cau_key_parameter_struct key_initpara; __IO uint32_t counter = 0U; uint32_t busystatus = 0U; /* key structure initialization */ cau_key_parameter_init(&key_initpara); /* AES key structure parameter config */ cau_aes_key_config(key, keysize, &key_initpara); /* key initialization */ cau_key_init(&key_initpara); /* AES decryption */ if(CAU_DECRYPT == algo_dir){ /* flush the IN and OUT FIFOs */ cau_fifo_flush(); /* initialize the CAU peripheral */ cau_init(CAU_DECRYPT, CAU_MODE_AES_KEY, CAU_SWAPPING_32BIT); /* enable the CAU peripheral */ cau_enable(); /* wait until the busy flag is RESET */ do{ busystatus = cau_flag_get(CAU_FLAG_BUSY); counter++; }while((AESBSY_TIMEOUT != counter) && (RESET != busystatus)); if(RESET != busystatus){ return ERROR; } } /* initialize the CAU peripheral */ cau_init(algo_dir, CAU_MODE_AES_ECB, CAU_SWAPPING_8BIT); /* flush the IN and OUT FIFOs */ cau_fifo_flush(); /* enable the CAU peripheral */ cau_enable(); /* AES calculate process */ ret = cau_aes_calculate(text->input, text->in_length, text->output); /* disable the CAU peripheral */ cau_disable(); return ret; } /*! \brief encrypt and decrypt using AES in CBC mode \param[in] algo_dir: algorithm direction only one parameter can be selected which is shown as below \arg CAU_ENCRYPT: encrypt \arg CAU_DECRYPT: decrypt \param[in] key: key used for AES algorithm \param[in] keysize: length of the key, must be a 128, 192 or 256 \param[in] iv: initialization vectors used for TDES algorithm \param[in] text: pointer to the text information struct input: pointer to the input buffer in_length: length of the input buffer, must be a multiple of 16 output: pointer to the returned buffer \param[out] none \retval ErrStatus: SUCCESS or ERROR */ ErrStatus cau_aes_cbc(uint32_t algo_dir, uint8_t *key, uint16_t keysize, uint8_t iv[16], cau_text_struct *text) { ErrStatus ret = ERROR; cau_key_parameter_struct key_initpara; cau_iv_parameter_struct iv_initpara; __IO uint32_t counter = 0U; uint32_t busystatus = 0U; uint32_t ivaddr = (uint32_t)iv; /* key structure initialization */ cau_key_parameter_init(&key_initpara); /* AES key structure parameter config */ cau_aes_key_config(key, keysize, &key_initpara); /* key initialization */ cau_key_init(&key_initpara); /* AES decryption */ if(CAU_DECRYPT == algo_dir){ /* flush the IN and OUT FIFOs */ cau_fifo_flush(); /* initialize the CAU peripheral */ cau_init(CAU_DECRYPT, CAU_MODE_AES_KEY, CAU_SWAPPING_32BIT); /* enable the CAU peripheral */ cau_enable(); /* wait until the busy flag is RESET */ do{ busystatus = cau_flag_get(CAU_FLAG_BUSY); counter++; }while((AESBSY_TIMEOUT != counter) && (RESET != busystatus)); if(RESET != busystatus){ return ERROR; } } /* initialize the CAU peripheral */ cau_init(algo_dir, CAU_MODE_AES_CBC, CAU_SWAPPING_8BIT); /* vectors initialization */ iv_initpara.iv_0_high = __REV(*(uint32_t*)(ivaddr)); ivaddr += 4U; iv_initpara.iv_0_low = __REV(*(uint32_t*)(ivaddr)); ivaddr += 4U; iv_initpara.iv_1_high = __REV(*(uint32_t*)(ivaddr)); ivaddr += 4U; iv_initpara.iv_1_low = __REV(*(uint32_t*)(ivaddr)); cau_iv_init(&iv_initpara); /* flush the IN and OUT FIFOs */ cau_fifo_flush(); /* enable the CAU peripheral */ cau_enable(); /* AES calculate process */ ret = cau_aes_calculate(text->input, text->in_length, text->output); /* disable the CAU peripheral */ cau_disable(); return ret; } /*! \brief encrypt and decrypt using AES in CTR mode \param[in] algo_dir: algorithm direction only one parameter can be selected which is shown as below \arg CAU_ENCRYPT: encrypt \arg CAU_DECRYPT: decrypt \param[in] key: key used for AES algorithm \param[in] keysize: length of the key, must be a 128, 192 or 256 \param[in] iv: initialization vectors used for TDES algorithm \param[in] text: pointer to the text information struct input: pointer to the input buffer in_length: length of the input buffer, must be a multiple of 16 output: pointer to the returned buffer \param[out] none \retval ErrStatus: SUCCESS or ERROR */ ErrStatus cau_aes_ctr(uint32_t algo_dir, uint8_t *key, uint16_t keysize, uint8_t iv[16], cau_text_struct *text) { ErrStatus ret = ERROR; cau_key_parameter_struct key_initpara; cau_iv_parameter_struct iv_initpara; uint32_t ivaddr = (uint32_t)iv; /* key structure initialization */ cau_key_parameter_init(&key_initpara); /* initialize the CAU peripheral */ cau_init(algo_dir, CAU_MODE_AES_CTR, CAU_SWAPPING_8BIT); /* AES key structure parameter config */ cau_aes_key_config(key, keysize, &key_initpara); /* key initialization */ cau_key_init(&key_initpara); /* vectors initialization */ iv_initpara.iv_0_high = __REV(*(uint32_t*)(ivaddr)); ivaddr += 4U; iv_initpara.iv_0_low = __REV(*(uint32_t*)(ivaddr)); ivaddr += 4U; iv_initpara.iv_1_high = __REV(*(uint32_t*)(ivaddr)); ivaddr += 4U; iv_initpara.iv_1_low = __REV(*(uint32_t*)(ivaddr)); cau_iv_init(&iv_initpara); /* flush the IN and OUT FIFOs */ cau_fifo_flush(); /* enable the CAU peripheral */ cau_enable(); /* AES calculate process */ ret = cau_aes_calculate(text->input, text->in_length, text->output); /* disable the CAU peripheral */ cau_disable(); return ret; } /*! \brief AES key structure parameter config \param[in] key: key used for AES algorithm \param[in] keysize: length of the key, must be a 128, 192 or 256 \param[out] cau_key_initpara: key init parameter struct key_0_high: key 0 high key_0_low: key 0 low key_1_high: key 1 high key_1_low: key 1 low key_2_high: key 2 high key_2_low: key 2 low key_3_high: key 3 high key_3_low: key 3 low \retval none */ static void cau_aes_key_config(uint8_t *key, uint16_t keysize, cau_key_parameter_struct* cau_key_initpara) { uint32_t keyaddr = (uint32_t)key; switch(keysize){ case 128: cau_aes_keysize_config(CAU_KEYSIZE_128BIT); cau_key_initpara->key_2_high = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_2_low = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_3_high = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_3_low = __REV(*(uint32_t*)(keyaddr)); break; case 192: cau_aes_keysize_config(CAU_KEYSIZE_192BIT); cau_key_initpara->key_1_high = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_1_low = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_2_high = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_2_low = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_3_high = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_3_low = __REV(*(uint32_t*)(keyaddr)); break; case 256: cau_aes_keysize_config(CAU_KEYSIZE_256BIT); cau_key_initpara->key_0_high = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_0_low = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_1_high = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_1_low = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_2_high = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_2_low = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_3_high = __REV(*(uint32_t*)(keyaddr)); keyaddr += 4U; cau_key_initpara->key_3_low = __REV(*(uint32_t*)(keyaddr)); break; default: break; } } /*! \brief AES calculate process \param[in] input: pointer to the input buffer \param[in] in_length: length of the input buffer, must be a multiple of 16 \param[in] output: pointer to the returned buffer \param[out] none \retval ErrStatus: SUCCESS or ERROR */ static ErrStatus cau_aes_calculate(uint8_t *input, uint32_t in_length, uint8_t *output) { uint32_t inputaddr = (uint32_t)input; uint32_t outputaddr = (uint32_t)output; uint32_t i = 0U; __IO uint32_t counter = 0U; uint32_t busystatus = 0U; /* the clock is not enabled or there is no embeded CAU peripheral */ if(DISABLE == cau_enable_state_get()){ return ERROR; } for(i = 0U; i < in_length; i += 16U){ /* write data to the IN FIFO */ cau_data_write(*(uint32_t*)(inputaddr)); inputaddr += 4U; cau_data_write(*(uint32_t*)(inputaddr)); inputaddr += 4U; cau_data_write(*(uint32_t*)(inputaddr)); inputaddr += 4U; cau_data_write(*(uint32_t*)(inputaddr)); inputaddr += 4U; /* wait until the complete message has been processed */ counter = 0U; do{ busystatus = cau_flag_get(CAU_FLAG_BUSY); counter++; }while((AESBSY_TIMEOUT != counter) && (RESET != busystatus)); if(RESET != busystatus){ return ERROR; }else{ /* read the output block from the output FIFO */ *(uint32_t*)(outputaddr) = cau_data_read(); outputaddr += 4U; *(uint32_t*)(outputaddr) = cau_data_read(); outputaddr += 4U; *(uint32_t*)(outputaddr) = cau_data_read(); outputaddr += 4U; *(uint32_t*)(outputaddr) = cau_data_read(); outputaddr += 4U; } } return SUCCESS; }
165573.c
/** ****************************************************************************** * @file stm32f7xx_hal_qspi.c * @author MCD Application Team * @brief QSPI HAL module driver. * This file provides firmware functions to manage the following * functionalities of the QuadSPI interface (QSPI). * + Initialization and de-initialization functions * + Indirect functional mode management * + Memory-mapped functional mode management * + Auto-polling functional mode management * + Interrupts and flags management * + DMA channel configuration for indirect functional mode * + Errors management and abort functionality * * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim =============================================================================== ##### How to use this driver ##### =============================================================================== [..] *** Initialization *** ====================== [..] (#) As prerequisite, fill in the HAL_QSPI_MspInit() : (++) Enable QuadSPI clock interface with __HAL_RCC_QSPI_CLK_ENABLE(). (++) Reset QuadSPI Peripheral with __HAL_RCC_QSPI_FORCE_RESET() and __HAL_RCC_QSPI_RELEASE_RESET(). (++) Enable the clocks for the QuadSPI GPIOS with __HAL_RCC_GPIOx_CLK_ENABLE(). (++) Configure these QuadSPI pins in alternate mode using HAL_GPIO_Init(). (++) If interrupt mode is used, enable and configure QuadSPI global interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ(). (++) If DMA mode is used, enable the clocks for the QuadSPI DMA channel with __HAL_RCC_DMAx_CLK_ENABLE(), configure DMA with HAL_DMA_Init(), link it with QuadSPI handle using __HAL_LINKDMA(), enable and configure DMA channel global interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ(). (#) Configure the flash size, the clock prescaler, the fifo threshold, the clock mode, the sample shifting and the CS high time using the HAL_QSPI_Init() function. *** Indirect functional mode *** ================================ [..] (#) Configure the command sequence using the HAL_QSPI_Command() or HAL_QSPI_Command_IT() functions : (++) Instruction phase : the mode used and if present the instruction opcode. (++) Address phase : the mode used and if present the size and the address value. (++) Alternate-bytes phase : the mode used and if present the size and the alternate bytes values. (++) Dummy-cycles phase : the number of dummy cycles (mode used is same as data phase). (++) Data phase : the mode used and if present the number of bytes. (++) Double Data Rate (DDR) mode : the activation (or not) of this mode and the delay if activated. (++) Sending Instruction Only Once (SIOO) mode : the activation (or not) of this mode. (#) If no data is required for the command, it is sent directly to the memory : (++) In polling mode, the output of the function is done when the transfer is complete. (++) In interrupt mode, HAL_QSPI_CmdCpltCallback() will be called when the transfer is complete. (#) For the indirect write mode, use HAL_QSPI_Transmit(), HAL_QSPI_Transmit_DMA() or HAL_QSPI_Transmit_IT() after the command configuration : (++) In polling mode, the output of the function is done when the transfer is complete. (++) In interrupt mode, HAL_QSPI_FifoThresholdCallback() will be called when the fifo threshold is reached and HAL_QSPI_TxCpltCallback() will be called when the transfer is complete. (++) In DMA mode, HAL_QSPI_TxHalfCpltCallback() will be called at the half transfer and HAL_QSPI_TxCpltCallback() will be called when the transfer is complete. (#) For the indirect read mode, use HAL_QSPI_Receive(), HAL_QSPI_Receive_DMA() or HAL_QSPI_Receive_IT() after the command configuration : (++) In polling mode, the output of the function is done when the transfer is complete. (++) In interrupt mode, HAL_QSPI_FifoThresholdCallback() will be called when the fifo threshold is reached and HAL_QSPI_RxCpltCallback() will be called when the transfer is complete. (++) In DMA mode, HAL_QSPI_RxHalfCpltCallback() will be called at the half transfer and HAL_QSPI_RxCpltCallback() will be called when the transfer is complete. *** Auto-polling functional mode *** ==================================== [..] (#) Configure the command sequence and the auto-polling functional mode using the HAL_QSPI_AutoPolling() or HAL_QSPI_AutoPolling_IT() functions : (++) Instruction phase : the mode used and if present the instruction opcode. (++) Address phase : the mode used and if present the size and the address value. (++) Alternate-bytes phase : the mode used and if present the size and the alternate bytes values. (++) Dummy-cycles phase : the number of dummy cycles (mode used is same as data phase). (++) Data phase : the mode used. (++) Double Data Rate (DDR) mode : the activation (or not) of this mode and the delay if activated. (++) Sending Instruction Only Once (SIOO) mode : the activation (or not) of this mode. (++) The size of the status bytes, the match value, the mask used, the match mode (OR/AND), the polling interval and the automatic stop activation. (#) After the configuration : (++) In polling mode, the output of the function is done when the status match is reached. The automatic stop is activated to avoid an infinite loop. (++) In interrupt mode, HAL_QSPI_StatusMatchCallback() will be called each time the status match is reached. *** Memory-mapped functional mode *** ===================================== [..] (#) Configure the command sequence and the memory-mapped functional mode using the HAL_QSPI_MemoryMapped() functions : (++) Instruction phase : the mode used and if present the instruction opcode. (++) Address phase : the mode used and the size. (++) Alternate-bytes phase : the mode used and if present the size and the alternate bytes values. (++) Dummy-cycles phase : the number of dummy cycles (mode used is same as data phase). (++) Data phase : the mode used. (++) Double Data Rate (DDR) mode : the activation (or not) of this mode and the delay if activated. (++) Sending Instruction Only Once (SIOO) mode : the activation (or not) of this mode. (++) The timeout activation and the timeout period. (#) After the configuration, the QuadSPI will be used as soon as an access on the AHB is done on the address range. HAL_QSPI_TimeOutCallback() will be called when the timeout expires. *** Errors management and abort functionality *** ================================================= [..] (#) HAL_QSPI_GetError() function gives the error raised during the last operation. (#) HAL_QSPI_Abort() and HAL_QSPI_AbortIT() functions aborts any on-going operation and flushes the fifo : (++) In polling mode, the output of the function is done when the transfer complete bit is set and the busy bit cleared. (++) In interrupt mode, HAL_QSPI_AbortCpltCallback() will be called when the transfer complete bit is set. *** Control functions *** ========================= [..] (#) HAL_QSPI_GetState() function gives the current state of the HAL QuadSPI driver. (#) HAL_QSPI_SetTimeout() function configures the timeout value used in the driver. (#) HAL_QSPI_SetFifoThreshold() function configures the threshold on the Fifo of the QSPI IP. (#) HAL_QSPI_GetFifoThreshold() function gives the current of the Fifo's threshold (#) HAL_QSPI_SetFlashID() function configures the index of the flash memory to be accessed. *** Callback registration *** ============================================= [..] The compilation define USE_HAL_QSPI_REGISTER_CALLBACKS when set to 1 allows the user to configure dynamically the driver callbacks. Use Functions HAL_QSPI_RegisterCallback() to register a user callback, it allows to register following callbacks: (+) ErrorCallback : callback when error occurs. (+) AbortCpltCallback : callback when abort is completed. (+) FifoThresholdCallback : callback when the fifo threshold is reached. (+) CmdCpltCallback : callback when a command without data is completed. (+) RxCpltCallback : callback when a reception transfer is completed. (+) TxCpltCallback : callback when a transmission transfer is completed. (+) RxHalfCpltCallback : callback when half of the reception transfer is completed. (+) TxHalfCpltCallback : callback when half of the transmission transfer is completed. (+) StatusMatchCallback : callback when a status match occurs. (+) TimeOutCallback : callback when the timeout perioed expires. (+) MspInitCallback : QSPI MspInit. (+) MspDeInitCallback : QSPI MspDeInit. This function takes as parameters the HAL peripheral handle, the Callback ID and a pointer to the user callback function. Use function HAL_QSPI_UnRegisterCallback() to reset a callback to the default weak (surcharged) function. It allows to reset following callbacks: (+) ErrorCallback : callback when error occurs. (+) AbortCpltCallback : callback when abort is completed. (+) FifoThresholdCallback : callback when the fifo threshold is reached. (+) CmdCpltCallback : callback when a command without data is completed. (+) RxCpltCallback : callback when a reception transfer is completed. (+) TxCpltCallback : callback when a transmission transfer is completed. (+) RxHalfCpltCallback : callback when half of the reception transfer is completed. (+) TxHalfCpltCallback : callback when half of the transmission transfer is completed. (+) StatusMatchCallback : callback when a status match occurs. (+) TimeOutCallback : callback when the timeout perioed expires. (+) MspInitCallback : QSPI MspInit. (+) MspDeInitCallback : QSPI MspDeInit. This function) takes as parameters the HAL peripheral handle and the Callback ID. By default, after the HAL_QSPI_Init and if the state is HAL_QSPI_STATE_RESET all callbacks are reset to the corresponding legacy weak (surcharged) functions. Exception done for MspInit and MspDeInit callbacks that are respectively reset to the legacy weak (surcharged) functions in the HAL_QSPI_Init and HAL_QSPI_DeInit only when these callbacks are null (not registered beforehand). If not, MspInit or MspDeInit are not null, the HAL_QSPI_Init and HAL_QSPI_DeInit keep and use the user MspInit/MspDeInit callbacks (registered beforehand) Callbacks can be registered/unregistered in READY state only. Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. In that case first register the MspInit/MspDeInit user callbacks using HAL_QSPI_RegisterCallback before calling HAL_QSPI_DeInit or HAL_QSPI_Init function. When The compilation define USE_HAL_QSPI_REGISTER_CALLBACKS is set to 0 or not defined, the callback registering feature is not available and weak (surcharged) callbacks are used. *** Workarounds linked to Silicon Limitation *** ==================================================== [..] (#) Workarounds Implemented inside HAL Driver (++) Extra data written in the FIFO at the end of a read transfer @endverbatim ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f7xx_hal.h" #if defined(QUADSPI) /** @addtogroup STM32F7xx_HAL_Driver * @{ */ /** @defgroup QSPI QSPI * @brief QSPI HAL module driver * @{ */ #ifdef HAL_QSPI_MODULE_ENABLED /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /** @defgroup QSPI_Private_Constants QSPI Private Constants * @{ */ #define QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE 0x00000000U /*!<Indirect write mode*/ #define QSPI_FUNCTIONAL_MODE_INDIRECT_READ ((uint32_t)QUADSPI_CCR_FMODE_0) /*!<Indirect read mode*/ #define QSPI_FUNCTIONAL_MODE_AUTO_POLLING ((uint32_t)QUADSPI_CCR_FMODE_1) /*!<Automatic polling mode*/ #define QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED ((uint32_t)QUADSPI_CCR_FMODE) /*!<Memory-mapped mode*/ /** * @} */ /* Private macro -------------------------------------------------------------*/ /** @defgroup QSPI_Private_Macros QSPI Private Macros * @{ */ #define IS_QSPI_FUNCTIONAL_MODE(MODE) (((MODE) == QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE) || \ ((MODE) == QSPI_FUNCTIONAL_MODE_INDIRECT_READ) || \ ((MODE) == QSPI_FUNCTIONAL_MODE_AUTO_POLLING) || \ ((MODE) == QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED)) /** * @} */ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ static void QSPI_DMARxCplt(DMA_HandleTypeDef *hdma); static void QSPI_DMATxCplt(DMA_HandleTypeDef *hdma); static void QSPI_DMARxHalfCplt(DMA_HandleTypeDef *hdma); static void QSPI_DMATxHalfCplt(DMA_HandleTypeDef *hdma); static void QSPI_DMAError(DMA_HandleTypeDef *hdma); static void QSPI_DMAAbortCplt(DMA_HandleTypeDef *hdma); static HAL_StatusTypeDef QSPI_WaitFlagStateUntilTimeout(QSPI_HandleTypeDef *hqspi, uint32_t Flag, FlagStatus State, uint32_t Tickstart, uint32_t Timeout); static HAL_StatusTypeDef QSPI_WaitFlagStateUntilTimeout_CPUCycle(QSPI_HandleTypeDef *hqspi, uint32_t Flag, FlagStatus State, uint32_t Timeout); static void QSPI_Config(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, uint32_t FunctionalMode); /* Exported functions --------------------------------------------------------*/ /** @defgroup QSPI_Exported_Functions QSPI Exported Functions * @{ */ /** @defgroup QSPI_Exported_Functions_Group1 Initialization/de-initialization functions * @brief Initialization and Configuration functions * @verbatim =============================================================================== ##### Initialization and Configuration functions ##### =============================================================================== [..] This subsection provides a set of functions allowing to : (+) Initialize the QuadSPI. (+) De-initialize the QuadSPI. @endverbatim * @{ */ /** * @brief Initialize the QSPI mode according to the specified parameters * in the QSPI_InitTypeDef and initialize the associated handle. * @param hqspi : QSPI handle * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Init(QSPI_HandleTypeDef *hqspi) { HAL_StatusTypeDef status; uint32_t tickstart = HAL_GetTick(); /* Check the QSPI handle allocation */ if(hqspi == NULL) { return HAL_ERROR; } /* Check the parameters */ assert_param(IS_QSPI_ALL_INSTANCE(hqspi->Instance)); assert_param(IS_QSPI_CLOCK_PRESCALER(hqspi->Init.ClockPrescaler)); assert_param(IS_QSPI_FIFO_THRESHOLD(hqspi->Init.FifoThreshold)); assert_param(IS_QSPI_SSHIFT(hqspi->Init.SampleShifting)); assert_param(IS_QSPI_FLASH_SIZE(hqspi->Init.FlashSize)); assert_param(IS_QSPI_CS_HIGH_TIME(hqspi->Init.ChipSelectHighTime)); assert_param(IS_QSPI_CLOCK_MODE(hqspi->Init.ClockMode)); assert_param(IS_QSPI_DUAL_FLASH_MODE(hqspi->Init.DualFlash)); if (hqspi->Init.DualFlash != QSPI_DUALFLASH_ENABLE ) { assert_param(IS_QSPI_FLASH_ID(hqspi->Init.FlashID)); } if(hqspi->State == HAL_QSPI_STATE_RESET) { /* Allocate lock resource and initialize it */ hqspi->Lock = HAL_UNLOCKED; #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) /* Reset Callback pointers in HAL_QSPI_STATE_RESET only */ hqspi->ErrorCallback = HAL_QSPI_ErrorCallback; hqspi->AbortCpltCallback = HAL_QSPI_AbortCpltCallback; hqspi->FifoThresholdCallback = HAL_QSPI_FifoThresholdCallback; hqspi->CmdCpltCallback = HAL_QSPI_CmdCpltCallback; hqspi->RxCpltCallback = HAL_QSPI_RxCpltCallback; hqspi->TxCpltCallback = HAL_QSPI_TxCpltCallback; hqspi->RxHalfCpltCallback = HAL_QSPI_RxHalfCpltCallback; hqspi->TxHalfCpltCallback = HAL_QSPI_TxHalfCpltCallback; hqspi->StatusMatchCallback = HAL_QSPI_StatusMatchCallback; hqspi->TimeOutCallback = HAL_QSPI_TimeOutCallback; if(hqspi->MspInitCallback == NULL) { hqspi->MspInitCallback = HAL_QSPI_MspInit; } /* Init the low level hardware */ hqspi->MspInitCallback(hqspi); #else /* Init the low level hardware : GPIO, CLOCK */ HAL_QSPI_MspInit(hqspi); #endif /* Configure the default timeout for the QSPI memory access */ HAL_QSPI_SetTimeout(hqspi, HAL_QSPI_TIMEOUT_DEFAULT_VALUE); } /* Configure QSPI FIFO Threshold */ MODIFY_REG(hqspi->Instance->CR, QUADSPI_CR_FTHRES, ((hqspi->Init.FifoThreshold - 1U) << QUADSPI_CR_FTHRES_Pos)); /* Wait till BUSY flag reset */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_BUSY, RESET, tickstart, hqspi->Timeout); if(status == HAL_OK) { /* Configure QSPI Clock Prescaler and Sample Shift */ MODIFY_REG(hqspi->Instance->CR, (QUADSPI_CR_PRESCALER | QUADSPI_CR_SSHIFT | QUADSPI_CR_FSEL | QUADSPI_CR_DFM), ((hqspi->Init.ClockPrescaler << QUADSPI_CR_PRESCALER_Pos) | hqspi->Init.SampleShifting | hqspi->Init.FlashID | hqspi->Init.DualFlash)); /* Configure QSPI Flash Size, CS High Time and Clock Mode */ MODIFY_REG(hqspi->Instance->DCR, (QUADSPI_DCR_FSIZE | QUADSPI_DCR_CSHT | QUADSPI_DCR_CKMODE), ((hqspi->Init.FlashSize << QUADSPI_DCR_FSIZE_Pos) | hqspi->Init.ChipSelectHighTime | hqspi->Init.ClockMode)); /* Enable the QSPI peripheral */ __HAL_QSPI_ENABLE(hqspi); /* Set QSPI error code to none */ hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; /* Initialize the QSPI state */ hqspi->State = HAL_QSPI_STATE_READY; } /* Release Lock */ __HAL_UNLOCK(hqspi); /* Return function status */ return status; } /** * @brief De-Initialize the QSPI peripheral. * @param hqspi : QSPI handle * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_DeInit(QSPI_HandleTypeDef *hqspi) { /* Check the QSPI handle allocation */ if(hqspi == NULL) { return HAL_ERROR; } /* Disable the QSPI Peripheral Clock */ __HAL_QSPI_DISABLE(hqspi); #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) if(hqspi->MspDeInitCallback == NULL) { hqspi->MspDeInitCallback = HAL_QSPI_MspDeInit; } /* DeInit the low level hardware */ hqspi->MspDeInitCallback(hqspi); #else /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */ HAL_QSPI_MspDeInit(hqspi); #endif /* Set QSPI error code to none */ hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; /* Initialize the QSPI state */ hqspi->State = HAL_QSPI_STATE_RESET; /* Release Lock */ __HAL_UNLOCK(hqspi); return HAL_OK; } /** * @brief Initialize the QSPI MSP. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_MspInit(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE : This function should not be modified, when the callback is needed, the HAL_QSPI_MspInit can be implemented in the user file */ } /** * @brief DeInitialize the QSPI MSP. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE : This function should not be modified, when the callback is needed, the HAL_QSPI_MspDeInit can be implemented in the user file */ } /** * @} */ /** @defgroup QSPI_Exported_Functions_Group2 Input and Output operation functions * @brief QSPI Transmit/Receive functions * @verbatim =============================================================================== ##### IO operation functions ##### =============================================================================== [..] This subsection provides a set of functions allowing to : (+) Handle the interrupts. (+) Handle the command sequence. (+) Transmit data in blocking, interrupt or DMA mode. (+) Receive data in blocking, interrupt or DMA mode. (+) Manage the auto-polling functional mode. (+) Manage the memory-mapped functional mode. @endverbatim * @{ */ /** * @brief Handle QSPI interrupt request. * @param hqspi : QSPI handle * @retval None */ void HAL_QSPI_IRQHandler(QSPI_HandleTypeDef *hqspi) { __IO uint32_t *data_reg; uint32_t flag = READ_REG(hqspi->Instance->SR); uint32_t itsource = READ_REG(hqspi->Instance->CR); /* QSPI Fifo Threshold interrupt occurred ----------------------------------*/ if(((flag & QSPI_FLAG_FT) != 0U) && ((itsource & QSPI_IT_FT) != 0U)) { data_reg = &hqspi->Instance->DR; if(hqspi->State == HAL_QSPI_STATE_BUSY_INDIRECT_TX) { /* Transmission process */ while(__HAL_QSPI_GET_FLAG(hqspi, QSPI_FLAG_FT) != RESET) { if (hqspi->TxXferCount > 0U) { /* Fill the FIFO until the threshold is reached */ *((__IO uint8_t *)data_reg) = *hqspi->pTxBuffPtr; hqspi->pTxBuffPtr++; hqspi->TxXferCount--; } else { /* No more data available for the transfer */ /* Disable the QSPI FIFO Threshold Interrupt */ __HAL_QSPI_DISABLE_IT(hqspi, QSPI_IT_FT); break; } } } else if(hqspi->State == HAL_QSPI_STATE_BUSY_INDIRECT_RX) { /* Receiving Process */ while(__HAL_QSPI_GET_FLAG(hqspi, QSPI_FLAG_FT) != RESET) { if (hqspi->RxXferCount > 0U) { /* Read the FIFO until the threshold is reached */ *hqspi->pRxBuffPtr = *((__IO uint8_t *)data_reg); hqspi->pRxBuffPtr++; hqspi->RxXferCount--; } else { /* All data have been received for the transfer */ /* Disable the QSPI FIFO Threshold Interrupt */ __HAL_QSPI_DISABLE_IT(hqspi, QSPI_IT_FT); break; } } } else { /* Nothing to do */ } /* FIFO Threshold callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->FifoThresholdCallback(hqspi); #else HAL_QSPI_FifoThresholdCallback(hqspi); #endif } /* QSPI Transfer Complete interrupt occurred -------------------------------*/ else if(((flag & QSPI_FLAG_TC) != 0U) && ((itsource & QSPI_IT_TC) != 0U)) { /* Clear interrupt */ WRITE_REG(hqspi->Instance->FCR, QSPI_FLAG_TC); /* Disable the QSPI FIFO Threshold, Transfer Error and Transfer complete Interrupts */ __HAL_QSPI_DISABLE_IT(hqspi, QSPI_IT_TC | QSPI_IT_TE | QSPI_IT_FT); /* Transfer complete callback */ if(hqspi->State == HAL_QSPI_STATE_BUSY_INDIRECT_TX) { if ((hqspi->Instance->CR & QUADSPI_CR_DMAEN) != 0U) { /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */ CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN); /* Disable the DMA channel */ __HAL_DMA_DISABLE(hqspi->hdma); } #if defined(QSPI1_V1_0) /* Clear Busy bit */ HAL_QSPI_Abort_IT(hqspi); #endif /* Change state of QSPI */ hqspi->State = HAL_QSPI_STATE_READY; /* TX Complete callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->TxCpltCallback(hqspi); #else HAL_QSPI_TxCpltCallback(hqspi); #endif } else if(hqspi->State == HAL_QSPI_STATE_BUSY_INDIRECT_RX) { if ((hqspi->Instance->CR & QUADSPI_CR_DMAEN) != 0U) { /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */ CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN); /* Disable the DMA channel */ __HAL_DMA_DISABLE(hqspi->hdma); } else { data_reg = &hqspi->Instance->DR; while(READ_BIT(hqspi->Instance->SR, QUADSPI_SR_FLEVEL) != 0U) { if (hqspi->RxXferCount > 0U) { /* Read the last data received in the FIFO until it is empty */ *hqspi->pRxBuffPtr = *((__IO uint8_t *)data_reg); hqspi->pRxBuffPtr++; hqspi->RxXferCount--; } else { /* All data have been received for the transfer */ break; } } } #if defined(QSPI1_V1_0) /* Workaround - Extra data written in the FIFO at the end of a read transfer */ HAL_QSPI_Abort_IT(hqspi); #endif /* Change state of QSPI */ hqspi->State = HAL_QSPI_STATE_READY; /* RX Complete callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->RxCpltCallback(hqspi); #else HAL_QSPI_RxCpltCallback(hqspi); #endif } else if(hqspi->State == HAL_QSPI_STATE_BUSY) { /* Change state of QSPI */ hqspi->State = HAL_QSPI_STATE_READY; /* Command Complete callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->CmdCpltCallback(hqspi); #else HAL_QSPI_CmdCpltCallback(hqspi); #endif } else if(hqspi->State == HAL_QSPI_STATE_ABORT) { /* Reset functional mode configuration to indirect write mode by default */ CLEAR_BIT(hqspi->Instance->CCR, QUADSPI_CCR_FMODE); /* Change state of QSPI */ hqspi->State = HAL_QSPI_STATE_READY; if (hqspi->ErrorCode == HAL_QSPI_ERROR_NONE) { /* Abort called by the user */ /* Abort Complete callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->AbortCpltCallback(hqspi); #else HAL_QSPI_AbortCpltCallback(hqspi); #endif } else { /* Abort due to an error (eg : DMA error) */ /* Error callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->ErrorCallback(hqspi); #else HAL_QSPI_ErrorCallback(hqspi); #endif } } else { /* Nothing to do */ } } /* QSPI Status Match interrupt occurred ------------------------------------*/ else if(((flag & QSPI_FLAG_SM) != 0U) && ((itsource & QSPI_IT_SM) != 0U)) { /* Clear interrupt */ WRITE_REG(hqspi->Instance->FCR, QSPI_FLAG_SM); /* Check if the automatic poll mode stop is activated */ if(READ_BIT(hqspi->Instance->CR, QUADSPI_CR_APMS) != 0U) { /* Disable the QSPI Transfer Error and Status Match Interrupts */ __HAL_QSPI_DISABLE_IT(hqspi, (QSPI_IT_SM | QSPI_IT_TE)); /* Change state of QSPI */ hqspi->State = HAL_QSPI_STATE_READY; } /* Status match callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->StatusMatchCallback(hqspi); #else HAL_QSPI_StatusMatchCallback(hqspi); #endif } /* QSPI Transfer Error interrupt occurred ----------------------------------*/ else if(((flag & QSPI_FLAG_TE) != 0U) && ((itsource & QSPI_IT_TE) != 0U)) { /* Clear interrupt */ WRITE_REG(hqspi->Instance->FCR, QSPI_FLAG_TE); /* Disable all the QSPI Interrupts */ __HAL_QSPI_DISABLE_IT(hqspi, QSPI_IT_SM | QSPI_IT_TC | QSPI_IT_TE | QSPI_IT_FT); /* Set error code */ hqspi->ErrorCode |= HAL_QSPI_ERROR_TRANSFER; if ((hqspi->Instance->CR & QUADSPI_CR_DMAEN) != 0U) { /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */ CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN); /* Disable the DMA channel */ hqspi->hdma->XferAbortCallback = QSPI_DMAAbortCplt; if (HAL_DMA_Abort_IT(hqspi->hdma) != HAL_OK) { /* Set error code to DMA */ hqspi->ErrorCode |= HAL_QSPI_ERROR_DMA; /* Change state of QSPI */ hqspi->State = HAL_QSPI_STATE_READY; /* Error callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->ErrorCallback(hqspi); #else HAL_QSPI_ErrorCallback(hqspi); #endif } } else { /* Change state of QSPI */ hqspi->State = HAL_QSPI_STATE_READY; /* Error callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->ErrorCallback(hqspi); #else HAL_QSPI_ErrorCallback(hqspi); #endif } } /* QSPI Timeout interrupt occurred -----------------------------------------*/ else if(((flag & QSPI_FLAG_TO) != 0U) && ((itsource & QSPI_IT_TO) != 0U)) { /* Clear interrupt */ WRITE_REG(hqspi->Instance->FCR, QSPI_FLAG_TO); /* Timeout callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->TimeOutCallback(hqspi); #else HAL_QSPI_TimeOutCallback(hqspi); #endif } else { /* Nothing to do */ } } /** * @brief Set the command configuration. * @param hqspi : QSPI handle * @param cmd : structure that contains the command configuration information * @param Timeout : Timeout duration * @note This function is used only in Indirect Read or Write Modes * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Command(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, uint32_t Timeout) { HAL_StatusTypeDef status; uint32_t tickstart = HAL_GetTick(); /* Check the parameters */ assert_param(IS_QSPI_INSTRUCTION_MODE(cmd->InstructionMode)); if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE) { assert_param(IS_QSPI_INSTRUCTION(cmd->Instruction)); } assert_param(IS_QSPI_ADDRESS_MODE(cmd->AddressMode)); if (cmd->AddressMode != QSPI_ADDRESS_NONE) { assert_param(IS_QSPI_ADDRESS_SIZE(cmd->AddressSize)); } assert_param(IS_QSPI_ALTERNATE_BYTES_MODE(cmd->AlternateByteMode)); if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE) { assert_param(IS_QSPI_ALTERNATE_BYTES_SIZE(cmd->AlternateBytesSize)); } assert_param(IS_QSPI_DUMMY_CYCLES(cmd->DummyCycles)); assert_param(IS_QSPI_DATA_MODE(cmd->DataMode)); assert_param(IS_QSPI_DDR_MODE(cmd->DdrMode)); assert_param(IS_QSPI_DDR_HHC(cmd->DdrHoldHalfCycle)); assert_param(IS_QSPI_SIOO_MODE(cmd->SIOOMode)); /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; /* Update QSPI state */ hqspi->State = HAL_QSPI_STATE_BUSY; /* Wait till BUSY flag reset */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_BUSY, RESET, tickstart, Timeout); if (status == HAL_OK) { /* Call the configuration function */ QSPI_Config(hqspi, cmd, QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE); if (cmd->DataMode == QSPI_DATA_NONE) { /* When there is no data phase, the transfer start as soon as the configuration is done so wait until TC flag is set to go back in idle state */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_TC, SET, tickstart, Timeout); if (status == HAL_OK) { __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC); /* Update QSPI state */ hqspi->State = HAL_QSPI_STATE_READY; } } else { /* Update QSPI state */ hqspi->State = HAL_QSPI_STATE_READY; } } } else { status = HAL_BUSY; } /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Return function status */ return status; } /** * @brief Set the command configuration in interrupt mode. * @param hqspi : QSPI handle * @param cmd : structure that contains the command configuration information * @note This function is used only in Indirect Read or Write Modes * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Command_IT(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd) { HAL_StatusTypeDef status; /* Check the parameters */ assert_param(IS_QSPI_INSTRUCTION_MODE(cmd->InstructionMode)); if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE) { assert_param(IS_QSPI_INSTRUCTION(cmd->Instruction)); } assert_param(IS_QSPI_ADDRESS_MODE(cmd->AddressMode)); if (cmd->AddressMode != QSPI_ADDRESS_NONE) { assert_param(IS_QSPI_ADDRESS_SIZE(cmd->AddressSize)); } assert_param(IS_QSPI_ALTERNATE_BYTES_MODE(cmd->AlternateByteMode)); if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE) { assert_param(IS_QSPI_ALTERNATE_BYTES_SIZE(cmd->AlternateBytesSize)); } assert_param(IS_QSPI_DUMMY_CYCLES(cmd->DummyCycles)); assert_param(IS_QSPI_DATA_MODE(cmd->DataMode)); assert_param(IS_QSPI_DDR_MODE(cmd->DdrMode)); assert_param(IS_QSPI_DDR_HHC(cmd->DdrHoldHalfCycle)); assert_param(IS_QSPI_SIOO_MODE(cmd->SIOOMode)); /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; /* Update QSPI state */ hqspi->State = HAL_QSPI_STATE_BUSY; /* Wait till BUSY flag reset */ status = QSPI_WaitFlagStateUntilTimeout_CPUCycle(hqspi, QSPI_FLAG_BUSY, RESET, hqspi->Timeout); if (status == HAL_OK) { if (cmd->DataMode == QSPI_DATA_NONE) { /* Clear interrupt */ __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TE | QSPI_FLAG_TC); } /* Call the configuration function */ QSPI_Config(hqspi, cmd, QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE); if (cmd->DataMode == QSPI_DATA_NONE) { /* When there is no data phase, the transfer start as soon as the configuration is done so activate TC and TE interrupts */ /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Enable the QSPI Transfer Error Interrupt */ __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE | QSPI_IT_TC); } else { /* Update QSPI state */ hqspi->State = HAL_QSPI_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hqspi); } } else { /* Process unlocked */ __HAL_UNLOCK(hqspi); } } else { status = HAL_BUSY; /* Process unlocked */ __HAL_UNLOCK(hqspi); } /* Return function status */ return status; } /** * @brief Transmit an amount of data in blocking mode. * @param hqspi : QSPI handle * @param pData : pointer to data buffer * @param Timeout : Timeout duration * @note This function is used only in Indirect Write Mode * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Transmit(QSPI_HandleTypeDef *hqspi, uint8_t *pData, uint32_t Timeout) { HAL_StatusTypeDef status = HAL_OK; uint32_t tickstart = HAL_GetTick(); __IO uint32_t *data_reg = &hqspi->Instance->DR; /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; if(pData != NULL ) { /* Update state */ hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_TX; /* Configure counters and size of the handle */ hqspi->TxXferCount = READ_REG(hqspi->Instance->DLR) + 1U; hqspi->TxXferSize = READ_REG(hqspi->Instance->DLR) + 1U; hqspi->pTxBuffPtr = pData; /* Configure QSPI: CCR register with functional as indirect write */ MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE); while(hqspi->TxXferCount > 0U) { /* Wait until FT flag is set to send data */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_FT, SET, tickstart, Timeout); if (status != HAL_OK) { break; } *((__IO uint8_t *)data_reg) = *hqspi->pTxBuffPtr; hqspi->pTxBuffPtr++; hqspi->TxXferCount--; } if (status == HAL_OK) { /* Wait until TC flag is set to go back in idle state */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_TC, SET, tickstart, Timeout); if (status == HAL_OK) { /* Clear Transfer Complete bit */ __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC); #if defined(QSPI1_V1_0) /* Clear Busy bit */ status = HAL_QSPI_Abort(hqspi); #endif } } /* Update QSPI state */ hqspi->State = HAL_QSPI_STATE_READY; } else { hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM; status = HAL_ERROR; } } else { status = HAL_BUSY; } /* Process unlocked */ __HAL_UNLOCK(hqspi); return status; } /** * @brief Receive an amount of data in blocking mode. * @param hqspi : QSPI handle * @param pData : pointer to data buffer * @param Timeout : Timeout duration * @note This function is used only in Indirect Read Mode * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Receive(QSPI_HandleTypeDef *hqspi, uint8_t *pData, uint32_t Timeout) { HAL_StatusTypeDef status = HAL_OK; uint32_t tickstart = HAL_GetTick(); uint32_t addr_reg = READ_REG(hqspi->Instance->AR); __IO uint32_t *data_reg = &hqspi->Instance->DR; /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; if(pData != NULL ) { /* Update state */ hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_RX; /* Configure counters and size of the handle */ hqspi->RxXferCount = READ_REG(hqspi->Instance->DLR) + 1U; hqspi->RxXferSize = READ_REG(hqspi->Instance->DLR) + 1U; hqspi->pRxBuffPtr = pData; /* Configure QSPI: CCR register with functional as indirect read */ MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_READ); /* Start the transfer by re-writing the address in AR register */ WRITE_REG(hqspi->Instance->AR, addr_reg); while(hqspi->RxXferCount > 0U) { /* Wait until FT or TC flag is set to read received data */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, (QSPI_FLAG_FT | QSPI_FLAG_TC), SET, tickstart, Timeout); if (status != HAL_OK) { break; } *hqspi->pRxBuffPtr = *((__IO uint8_t *)data_reg); hqspi->pRxBuffPtr++; hqspi->RxXferCount--; } if (status == HAL_OK) { /* Wait until TC flag is set to go back in idle state */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_TC, SET, tickstart, Timeout); if (status == HAL_OK) { /* Clear Transfer Complete bit */ __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC); #if defined(QSPI1_V1_0) /* Workaround - Extra data written in the FIFO at the end of a read transfer */ status = HAL_QSPI_Abort(hqspi); #endif } } /* Update QSPI state */ hqspi->State = HAL_QSPI_STATE_READY; } else { hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM; status = HAL_ERROR; } } else { status = HAL_BUSY; } /* Process unlocked */ __HAL_UNLOCK(hqspi); return status; } /** * @brief Send an amount of data in non-blocking mode with interrupt. * @param hqspi : QSPI handle * @param pData : pointer to data buffer * @note This function is used only in Indirect Write Mode * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Transmit_IT(QSPI_HandleTypeDef *hqspi, uint8_t *pData) { HAL_StatusTypeDef status = HAL_OK; /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; if(pData != NULL ) { /* Update state */ hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_TX; /* Configure counters and size of the handle */ hqspi->TxXferCount = READ_REG(hqspi->Instance->DLR) + 1U; hqspi->TxXferSize = READ_REG(hqspi->Instance->DLR) + 1U; hqspi->pTxBuffPtr = pData; /* Clear interrupt */ __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TE | QSPI_FLAG_TC); /* Configure QSPI: CCR register with functional as indirect write */ MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE); /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Enable the QSPI transfer error, FIFO threshold and transfer complete Interrupts */ __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE | QSPI_IT_FT | QSPI_IT_TC); } else { hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM; status = HAL_ERROR; /* Process unlocked */ __HAL_UNLOCK(hqspi); } } else { status = HAL_BUSY; /* Process unlocked */ __HAL_UNLOCK(hqspi); } return status; } /** * @brief Receive an amount of data in non-blocking mode with interrupt. * @param hqspi : QSPI handle * @param pData : pointer to data buffer * @note This function is used only in Indirect Read Mode * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Receive_IT(QSPI_HandleTypeDef *hqspi, uint8_t *pData) { HAL_StatusTypeDef status = HAL_OK; uint32_t addr_reg = READ_REG(hqspi->Instance->AR); /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; if(pData != NULL ) { /* Update state */ hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_RX; /* Configure counters and size of the handle */ hqspi->RxXferCount = READ_REG(hqspi->Instance->DLR) + 1U; hqspi->RxXferSize = READ_REG(hqspi->Instance->DLR) + 1U; hqspi->pRxBuffPtr = pData; /* Clear interrupt */ __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TE | QSPI_FLAG_TC); /* Configure QSPI: CCR register with functional as indirect read */ MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_READ); /* Start the transfer by re-writing the address in AR register */ WRITE_REG(hqspi->Instance->AR, addr_reg); /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Enable the QSPI transfer error, FIFO threshold and transfer complete Interrupts */ __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE | QSPI_IT_FT | QSPI_IT_TC); } else { hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM; status = HAL_ERROR; /* Process unlocked */ __HAL_UNLOCK(hqspi); } } else { status = HAL_BUSY; /* Process unlocked */ __HAL_UNLOCK(hqspi); } return status; } /** * @brief Send an amount of data in non-blocking mode with DMA. * @param hqspi : QSPI handle * @param pData : pointer to data buffer * @note This function is used only in Indirect Write Mode * @note If DMA peripheral access is configured as halfword, the number * of data and the fifo threshold should be aligned on halfword * @note If DMA peripheral access is configured as word, the number * of data and the fifo threshold should be aligned on word * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Transmit_DMA(QSPI_HandleTypeDef *hqspi, uint8_t *pData) { HAL_StatusTypeDef status = HAL_OK; uint32_t data_size = (READ_REG(hqspi->Instance->DLR) + 1U); /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { /* Clear the error code */ hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; if(pData != NULL ) { /* Configure counters of the handle */ if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE) { hqspi->TxXferCount = data_size; } else if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_HALFWORD) { if (((data_size % 2U) != 0U) || ((hqspi->Init.FifoThreshold % 2U) != 0U)) { /* The number of data or the fifo threshold is not aligned on halfword => no transfer possible with DMA peripheral access configured as halfword */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM; status = HAL_ERROR; /* Process unlocked */ __HAL_UNLOCK(hqspi); } else { hqspi->TxXferCount = (data_size >> 1U); } } else if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_WORD) { if (((data_size % 4U) != 0U) || ((hqspi->Init.FifoThreshold % 4U) != 0U)) { /* The number of data or the fifo threshold is not aligned on word => no transfer possible with DMA peripheral access configured as word */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM; status = HAL_ERROR; /* Process unlocked */ __HAL_UNLOCK(hqspi); } else { hqspi->TxXferCount = (data_size >> 2U); } } else { /* Nothing to do */ } if (status == HAL_OK) { /* Update state */ hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_TX; /* Clear interrupt */ __HAL_QSPI_CLEAR_FLAG(hqspi, (QSPI_FLAG_TE | QSPI_FLAG_TC)); /* Configure size and pointer of the handle */ hqspi->TxXferSize = hqspi->TxXferCount; hqspi->pTxBuffPtr = pData; /* Configure QSPI: CCR register with functional mode as indirect write */ MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE); /* Set the QSPI DMA transfer complete callback */ hqspi->hdma->XferCpltCallback = QSPI_DMATxCplt; /* Set the QSPI DMA Half transfer complete callback */ hqspi->hdma->XferHalfCpltCallback = QSPI_DMATxHalfCplt; /* Set the DMA error callback */ hqspi->hdma->XferErrorCallback = QSPI_DMAError; /* Clear the DMA abort callback */ hqspi->hdma->XferAbortCallback = NULL; /* Configure the direction of the DMA */ hqspi->hdma->Init.Direction = DMA_MEMORY_TO_PERIPH; MODIFY_REG(hqspi->hdma->Instance->CR, DMA_SxCR_DIR, hqspi->hdma->Init.Direction); /* Enable the QSPI transmit DMA Channel */ if (HAL_DMA_Start_IT(hqspi->hdma, (uint32_t)pData, (uint32_t)&hqspi->Instance->DR, hqspi->TxXferSize) == HAL_OK) { /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Enable the QSPI transfer error Interrupt */ __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE); /* Enable the DMA transfer by setting the DMAEN bit in the QSPI CR register */ SET_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN); } else { status = HAL_ERROR; hqspi->ErrorCode |= HAL_QSPI_ERROR_DMA; hqspi->State = HAL_QSPI_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hqspi); } } } else { hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM; status = HAL_ERROR; /* Process unlocked */ __HAL_UNLOCK(hqspi); } } else { status = HAL_BUSY; /* Process unlocked */ __HAL_UNLOCK(hqspi); } return status; } /** * @brief Receive an amount of data in non-blocking mode with DMA. * @param hqspi : QSPI handle * @param pData : pointer to data buffer. * @note This function is used only in Indirect Read Mode * @note If DMA peripheral access is configured as halfword, the number * of data and the fifo threshold should be aligned on halfword * @note If DMA peripheral access is configured as word, the number * of data and the fifo threshold should be aligned on word * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Receive_DMA(QSPI_HandleTypeDef *hqspi, uint8_t *pData) { HAL_StatusTypeDef status = HAL_OK; uint32_t addr_reg = READ_REG(hqspi->Instance->AR); uint32_t data_size = (READ_REG(hqspi->Instance->DLR) + 1U); /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { /* Clear the error code */ hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; if(pData != NULL ) { /* Configure counters of the handle */ if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_BYTE) { hqspi->RxXferCount = data_size; } else if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_HALFWORD) { if (((data_size % 2U) != 0U) || ((hqspi->Init.FifoThreshold % 2U) != 0U)) { /* The number of data or the fifo threshold is not aligned on halfword => no transfer possible with DMA peripheral access configured as halfword */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM; status = HAL_ERROR; /* Process unlocked */ __HAL_UNLOCK(hqspi); } else { hqspi->RxXferCount = (data_size >> 1U); } } else if (hqspi->hdma->Init.PeriphDataAlignment == DMA_PDATAALIGN_WORD) { if (((data_size % 4U) != 0U) || ((hqspi->Init.FifoThreshold % 4U) != 0U)) { /* The number of data or the fifo threshold is not aligned on word => no transfer possible with DMA peripheral access configured as word */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM; status = HAL_ERROR; /* Process unlocked */ __HAL_UNLOCK(hqspi); } else { hqspi->RxXferCount = (data_size >> 2U); } } else { /* Nothing to do */ } if (status == HAL_OK) { /* Update state */ hqspi->State = HAL_QSPI_STATE_BUSY_INDIRECT_RX; /* Clear interrupt */ __HAL_QSPI_CLEAR_FLAG(hqspi, (QSPI_FLAG_TE | QSPI_FLAG_TC)); /* Configure size and pointer of the handle */ hqspi->RxXferSize = hqspi->RxXferCount; hqspi->pRxBuffPtr = pData; /* Set the QSPI DMA transfer complete callback */ hqspi->hdma->XferCpltCallback = QSPI_DMARxCplt; /* Set the QSPI DMA Half transfer complete callback */ hqspi->hdma->XferHalfCpltCallback = QSPI_DMARxHalfCplt; /* Set the DMA error callback */ hqspi->hdma->XferErrorCallback = QSPI_DMAError; /* Clear the DMA abort callback */ hqspi->hdma->XferAbortCallback = NULL; /* Configure the direction of the DMA */ hqspi->hdma->Init.Direction = DMA_PERIPH_TO_MEMORY; MODIFY_REG(hqspi->hdma->Instance->CR, DMA_SxCR_DIR, hqspi->hdma->Init.Direction); /* Enable the DMA Channel */ if (HAL_DMA_Start_IT(hqspi->hdma, (uint32_t)&hqspi->Instance->DR, (uint32_t)pData, hqspi->RxXferSize) == HAL_OK) { /* Configure QSPI: CCR register with functional as indirect read */ MODIFY_REG(hqspi->Instance->CCR, QUADSPI_CCR_FMODE, QSPI_FUNCTIONAL_MODE_INDIRECT_READ); /* Start the transfer by re-writing the address in AR register */ WRITE_REG(hqspi->Instance->AR, addr_reg); /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Enable the QSPI transfer error Interrupt */ __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TE); /* Enable the DMA transfer by setting the DMAEN bit in the QSPI CR register */ SET_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN); } else { status = HAL_ERROR; hqspi->ErrorCode |= HAL_QSPI_ERROR_DMA; hqspi->State = HAL_QSPI_STATE_READY; /* Process unlocked */ __HAL_UNLOCK(hqspi); } } } else { hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_PARAM; status = HAL_ERROR; /* Process unlocked */ __HAL_UNLOCK(hqspi); } } else { status = HAL_BUSY; /* Process unlocked */ __HAL_UNLOCK(hqspi); } return status; } /** * @brief Configure the QSPI Automatic Polling Mode in blocking mode. * @param hqspi : QSPI handle * @param cmd : structure that contains the command configuration information. * @param cfg : structure that contains the polling configuration information. * @param Timeout : Timeout duration * @note This function is used only in Automatic Polling Mode * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_AutoPolling(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, QSPI_AutoPollingTypeDef *cfg, uint32_t Timeout) { HAL_StatusTypeDef status; uint32_t tickstart = HAL_GetTick(); /* Check the parameters */ assert_param(IS_QSPI_INSTRUCTION_MODE(cmd->InstructionMode)); if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE) { assert_param(IS_QSPI_INSTRUCTION(cmd->Instruction)); } assert_param(IS_QSPI_ADDRESS_MODE(cmd->AddressMode)); if (cmd->AddressMode != QSPI_ADDRESS_NONE) { assert_param(IS_QSPI_ADDRESS_SIZE(cmd->AddressSize)); } assert_param(IS_QSPI_ALTERNATE_BYTES_MODE(cmd->AlternateByteMode)); if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE) { assert_param(IS_QSPI_ALTERNATE_BYTES_SIZE(cmd->AlternateBytesSize)); } assert_param(IS_QSPI_DUMMY_CYCLES(cmd->DummyCycles)); assert_param(IS_QSPI_DATA_MODE(cmd->DataMode)); assert_param(IS_QSPI_DDR_MODE(cmd->DdrMode)); assert_param(IS_QSPI_DDR_HHC(cmd->DdrHoldHalfCycle)); assert_param(IS_QSPI_SIOO_MODE(cmd->SIOOMode)); assert_param(IS_QSPI_INTERVAL(cfg->Interval)); assert_param(IS_QSPI_STATUS_BYTES_SIZE(cfg->StatusBytesSize)); assert_param(IS_QSPI_MATCH_MODE(cfg->MatchMode)); /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; /* Update state */ hqspi->State = HAL_QSPI_STATE_BUSY_AUTO_POLLING; /* Wait till BUSY flag reset */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_BUSY, RESET, tickstart, Timeout); if (status == HAL_OK) { /* Configure QSPI: PSMAR register with the status match value */ WRITE_REG(hqspi->Instance->PSMAR, cfg->Match); /* Configure QSPI: PSMKR register with the status mask value */ WRITE_REG(hqspi->Instance->PSMKR, cfg->Mask); /* Configure QSPI: PIR register with the interval value */ WRITE_REG(hqspi->Instance->PIR, cfg->Interval); /* Configure QSPI: CR register with Match mode and Automatic stop enabled (otherwise there will be an infinite loop in blocking mode) */ MODIFY_REG(hqspi->Instance->CR, (QUADSPI_CR_PMM | QUADSPI_CR_APMS), (cfg->MatchMode | QSPI_AUTOMATIC_STOP_ENABLE)); /* Call the configuration function */ cmd->NbData = cfg->StatusBytesSize; QSPI_Config(hqspi, cmd, QSPI_FUNCTIONAL_MODE_AUTO_POLLING); /* Wait until SM flag is set to go back in idle state */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_SM, SET, tickstart, Timeout); if (status == HAL_OK) { __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_SM); /* Update state */ hqspi->State = HAL_QSPI_STATE_READY; } } } else { status = HAL_BUSY; } /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Return function status */ return status; } /** * @brief Configure the QSPI Automatic Polling Mode in non-blocking mode. * @param hqspi : QSPI handle * @param cmd : structure that contains the command configuration information. * @param cfg : structure that contains the polling configuration information. * @note This function is used only in Automatic Polling Mode * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_AutoPolling_IT(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, QSPI_AutoPollingTypeDef *cfg) { HAL_StatusTypeDef status; /* Check the parameters */ assert_param(IS_QSPI_INSTRUCTION_MODE(cmd->InstructionMode)); if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE) { assert_param(IS_QSPI_INSTRUCTION(cmd->Instruction)); } assert_param(IS_QSPI_ADDRESS_MODE(cmd->AddressMode)); if (cmd->AddressMode != QSPI_ADDRESS_NONE) { assert_param(IS_QSPI_ADDRESS_SIZE(cmd->AddressSize)); } assert_param(IS_QSPI_ALTERNATE_BYTES_MODE(cmd->AlternateByteMode)); if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE) { assert_param(IS_QSPI_ALTERNATE_BYTES_SIZE(cmd->AlternateBytesSize)); } assert_param(IS_QSPI_DUMMY_CYCLES(cmd->DummyCycles)); assert_param(IS_QSPI_DATA_MODE(cmd->DataMode)); assert_param(IS_QSPI_DDR_MODE(cmd->DdrMode)); assert_param(IS_QSPI_DDR_HHC(cmd->DdrHoldHalfCycle)); assert_param(IS_QSPI_SIOO_MODE(cmd->SIOOMode)); assert_param(IS_QSPI_INTERVAL(cfg->Interval)); assert_param(IS_QSPI_STATUS_BYTES_SIZE(cfg->StatusBytesSize)); assert_param(IS_QSPI_MATCH_MODE(cfg->MatchMode)); assert_param(IS_QSPI_AUTOMATIC_STOP(cfg->AutomaticStop)); /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; /* Update state */ hqspi->State = HAL_QSPI_STATE_BUSY_AUTO_POLLING; /* Wait till BUSY flag reset */ status = QSPI_WaitFlagStateUntilTimeout_CPUCycle(hqspi, QSPI_FLAG_BUSY, RESET, hqspi->Timeout); if (status == HAL_OK) { /* Configure QSPI: PSMAR register with the status match value */ WRITE_REG(hqspi->Instance->PSMAR, cfg->Match); /* Configure QSPI: PSMKR register with the status mask value */ WRITE_REG(hqspi->Instance->PSMKR, cfg->Mask); /* Configure QSPI: PIR register with the interval value */ WRITE_REG(hqspi->Instance->PIR, cfg->Interval); /* Configure QSPI: CR register with Match mode and Automatic stop mode */ MODIFY_REG(hqspi->Instance->CR, (QUADSPI_CR_PMM | QUADSPI_CR_APMS), (cfg->MatchMode | cfg->AutomaticStop)); /* Clear interrupt */ __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TE | QSPI_FLAG_SM); /* Call the configuration function */ cmd->NbData = cfg->StatusBytesSize; QSPI_Config(hqspi, cmd, QSPI_FUNCTIONAL_MODE_AUTO_POLLING); /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Enable the QSPI Transfer Error and status match Interrupt */ __HAL_QSPI_ENABLE_IT(hqspi, (QSPI_IT_SM | QSPI_IT_TE)); } else { /* Process unlocked */ __HAL_UNLOCK(hqspi); } } else { status = HAL_BUSY; /* Process unlocked */ __HAL_UNLOCK(hqspi); } /* Return function status */ return status; } /** * @brief Configure the Memory Mapped mode. * @param hqspi : QSPI handle * @param cmd : structure that contains the command configuration information. * @param cfg : structure that contains the memory mapped configuration information. * @note This function is used only in Memory mapped Mode * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_MemoryMapped(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, QSPI_MemoryMappedTypeDef *cfg) { HAL_StatusTypeDef status; uint32_t tickstart = HAL_GetTick(); /* Check the parameters */ assert_param(IS_QSPI_INSTRUCTION_MODE(cmd->InstructionMode)); if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE) { assert_param(IS_QSPI_INSTRUCTION(cmd->Instruction)); } assert_param(IS_QSPI_ADDRESS_MODE(cmd->AddressMode)); if (cmd->AddressMode != QSPI_ADDRESS_NONE) { assert_param(IS_QSPI_ADDRESS_SIZE(cmd->AddressSize)); } assert_param(IS_QSPI_ALTERNATE_BYTES_MODE(cmd->AlternateByteMode)); if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE) { assert_param(IS_QSPI_ALTERNATE_BYTES_SIZE(cmd->AlternateBytesSize)); } assert_param(IS_QSPI_DUMMY_CYCLES(cmd->DummyCycles)); assert_param(IS_QSPI_DATA_MODE(cmd->DataMode)); assert_param(IS_QSPI_DDR_MODE(cmd->DdrMode)); assert_param(IS_QSPI_DDR_HHC(cmd->DdrHoldHalfCycle)); assert_param(IS_QSPI_SIOO_MODE(cmd->SIOOMode)); assert_param(IS_QSPI_TIMEOUT_ACTIVATION(cfg->TimeOutActivation)); /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { hqspi->ErrorCode = HAL_QSPI_ERROR_NONE; /* Update state */ hqspi->State = HAL_QSPI_STATE_BUSY_MEM_MAPPED; /* Wait till BUSY flag reset */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_BUSY, RESET, tickstart, hqspi->Timeout); if (status == HAL_OK) { /* Configure QSPI: CR register with timeout counter enable */ MODIFY_REG(hqspi->Instance->CR, QUADSPI_CR_TCEN, cfg->TimeOutActivation); if (cfg->TimeOutActivation == QSPI_TIMEOUT_COUNTER_ENABLE) { assert_param(IS_QSPI_TIMEOUT_PERIOD(cfg->TimeOutPeriod)); /* Configure QSPI: LPTR register with the low-power timeout value */ WRITE_REG(hqspi->Instance->LPTR, cfg->TimeOutPeriod); /* Clear interrupt */ __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TO); /* Enable the QSPI TimeOut Interrupt */ __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TO); } /* Call the configuration function */ QSPI_Config(hqspi, cmd, QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED); } } else { status = HAL_BUSY; } /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Return function status */ return status; } /** * @brief Transfer Error callback. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_ErrorCallback(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE : This function should not be modified, when the callback is needed, the HAL_QSPI_ErrorCallback could be implemented in the user file */ } /** * @brief Abort completed callback. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_AbortCpltCallback(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE: This function should not be modified, when the callback is needed, the HAL_QSPI_AbortCpltCallback could be implemented in the user file */ } /** * @brief Command completed callback. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_CmdCpltCallback(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE: This function should not be modified, when the callback is needed, the HAL_QSPI_CmdCpltCallback could be implemented in the user file */ } /** * @brief Rx Transfer completed callback. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_RxCpltCallback(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE: This function should not be modified, when the callback is needed, the HAL_QSPI_RxCpltCallback could be implemented in the user file */ } /** * @brief Tx Transfer completed callback. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_TxCpltCallback(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE: This function should not be modified, when the callback is needed, the HAL_QSPI_TxCpltCallback could be implemented in the user file */ } /** * @brief Rx Half Transfer completed callback. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_RxHalfCpltCallback(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE: This function should not be modified, when the callback is needed, the HAL_QSPI_RxHalfCpltCallback could be implemented in the user file */ } /** * @brief Tx Half Transfer completed callback. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_TxHalfCpltCallback(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE: This function should not be modified, when the callback is needed, the HAL_QSPI_TxHalfCpltCallback could be implemented in the user file */ } /** * @brief FIFO Threshold callback. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_FifoThresholdCallback(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE : This function should not be modified, when the callback is needed, the HAL_QSPI_FIFOThresholdCallback could be implemented in the user file */ } /** * @brief Status Match callback. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_StatusMatchCallback(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE : This function should not be modified, when the callback is needed, the HAL_QSPI_StatusMatchCallback could be implemented in the user file */ } /** * @brief Timeout callback. * @param hqspi : QSPI handle * @retval None */ __weak void HAL_QSPI_TimeOutCallback(QSPI_HandleTypeDef *hqspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hqspi); /* NOTE : This function should not be modified, when the callback is needed, the HAL_QSPI_TimeOutCallback could be implemented in the user file */ } #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) /** * @brief Register a User QSPI Callback * To be used instead of the weak (surcharged) predefined callback * @param hqspi : QSPI handle * @param CallbackId : ID of the callback to be registered * This parameter can be one of the following values: * @arg @ref HAL_QSPI_ERROR_CB_ID QSPI Error Callback ID * @arg @ref HAL_QSPI_ABORT_CB_ID QSPI Abort Callback ID * @arg @ref HAL_QSPI_FIFO_THRESHOLD_CB_ID QSPI FIFO Threshold Callback ID * @arg @ref HAL_QSPI_CMD_CPLT_CB_ID QSPI Command Complete Callback ID * @arg @ref HAL_QSPI_RX_CPLT_CB_ID QSPI Rx Complete Callback ID * @arg @ref HAL_QSPI_TX_CPLT_CB_ID QSPI Tx Complete Callback ID * @arg @ref HAL_QSPI_RX_HALF_CPLT_CB_ID QSPI Rx Half Complete Callback ID * @arg @ref HAL_QSPI_TX_HALF_CPLT_CB_ID QSPI Tx Half Complete Callback ID * @arg @ref HAL_QSPI_STATUS_MATCH_CB_ID QSPI Status Match Callback ID * @arg @ref HAL_QSPI_TIMEOUT_CB_ID QSPI Timeout Callback ID * @arg @ref HAL_QSPI_MSP_INIT_CB_ID QSPI MspInit callback ID * @arg @ref HAL_QSPI_MSP_DEINIT_CB_ID QSPI MspDeInit callback ID * @param pCallback : pointer to the Callback function * @retval status */ HAL_StatusTypeDef HAL_QSPI_RegisterCallback (QSPI_HandleTypeDef *hqspi, HAL_QSPI_CallbackIDTypeDef CallbackId, pQSPI_CallbackTypeDef pCallback) { HAL_StatusTypeDef status = HAL_OK; if(pCallback == NULL) { /* Update the error code */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK; return HAL_ERROR; } /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { switch (CallbackId) { case HAL_QSPI_ERROR_CB_ID : hqspi->ErrorCallback = pCallback; break; case HAL_QSPI_ABORT_CB_ID : hqspi->AbortCpltCallback = pCallback; break; case HAL_QSPI_FIFO_THRESHOLD_CB_ID : hqspi->FifoThresholdCallback = pCallback; break; case HAL_QSPI_CMD_CPLT_CB_ID : hqspi->CmdCpltCallback = pCallback; break; case HAL_QSPI_RX_CPLT_CB_ID : hqspi->RxCpltCallback = pCallback; break; case HAL_QSPI_TX_CPLT_CB_ID : hqspi->TxCpltCallback = pCallback; break; case HAL_QSPI_RX_HALF_CPLT_CB_ID : hqspi->RxHalfCpltCallback = pCallback; break; case HAL_QSPI_TX_HALF_CPLT_CB_ID : hqspi->TxHalfCpltCallback = pCallback; break; case HAL_QSPI_STATUS_MATCH_CB_ID : hqspi->StatusMatchCallback = pCallback; break; case HAL_QSPI_TIMEOUT_CB_ID : hqspi->TimeOutCallback = pCallback; break; case HAL_QSPI_MSP_INIT_CB_ID : hqspi->MspInitCallback = pCallback; break; case HAL_QSPI_MSP_DEINIT_CB_ID : hqspi->MspDeInitCallback = pCallback; break; default : /* Update the error code */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK; /* update return status */ status = HAL_ERROR; break; } } else if (hqspi->State == HAL_QSPI_STATE_RESET) { switch (CallbackId) { case HAL_QSPI_MSP_INIT_CB_ID : hqspi->MspInitCallback = pCallback; break; case HAL_QSPI_MSP_DEINIT_CB_ID : hqspi->MspDeInitCallback = pCallback; break; default : /* Update the error code */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK; /* update return status */ status = HAL_ERROR; break; } } else { /* Update the error code */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK; /* update return status */ status = HAL_ERROR; } /* Release Lock */ __HAL_UNLOCK(hqspi); return status; } /** * @brief Unregister a User QSPI Callback * QSPI Callback is redirected to the weak (surcharged) predefined callback * @param hqspi : QSPI handle * @param CallbackId : ID of the callback to be unregistered * This parameter can be one of the following values: * @arg @ref HAL_QSPI_ERROR_CB_ID QSPI Error Callback ID * @arg @ref HAL_QSPI_ABORT_CB_ID QSPI Abort Callback ID * @arg @ref HAL_QSPI_FIFO_THRESHOLD_CB_ID QSPI FIFO Threshold Callback ID * @arg @ref HAL_QSPI_CMD_CPLT_CB_ID QSPI Command Complete Callback ID * @arg @ref HAL_QSPI_RX_CPLT_CB_ID QSPI Rx Complete Callback ID * @arg @ref HAL_QSPI_TX_CPLT_CB_ID QSPI Tx Complete Callback ID * @arg @ref HAL_QSPI_RX_HALF_CPLT_CB_ID QSPI Rx Half Complete Callback ID * @arg @ref HAL_QSPI_TX_HALF_CPLT_CB_ID QSPI Tx Half Complete Callback ID * @arg @ref HAL_QSPI_STATUS_MATCH_CB_ID QSPI Status Match Callback ID * @arg @ref HAL_QSPI_TIMEOUT_CB_ID QSPI Timeout Callback ID * @arg @ref HAL_QSPI_MSP_INIT_CB_ID QSPI MspInit callback ID * @arg @ref HAL_QSPI_MSP_DEINIT_CB_ID QSPI MspDeInit callback ID * @retval status */ HAL_StatusTypeDef HAL_QSPI_UnRegisterCallback (QSPI_HandleTypeDef *hqspi, HAL_QSPI_CallbackIDTypeDef CallbackId) { HAL_StatusTypeDef status = HAL_OK; /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { switch (CallbackId) { case HAL_QSPI_ERROR_CB_ID : hqspi->ErrorCallback = HAL_QSPI_ErrorCallback; break; case HAL_QSPI_ABORT_CB_ID : hqspi->AbortCpltCallback = HAL_QSPI_AbortCpltCallback; break; case HAL_QSPI_FIFO_THRESHOLD_CB_ID : hqspi->FifoThresholdCallback = HAL_QSPI_FifoThresholdCallback; break; case HAL_QSPI_CMD_CPLT_CB_ID : hqspi->CmdCpltCallback = HAL_QSPI_CmdCpltCallback; break; case HAL_QSPI_RX_CPLT_CB_ID : hqspi->RxCpltCallback = HAL_QSPI_RxCpltCallback; break; case HAL_QSPI_TX_CPLT_CB_ID : hqspi->TxCpltCallback = HAL_QSPI_TxCpltCallback; break; case HAL_QSPI_RX_HALF_CPLT_CB_ID : hqspi->RxHalfCpltCallback = HAL_QSPI_RxHalfCpltCallback; break; case HAL_QSPI_TX_HALF_CPLT_CB_ID : hqspi->TxHalfCpltCallback = HAL_QSPI_TxHalfCpltCallback; break; case HAL_QSPI_STATUS_MATCH_CB_ID : hqspi->StatusMatchCallback = HAL_QSPI_StatusMatchCallback; break; case HAL_QSPI_TIMEOUT_CB_ID : hqspi->TimeOutCallback = HAL_QSPI_TimeOutCallback; break; case HAL_QSPI_MSP_INIT_CB_ID : hqspi->MspInitCallback = HAL_QSPI_MspInit; break; case HAL_QSPI_MSP_DEINIT_CB_ID : hqspi->MspDeInitCallback = HAL_QSPI_MspDeInit; break; default : /* Update the error code */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK; /* update return status */ status = HAL_ERROR; break; } } else if (hqspi->State == HAL_QSPI_STATE_RESET) { switch (CallbackId) { case HAL_QSPI_MSP_INIT_CB_ID : hqspi->MspInitCallback = HAL_QSPI_MspInit; break; case HAL_QSPI_MSP_DEINIT_CB_ID : hqspi->MspDeInitCallback = HAL_QSPI_MspDeInit; break; default : /* Update the error code */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK; /* update return status */ status = HAL_ERROR; break; } } else { /* Update the error code */ hqspi->ErrorCode |= HAL_QSPI_ERROR_INVALID_CALLBACK; /* update return status */ status = HAL_ERROR; } /* Release Lock */ __HAL_UNLOCK(hqspi); return status; } #endif /** * @} */ /** @defgroup QSPI_Exported_Functions_Group3 Peripheral Control and State functions * @brief QSPI control and State functions * @verbatim =============================================================================== ##### Peripheral Control and State functions ##### =============================================================================== [..] This subsection provides a set of functions allowing to : (+) Check in run-time the state of the driver. (+) Check the error code set during last operation. (+) Abort any operation. @endverbatim * @{ */ /** * @brief Return the QSPI handle state. * @param hqspi : QSPI handle * @retval HAL state */ HAL_QSPI_StateTypeDef HAL_QSPI_GetState(QSPI_HandleTypeDef *hqspi) { /* Return QSPI handle state */ return hqspi->State; } /** * @brief Return the QSPI error code. * @param hqspi : QSPI handle * @retval QSPI Error Code */ uint32_t HAL_QSPI_GetError(QSPI_HandleTypeDef *hqspi) { return hqspi->ErrorCode; } /** * @brief Abort the current transmission. * @param hqspi : QSPI handle * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Abort(QSPI_HandleTypeDef *hqspi) { HAL_StatusTypeDef status = HAL_OK; uint32_t tickstart = HAL_GetTick(); /* Check if the state is in one of the busy states */ if (((uint32_t)hqspi->State & 0x2U) != 0U) { /* Process unlocked */ __HAL_UNLOCK(hqspi); if ((hqspi->Instance->CR & QUADSPI_CR_DMAEN) != 0U) { /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */ CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN); /* Abort DMA channel */ status = HAL_DMA_Abort(hqspi->hdma); if(status != HAL_OK) { hqspi->ErrorCode |= HAL_QSPI_ERROR_DMA; } } /* Configure QSPI: CR register with Abort request */ SET_BIT(hqspi->Instance->CR, QUADSPI_CR_ABORT); /* Wait until TC flag is set to go back in idle state */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_TC, SET, tickstart, hqspi->Timeout); if (status == HAL_OK) { __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC); /* Wait until BUSY flag is reset */ status = QSPI_WaitFlagStateUntilTimeout(hqspi, QSPI_FLAG_BUSY, RESET, tickstart, hqspi->Timeout); } if (status == HAL_OK) { /* Reset functional mode configuration to indirect write mode by default */ CLEAR_BIT(hqspi->Instance->CCR, QUADSPI_CCR_FMODE); /* Update state */ hqspi->State = HAL_QSPI_STATE_READY; } } return status; } /** * @brief Abort the current transmission (non-blocking function) * @param hqspi : QSPI handle * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_Abort_IT(QSPI_HandleTypeDef *hqspi) { HAL_StatusTypeDef status = HAL_OK; /* Check if the state is in one of the busy states */ if (((uint32_t)hqspi->State & 0x2U) != 0U) { /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Update QSPI state */ hqspi->State = HAL_QSPI_STATE_ABORT; /* Disable all interrupts */ __HAL_QSPI_DISABLE_IT(hqspi, (QSPI_IT_TO | QSPI_IT_SM | QSPI_IT_FT | QSPI_IT_TC | QSPI_IT_TE)); if ((hqspi->Instance->CR & QUADSPI_CR_DMAEN) != 0U) { /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */ CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN); /* Abort DMA channel */ hqspi->hdma->XferAbortCallback = QSPI_DMAAbortCplt; if (HAL_DMA_Abort_IT(hqspi->hdma) != HAL_OK) { /* Change state of QSPI */ hqspi->State = HAL_QSPI_STATE_READY; /* Abort Complete callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->AbortCpltCallback(hqspi); #else HAL_QSPI_AbortCpltCallback(hqspi); #endif } } else { /* Clear interrupt */ __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC); /* Enable the QSPI Transfer Complete Interrupt */ __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TC); /* Configure QSPI: CR register with Abort request */ SET_BIT(hqspi->Instance->CR, QUADSPI_CR_ABORT); } } return status; } /** @brief Set QSPI timeout. * @param hqspi : QSPI handle. * @param Timeout : Timeout for the QSPI memory access. * @retval None */ void HAL_QSPI_SetTimeout(QSPI_HandleTypeDef *hqspi, uint32_t Timeout) { hqspi->Timeout = Timeout; } /** @brief Set QSPI Fifo threshold. * @param hqspi : QSPI handle. * @param Threshold : Threshold of the Fifo (value between 1 and 16). * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_SetFifoThreshold(QSPI_HandleTypeDef *hqspi, uint32_t Threshold) { HAL_StatusTypeDef status = HAL_OK; /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { /* Synchronize init structure with new FIFO threshold value */ hqspi->Init.FifoThreshold = Threshold; /* Configure QSPI FIFO Threshold */ MODIFY_REG(hqspi->Instance->CR, QUADSPI_CR_FTHRES, ((hqspi->Init.FifoThreshold - 1U) << QUADSPI_CR_FTHRES_Pos)); } else { status = HAL_BUSY; } /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Return function status */ return status; } /** @brief Get QSPI Fifo threshold. * @param hqspi : QSPI handle. * @retval Fifo threshold (value between 1 and 16) */ uint32_t HAL_QSPI_GetFifoThreshold(QSPI_HandleTypeDef *hqspi) { return ((READ_BIT(hqspi->Instance->CR, QUADSPI_CR_FTHRES) >> QUADSPI_CR_FTHRES_Pos) + 1U); } /** @brief Set FlashID. * @param hqspi : QSPI handle. * @param FlashID : Index of the flash memory to be accessed. * This parameter can be a value of @ref QSPI_Flash_Select. * @note The FlashID is ignored when dual flash mode is enabled. * @retval HAL status */ HAL_StatusTypeDef HAL_QSPI_SetFlashID(QSPI_HandleTypeDef *hqspi, uint32_t FlashID) { HAL_StatusTypeDef status = HAL_OK; /* Check the parameter */ assert_param(IS_QSPI_FLASH_ID(FlashID)); /* Process locked */ __HAL_LOCK(hqspi); if(hqspi->State == HAL_QSPI_STATE_READY) { /* Synchronize init structure with new FlashID value */ hqspi->Init.FlashID = FlashID; /* Configure QSPI FlashID */ MODIFY_REG(hqspi->Instance->CR, QUADSPI_CR_FSEL, FlashID); } else { status = HAL_BUSY; } /* Process unlocked */ __HAL_UNLOCK(hqspi); /* Return function status */ return status; } /** * @} */ /** * @} */ /** @defgroup QSPI_Private_Functions QSPI Private Functions * @{ */ /** * @brief DMA QSPI receive process complete callback. * @param hdma : DMA handle * @retval None */ static void QSPI_DMARxCplt(DMA_HandleTypeDef *hdma) { QSPI_HandleTypeDef* hqspi = (QSPI_HandleTypeDef*)(hdma->Parent); hqspi->RxXferCount = 0U; /* Enable the QSPI transfer complete Interrupt */ __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TC); } /** * @brief DMA QSPI transmit process complete callback. * @param hdma : DMA handle * @retval None */ static void QSPI_DMATxCplt(DMA_HandleTypeDef *hdma) { QSPI_HandleTypeDef* hqspi = (QSPI_HandleTypeDef*)(hdma->Parent); hqspi->TxXferCount = 0U; /* Enable the QSPI transfer complete Interrupt */ __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TC); } /** * @brief DMA QSPI receive process half complete callback. * @param hdma : DMA handle * @retval None */ static void QSPI_DMARxHalfCplt(DMA_HandleTypeDef *hdma) { QSPI_HandleTypeDef* hqspi = (QSPI_HandleTypeDef*)(hdma->Parent); #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->RxHalfCpltCallback(hqspi); #else HAL_QSPI_RxHalfCpltCallback(hqspi); #endif } /** * @brief DMA QSPI transmit process half complete callback. * @param hdma : DMA handle * @retval None */ static void QSPI_DMATxHalfCplt(DMA_HandleTypeDef *hdma) { QSPI_HandleTypeDef* hqspi = (QSPI_HandleTypeDef*)(hdma->Parent); #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->TxHalfCpltCallback(hqspi); #else HAL_QSPI_TxHalfCpltCallback(hqspi); #endif } /** * @brief DMA QSPI communication error callback. * @param hdma : DMA handle * @retval None */ static void QSPI_DMAError(DMA_HandleTypeDef *hdma) { QSPI_HandleTypeDef* hqspi = ( QSPI_HandleTypeDef* )(hdma->Parent); /* if DMA error is FIFO error ignore it */ if(HAL_DMA_GetError(hdma) != HAL_DMA_ERROR_FE) { hqspi->RxXferCount = 0U; hqspi->TxXferCount = 0U; hqspi->ErrorCode |= HAL_QSPI_ERROR_DMA; /* Disable the DMA transfer by clearing the DMAEN bit in the QSPI CR register */ CLEAR_BIT(hqspi->Instance->CR, QUADSPI_CR_DMAEN); /* Abort the QSPI */ (void)HAL_QSPI_Abort_IT(hqspi); } } /** * @brief DMA QSPI abort complete callback. * @param hdma : DMA handle * @retval None */ static void QSPI_DMAAbortCplt(DMA_HandleTypeDef *hdma) { QSPI_HandleTypeDef* hqspi = ( QSPI_HandleTypeDef* )(hdma->Parent); hqspi->RxXferCount = 0U; hqspi->TxXferCount = 0U; if(hqspi->State == HAL_QSPI_STATE_ABORT) { /* DMA Abort called by QSPI abort */ /* Clear interrupt */ __HAL_QSPI_CLEAR_FLAG(hqspi, QSPI_FLAG_TC); /* Enable the QSPI Transfer Complete Interrupt */ __HAL_QSPI_ENABLE_IT(hqspi, QSPI_IT_TC); /* Configure QSPI: CR register with Abort request */ SET_BIT(hqspi->Instance->CR, QUADSPI_CR_ABORT); } else { /* DMA Abort called due to a transfer error interrupt */ /* Change state of QSPI */ hqspi->State = HAL_QSPI_STATE_READY; /* Error callback */ #if (USE_HAL_QSPI_REGISTER_CALLBACKS == 1) hqspi->ErrorCallback(hqspi); #else HAL_QSPI_ErrorCallback(hqspi); #endif } } /** * @brief Wait for a flag state until timeout. * @param hqspi : QSPI handle * @param Flag : Flag checked * @param State : Value of the flag expected * @param Tickstart : Tick start value * @param Timeout : Duration of the timeout * @retval HAL status */ static HAL_StatusTypeDef QSPI_WaitFlagStateUntilTimeout(QSPI_HandleTypeDef *hqspi, uint32_t Flag, FlagStatus State, uint32_t Tickstart, uint32_t Timeout) { /* Wait until flag is in expected state */ while((__HAL_QSPI_GET_FLAG(hqspi, Flag)) != State) { /* Check for the Timeout */ if (Timeout != HAL_MAX_DELAY) { if(((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U)) { hqspi->State = HAL_QSPI_STATE_ERROR; hqspi->ErrorCode |= HAL_QSPI_ERROR_TIMEOUT; return HAL_ERROR; } } } return HAL_OK; } /** * @brief Wait for a flag state until timeout using CPU cycle. * @param hqspi : QSPI handle * @param Flag : Flag checked * @param State : Value of the flag expected * @param Timeout : Duration of the timeout * @retval HAL status */ static HAL_StatusTypeDef QSPI_WaitFlagStateUntilTimeout_CPUCycle(QSPI_HandleTypeDef *hqspi, uint32_t Flag, FlagStatus State, uint32_t Timeout) { __IO uint32_t count = Timeout * (SystemCoreClock / 16U / 1000U); do { if (count-- == 0U) { hqspi->State = HAL_QSPI_STATE_ERROR; hqspi->ErrorCode |= HAL_QSPI_ERROR_TIMEOUT; return HAL_TIMEOUT; } } while ((__HAL_QSPI_GET_FLAG(hqspi, Flag)) != State); return HAL_OK; } /** * @brief Configure the communication registers. * @param hqspi : QSPI handle * @param cmd : structure that contains the command configuration information * @param FunctionalMode : functional mode to configured * This parameter can be one of the following values: * @arg QSPI_FUNCTIONAL_MODE_INDIRECT_WRITE: Indirect write mode * @arg QSPI_FUNCTIONAL_MODE_INDIRECT_READ: Indirect read mode * @arg QSPI_FUNCTIONAL_MODE_AUTO_POLLING: Automatic polling mode * @arg QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED: Memory-mapped mode * @retval None */ static void QSPI_Config(QSPI_HandleTypeDef *hqspi, QSPI_CommandTypeDef *cmd, uint32_t FunctionalMode) { assert_param(IS_QSPI_FUNCTIONAL_MODE(FunctionalMode)); if ((cmd->DataMode != QSPI_DATA_NONE) && (FunctionalMode != QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED)) { /* Configure QSPI: DLR register with the number of data to read or write */ WRITE_REG(hqspi->Instance->DLR, (cmd->NbData - 1U)); } if (cmd->InstructionMode != QSPI_INSTRUCTION_NONE) { if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE) { /* Configure QSPI: ABR register with alternate bytes value */ WRITE_REG(hqspi->Instance->ABR, cmd->AlternateBytes); if (cmd->AddressMode != QSPI_ADDRESS_NONE) { /*---- Command with instruction, address and alternate bytes ----*/ /* Configure QSPI: CCR register with all communications parameters */ WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode | cmd->DataMode | (cmd->DummyCycles << QUADSPI_CCR_DCYC_Pos) | cmd->AlternateBytesSize | cmd->AlternateByteMode | cmd->AddressSize | cmd->AddressMode | cmd->InstructionMode | cmd->Instruction | FunctionalMode)); if (FunctionalMode != QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED) { /* Configure QSPI: AR register with address value */ WRITE_REG(hqspi->Instance->AR, cmd->Address); } } else { /*---- Command with instruction and alternate bytes ----*/ /* Configure QSPI: CCR register with all communications parameters */ WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode | cmd->DataMode | (cmd->DummyCycles << QUADSPI_CCR_DCYC_Pos) | cmd->AlternateBytesSize | cmd->AlternateByteMode | cmd->AddressMode | cmd->InstructionMode | cmd->Instruction | FunctionalMode)); } } else { if (cmd->AddressMode != QSPI_ADDRESS_NONE) { /*---- Command with instruction and address ----*/ /* Configure QSPI: CCR register with all communications parameters */ WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode | cmd->DataMode | (cmd->DummyCycles << QUADSPI_CCR_DCYC_Pos) | cmd->AlternateByteMode | cmd->AddressSize | cmd->AddressMode | cmd->InstructionMode | cmd->Instruction | FunctionalMode)); if (FunctionalMode != QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED) { /* Configure QSPI: AR register with address value */ WRITE_REG(hqspi->Instance->AR, cmd->Address); } } else { /*---- Command with only instruction ----*/ /* Configure QSPI: CCR register with all communications parameters */ WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode | cmd->DataMode | (cmd->DummyCycles << QUADSPI_CCR_DCYC_Pos) | cmd->AlternateByteMode | cmd->AddressMode | cmd->InstructionMode | cmd->Instruction | FunctionalMode)); } } } else { if (cmd->AlternateByteMode != QSPI_ALTERNATE_BYTES_NONE) { /* Configure QSPI: ABR register with alternate bytes value */ WRITE_REG(hqspi->Instance->ABR, cmd->AlternateBytes); if (cmd->AddressMode != QSPI_ADDRESS_NONE) { /*---- Command with address and alternate bytes ----*/ /* Configure QSPI: CCR register with all communications parameters */ WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode | cmd->DataMode | (cmd->DummyCycles << QUADSPI_CCR_DCYC_Pos) | cmd->AlternateBytesSize | cmd->AlternateByteMode | cmd->AddressSize | cmd->AddressMode | cmd->InstructionMode | FunctionalMode)); if (FunctionalMode != QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED) { /* Configure QSPI: AR register with address value */ WRITE_REG(hqspi->Instance->AR, cmd->Address); } } else { /*---- Command with only alternate bytes ----*/ /* Configure QSPI: CCR register with all communications parameters */ WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode | cmd->DataMode | (cmd->DummyCycles << QUADSPI_CCR_DCYC_Pos) | cmd->AlternateBytesSize | cmd->AlternateByteMode | cmd->AddressMode | cmd->InstructionMode | FunctionalMode)); } } else { if (cmd->AddressMode != QSPI_ADDRESS_NONE) { /*---- Command with only address ----*/ /* Configure QSPI: CCR register with all communications parameters */ WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode | cmd->DataMode | (cmd->DummyCycles << QUADSPI_CCR_DCYC_Pos) | cmd->AlternateByteMode | cmd->AddressSize | cmd->AddressMode | cmd->InstructionMode | FunctionalMode)); if (FunctionalMode != QSPI_FUNCTIONAL_MODE_MEMORY_MAPPED) { /* Configure QSPI: AR register with address value */ WRITE_REG(hqspi->Instance->AR, cmd->Address); } } else { /*---- Command with only data phase ----*/ if (cmd->DataMode != QSPI_DATA_NONE) { /* Configure QSPI: CCR register with all communications parameters */ WRITE_REG(hqspi->Instance->CCR, (cmd->DdrMode | cmd->DdrHoldHalfCycle | cmd->SIOOMode | cmd->DataMode | (cmd->DummyCycles << QUADSPI_CCR_DCYC_Pos) | cmd->AlternateByteMode | cmd->AddressMode | cmd->InstructionMode | FunctionalMode)); } } } } } /** * @} */ /** * @} */ #endif /* HAL_QSPI_MODULE_ENABLED */ /** * @} */ /** * @} */ #endif /* defined(QUADSPI) */
142235.c
// test storing ints in pointers int main() { // local variable int local = 7; // pointer to this variable int *ptr = &local; *ptr = 9; // modify via pointer // now store an int in the ptr ptr = (int*)23; local = (int)ptr; // read the int out of the ptr // point the ptr back at the local ptr = &local; // and verify everything is 23 return *ptr + local*10 - (23 + 23*10); }
302067.c
#define DLONG #include <../Source/klu_defaults.c>
998314.c
/* * Copyright (c) 2016, 2018, Oracle and/or its affiliates. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors may be used to * endorse or promote products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "nanolibc.h" int main(void) { uid_t uid = getuid(); printf("uid: %d\n", uid); return 0; }
485868.c
/* * mc6821core.c - Motorola MC6821 Emulation * * Written by * groepaz <[email protected]> * * This file is part of VICE, the Versatile Commodore Emulator. * See README for copyright notice. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. * */ #include "vice.h" /* define for debug messages */ /* #define MC6821_DEBUG */ #ifdef MC6821_DEBUG #include <stdio.h> #define DBG(x) printf x #else #define DBG(x) #endif #include <stdlib.h> #include "mc6821core.h" #include "snapshot.h" void mc6821core_reset(mc6821_state *ctx) { ctx->CA2 = 0; ctx->CA2state = 0; ctx->CB2 = 0; ctx->CB2state = 0; ctx->ctrlA = 0; ctx->dataA = 0; ctx->ddrA = 0; ctx->ctrlB = 0; ctx->dataB = 0; ctx->ddrB = 0; if (ctx->set_ca2) { ctx->set_ca2(ctx); } if (ctx->set_cb2) { ctx->set_cb2(ctx); } if (ctx->set_pa) { ctx->set_pa(ctx); } if (ctx->set_pb) { ctx->set_pb(ctx); } } uint8_t mc6821core_read(mc6821_state *ctx, int port /* rs1 */, int reg /* rs0 */) { uint8_t data = 0; if (port == 0) { /* MC6821 Port A */ if (reg == 1) { /* control register */ data = ctx->ctrlA; } else { if (ctx->ctrlA & MC6821_CTRL_REG) { /* data port */ data = ctx->dataA & ctx->ddrA; /* FIXME: CA2 output mode 0x08 */ if (ctx->CA2state == 1) { ctx->CA2 = 0; if (ctx->set_ca2) { ctx->set_ca2(ctx); } } /* get input from port */ if (ctx->get_pa) { data |= ctx->get_pa(ctx) & ~(ctx->ddrA); } else { data |= 0xff & ~(ctx->ddrA); } /* FIXME: CA2 output mode 0x08 */ if (ctx->CA2state == 1) { ctx->CA2 = 1; if (ctx->set_ca2) { ctx->set_ca2(ctx); } ctx->CA2state = 0; } /* irq flags are cleared when reading output port */ ctx->ctrlA &= ~(MC6821_CTRL_IRQ1 | MC6821_CTRL_IRQ2); } else { data = ctx->ddrA; } } } else { /* MC6821 Port B */ if (reg == 1) { /* control register */ data = ctx->ctrlB; } else { if (ctx->ctrlB & MC6821_CTRL_REG) { /* data port */ data = ctx->dataB & ctx->ddrB; if (ctx->get_pb) { data |= ctx->get_pb(ctx) & ~(ctx->ddrB); } else { data |= 0xff & ~(ctx->ddrB); } /* irq flags are cleared when reading output port */ ctx->ctrlB &= ~(MC6821_CTRL_IRQ1 | MC6821_CTRL_IRQ2); } else { data = ctx->ddrB; } } } return data; } uint8_t mc6821core_peek(mc6821_state *ctx, int port /* rs1 */, int reg /* rs0 */) { uint8_t data = 0; if (port == 0) { /* MC6821 Port A */ if (reg == 1) { /* control register */ data = ctx->ctrlA; } else { if (ctx->ctrlA & MC6821_CTRL_REG) { data = ctx->dataA; #if 0 if (ctx->get_pa) { data = ctx->get_pa(ctx); } #endif } else { data = ctx->ddrA; } } } else { /* MC6821 Port B */ if (reg == 1) { /* control register */ data = ctx->ctrlB; } else { if (ctx->ctrlB & MC6821_CTRL_REG) { data = ctx->dataB; #if 0 if (ctx->get_pb) { data = ctx->get_pb(ctx); } #endif } else { data = ctx->ddrB; } } } return data; } void mc6821core_store(mc6821_state *ctx, int port /* rs1 */, int reg /* rs0 */, uint8_t data) { if (port == 0) { /* MC6821 Port A */ if (reg == 1) { /* control register */ /* DBG(("MC6821: PA CTRL %02x\n", data)); */ ctx->ctrlA = data; if (data & MC6821_CTRL_C2DDR) { /* CA2 is output */ switch (data & MC6821_CTRL_C2MODE) { case MC6821_CTRL_C2_RESET_C2: ctx->CA2 = 0; /* update CA2 immediately */ if (ctx->set_ca2) { ctx->set_ca2(ctx); } break; case MC6821_CTRL_C2_SET_C2: ctx->CA2 = 1; /* update CA2 immediately */ if (ctx->set_ca2) { ctx->set_ca2(ctx); } break; case MC6821_CTRL_C2_STROBE_C: DBG(("MC6821: PA CTRL unimplemented output mode %02x for CA2\n", data & MC6821_CTRL_C2MODE)); break; case MC6821_CTRL_C2_STROBE_E: DBG(("MC6821: PA CTRL FIXME output mode %02x for CA2\n", data & MC6821_CTRL_C2MODE)); ctx->CA2state = 1; break; } } else { /* CA2 is input */ if (data & MC6821_CTRL_C2_IRQEN) { DBG(("MC6821: PA CTRL unimplemented irq mode %02x for CA2\n", data & MC6821_CTRL_C2MODE)); } } } else { if (ctx->ctrlA & MC6821_CTRL_REG) { /* output register */ /* DBG(("MC6821: PA DATA %02x\n",data)); */ ctx->dataA = data; if (ctx->set_pa) { ctx->set_pa(ctx); } } else { /* data direction register */ /* DBG(("MC6821: PA DDR %02x\n",data)); */ ctx->ddrA = data; /* update port if ddr changes */ if (ctx->set_pa) { ctx->set_pa(ctx); } } } } else { /* MC6821 Port B */ if (reg == 1) { /* control register */ DBG(("MC6821: PB CTRL %02x\n", data)); ctx->ctrlB = data; if (data & MC6821_CTRL_C2DDR) { /* CB2 is output */ switch (data & MC6821_CTRL_C2MODE) { case MC6821_CTRL_C2_RESET_C2: ctx->CB2 = 0; /* update CB2 immediately */ if (ctx->set_cb2) { ctx->set_cb2(ctx); } break; case MC6821_CTRL_C2_SET_C2: ctx->CB2 = 1; /* update CB2 immediately */ if (ctx->set_cb2) { ctx->set_cb2(ctx); } break; case MC6821_CTRL_C2_STROBE_C: DBG(("MC6821: PB CTRL unimplemented output mode %02x for CB2\n", data & MC6821_CTRL_C2MODE)); break; case MC6821_CTRL_C2_STROBE_E: DBG(("MC6821: PB CTRL FIXME output mode %02x for CB2\n", data & MC6821_CTRL_C2MODE)); ctx->CB2state = 1; break; } } else { /* CB2 is input */ if (data & MC6821_CTRL_C2_IRQEN) { DBG(("MC6821: PB CTRL unimplemented irq mode %02x for CB2\n", data & MC6821_CTRL_C2MODE)); } } } else { if (ctx->ctrlB & MC6821_CTRL_REG) { /* output register */ /* DBG(("MC6821: PB DATA %02x\n",data)); */ ctx->dataB = data; /* FIXME: CB2 output mode 0x08 */ if (ctx->CB2state == 1) { ctx->CB2 = 0; if (ctx->set_cb2) { ctx->set_cb2(ctx); } } if (ctx->set_pb) { ctx->set_pb(ctx); } /* FIXME: CB2 output mode 0x08 */ if (ctx->CB2state == 1) { ctx->CB2 = 1; if (ctx->set_cb2) { ctx->set_cb2(ctx); } ctx->CB2state = 0; } } else { /* data direction register */ DBG(("MC6821: PB DDR %02x\n", data)); ctx->ddrB = data; /* update port if ddr changes */ if (ctx->set_pb) { ctx->set_pb(ctx); } } } } } void mc6821core_set_signal(mc6821_state *ctx, int line) { /* DBG(("MC6821: SIGNAL %02x\n", line)); */ switch (line) { case MC6821_SIGNAL_CA1: ctx->ctrlA = (ctx->ctrlA | MC6821_CTRL_IRQ1); break; case MC6821_SIGNAL_CA2: ctx->ctrlA = (ctx->ctrlA | MC6821_CTRL_IRQ2); break; case MC6821_SIGNAL_CB1: ctx->ctrlB = (ctx->ctrlB | MC6821_CTRL_IRQ1); break; case MC6821_SIGNAL_CB2: ctx->ctrlB = (ctx->ctrlB | MC6821_CTRL_IRQ2); break; } } int mc6821core_snapshot_write_data(mc6821_state *ctx, snapshot_module_t *m) { if (m == NULL) { return -1; } if (0 || SMW_B(m, (uint8_t)ctx->ctrlA) < 0 || SMW_B(m, (uint8_t)ctx->ctrlB) < 0 || SMW_B(m, (uint8_t)ctx->dataA) < 0 || SMW_B(m, (uint8_t)ctx->dataB) < 0 || SMW_B(m, (uint8_t)ctx->ddrA) < 0 || SMW_B(m, (uint8_t)ctx->ddrB) < 0 || SMW_B(m, (uint8_t)ctx->CA2) < 0 || SMW_B(m, (uint8_t)ctx->CA2state) < 0 || SMW_B(m, (uint8_t)ctx->CB2) < 0 || SMW_B(m, (uint8_t)ctx->CB2state) < 0) { return -1; } return 0; } int mc6821core_snapshot_read_data(mc6821_state *ctx, snapshot_module_t *m) { if (m == NULL) { return -1; } if (0 || SMR_B(m, &ctx->ctrlA) < 0 || SMR_B(m, &ctx->ctrlB) < 0 || SMR_B(m, &ctx->dataA) < 0 || SMR_B(m, &ctx->dataB) < 0 || SMR_B(m, &ctx->ddrA) < 0 || SMR_B(m, &ctx->ddrB) < 0 || SMR_B_INT(m, &ctx->CA2) < 0 || SMR_B_INT(m, &ctx->CA2state) < 0 || SMR_B_INT(m, &ctx->CB2) < 0 || SMR_B_INT(m, &ctx->CB2state) < 0) { return -1; } return 0; }
325721.c
/*************************************************************************** Gaelco Type CG-1V/GAE1 Video Hardware Functions to emulate the video hardware of the machine CG-1V/GAE1 (Gaelco custom GFX & Sound chip): The CG-1V works with 16x16, 5 bpp gfx. It can handle: * 2 1024x512 tilemaps with linescroll. * 2 banks of 512 sprites (sprites can be grouped up to 16x16). Sprites can make the background darker or brighter. Memory map: =========== 0x000000-0x000fff Sprite bank #1 (1) 0x001000-0x001fff Sprite bank #2 (1) 0x002000-0x0023ff Linescroll tilemap #1 (2) 0x002400-0x0027ff Linescroll tilemap #2 (2) Linescroll entries are like this: Word | Bit(s) | Description -----+-FEDCBA98-76543210-+-------------------------- i | xxxxxx-- -------- | not used? i | ------xx xxxxxxxx | line i x scroll register 0x002800-0x002807 Scroll registers Word | Bit(s) | Description -----+-FEDCBA98-76543210-+-------------------------- 0 | xxxxxxx- -------- | not used? 0 | -------x xxxxxxxx | tilemap #1 y scroll register 1 | xxxxxx-- -------- | not used? 1 | ------xx xxxxxxxx | tilemap #1 x scroll register 2 | xxxxxxx- -------- | not used? 2 | -------x xxxxxxxx | tilemap #2 y scroll register 3 | xxxxxx-- -------- | not used? 3 | ------xx xxxxxxxx | tilemap #2 x scroll register 0x002890-0x0028ff Sound registers (3) 0x000000-0x00ffff Video RAM 0x010000-0x011fff Palette (xRRRRRGGGGGBBBBB) 0x018004-0x018007 Video Registers Word | Bit(s) | Description -----+-FEDCBA98-76543210-+-------------------------- 0 | x------- -------- | tilemap #1 linescroll enable 0 | -xxx---- -------- | not used? 0 | ----xxx- -------- | tilemap #1 video RAM bank? (4, 5) 0 | -------x -------- | not used? 0 | -------- x------- | unknown 0 | -------- -x------ | not used? 0 | -------- --xx---- | visible area size? (=0,480x240;=1,384x240;=2,320x240) 0 | -------- ----xxxx | not used? 1 | x------- -------- | tilemap #2 linescroll enable 1 | -xxx---- -------- | not used? 1 | ----xxx- -------- | tilemap #2 video RAM bank? (4, 5) 1 | -------x xxx----- | not used? 1 | -------- ---x---- | sprite bank select 1 | -------- ----xxxx | not used? 0x018008-0x018009 Clear video int? Notes: (1) See sprite format in the sprite section (2) x scroll register is not taken into account when doing line scroll (3) See sound/gaelco.c for the sound register layout (4) tilemaps use the memory [0x2000*bank .. 0x2000*bank + 0x1fff] (5) See tile format in the tilemap section Multi monitor notes: Some games have two RGB outputs to allow two or four simultaneous players linking two cabinets (World Rally 2, Touch & Go). In 2 monitors mode, the hardware maps one tilemap to a monitor and the other tilemap to the other monitor. The game palette is splitted, using the first half for one monitor and the second half for the other monitor. The sprite RAM has one bit that selects the sprite's target monitor. The sound is splitted too, right channel for cabinet 1 and the left channel for the other cabinet. ***************************************************************************/ #include "driver.h" #include "tilemap.h" #include "vidhrdw/generic.h" data16_t *gaelco2_vregs; static data16_t *gaelco2_videoram; /* tilemaps */ static struct tilemap *pant[2]; int dual_monitor; /* comment this line to display 2 monitors for the dual monitor games */ #define ONE_MONITOR /*************************************************************************** Callbacks for the TileMap code (single monitor games) Tile format ----------- Screen 0 & 1: (1024*512, 16x16 tiles) Word | Bit(s) | Description -----+-FEDCBA98-76543210-+-------------------------- 0 | -------- -----xxx | code (bits 18-16) 0 | -------- --xxx--- | not used? 0 | -------- -x------ | flip y 0 | -------- x------- | flip x 0 | -------x -------- | not used? 0 | xxxxxxx- -------- | color 1 | xxxxxxxx xxxxxxxx | code (bits 15-0) ***************************************************************************/ static void get_tile_info_gaelco2_screen0(int tile_index) { int data = gaelco2_videoram[(((gaelco2_vregs[0] >> 9) & 0x07)*0x2000/2) + (tile_index << 1)]; int data2 = gaelco2_videoram[(((gaelco2_vregs[0] >> 9) & 0x07)*0x2000/2) + ((tile_index << 1) + 1)]; int code = ((data & 0x07) << 16) | (data2 & 0xffff); SET_TILE_INFO(0, code, ((data >> 9) & 0x7f), TILE_FLIPXY((data >> 6) & 0x03)) } static void get_tile_info_gaelco2_screen1(int tile_index) { int data = gaelco2_videoram[(((gaelco2_vregs[1] >> 9) & 0x07)*0x2000/2) + (tile_index << 1)]; int data2 = gaelco2_videoram[(((gaelco2_vregs[1] >> 9) & 0x07)*0x2000/2) + ((tile_index << 1) + 1)]; int code = ((data & 0x07) << 16) | (data2 & 0xffff); SET_TILE_INFO(0, code, ((data >> 9) & 0x7f), TILE_FLIPXY((data >> 6) & 0x03)) } /*************************************************************************** Callbacks for the TileMap code (dual monitor games) Tile format ----------- Screen 0 & 1: (1024*512, 16x16 tiles) Word | Bit(s) | Description -----+-FEDCBA98-76543210-+-------------------------- 0 | -------- -----xxx | code (bits 18-16) 0 | -------- --xxx--- | not used? 0 | -------- -x------ | flip y 0 | -------- x------- | flip x 0 | -------x -------- | not used? 0 | -xxxxxx- -------- | color 0 | x------- -------- | unknown 1 | xxxxxxxx xxxxxxxx | code (bits 15-0) ***************************************************************************/ static void get_tile_info_gaelco2_screen0_dual(int tile_index) { int data = gaelco2_videoram[(((gaelco2_vregs[0] >> 9) & 0x07)*0x2000/2) + (tile_index << 1)]; int data2 = gaelco2_videoram[(((gaelco2_vregs[0] >> 9) & 0x07)*0x2000/2) + ((tile_index << 1) + 1)]; int code = ((data & 0x07) << 16) | (data2 & 0xffff); SET_TILE_INFO(0, code, ((data >> 9) & 0x3f), TILE_FLIPXY((data >> 6) & 0x03)) } static void get_tile_info_gaelco2_screen1_dual(int tile_index) { int data = gaelco2_videoram[(((gaelco2_vregs[1] >> 9) & 0x07)*0x2000/2) + (tile_index << 1)]; int data2 = gaelco2_videoram[(((gaelco2_vregs[1] >> 9) & 0x07)*0x2000/2) + ((tile_index << 1) + 1)]; int code = ((data & 0x07) << 16) | (data2 & 0xffff); SET_TILE_INFO(0, code, 0x40 + ((data >> 9) & 0x3f), TILE_FLIPXY((data >> 6) & 0x03)) } /*************************************************************************** Memory Handlers ***************************************************************************/ WRITE16_HANDLER( gaelco2_vram_w ) { int pant0_start = ((gaelco2_vregs[0] >> 9) & 0x07)*0x1000; int pant0_end = pant0_start + 0x1000; int pant1_start = ((gaelco2_vregs[1] >> 9) & 0x07)*0x1000; int pant1_end = pant1_start + 0x1000; int oldword = gaelco2_videoram[offset]; COMBINE_DATA(&gaelco2_videoram[offset]); /* tilemap 0 writes */ if ((offset >= pant0_start) && (offset < pant0_end)){ if (oldword != gaelco2_videoram[offset]){ tilemap_mark_tile_dirty(pant[0], ((offset << 1) & 0x1fff) >> 2); } } /* tilemap 1 writes */ if ((offset >= pant1_start) && (offset < pant1_end)){ if (oldword != gaelco2_videoram[offset]){ tilemap_mark_tile_dirty(pant[1], ((offset << 1) & 0x1fff) >> 2); } } } /*************************************************************************** Palette (paletteram16_xRRRRRGGGGGBBBBB_word_w) The game's palette uses colors 0-4095, but we need 15 aditional palettes to handle shadows and highlights properly. After a color write to the game's palette we update the other palettes with a darker/brighter color. Sprites use last palette entry for shadows and highlights (in order to make some pixels darker or brighter). The sprite's pens define the color adjustment: 0x00 -> Transparent 0x01-0x07 -> Shadow level (0x01 = min, 0x07 = max) 0x08-0x0f -> Highlight level (0x08 = max, 0x0f = min) 0x10-0x1f -> not used? ***************************************************************************/ #define RGB_CHG 0x08 #define ADJUST_COLOR(c) ((c < 0) ? 0 : ((c > 255) ? 255 : c)) /* table used for color adjustment */ static int pen_color_adjust[16] = { +RGB_CHG*0, -RGB_CHG*1, -RGB_CHG*2, -RGB_CHG*3, -RGB_CHG*4, -RGB_CHG*5, -RGB_CHG*6, -RGB_CHG*7, +RGB_CHG*8, +RGB_CHG*7, +RGB_CHG*6, +RGB_CHG*5, +RGB_CHG*4, +RGB_CHG*3, +RGB_CHG*2, +RGB_CHG*1 }; WRITE16_HANDLER( gaelco2_palette_w ) { int i, color, r, g, b, auxr, auxg, auxb; COMBINE_DATA(&paletteram16[offset]); color = paletteram16[offset]; /* extract RGB components */ r = (color >> 10) & 0x1f; g = (color >> 5) & 0x1f; b = (color >> 0) & 0x1f; r = (r << 3) | (r >> 2); g = (g << 3) | (g >> 2); b = (b << 3) | (b >> 2); /* update game palette */ palette_set_color(4096*0 + offset, r, g, b); /* update shadow/highligh palettes */ for (i = 1; i < 16; i++){ /* because the last palette entry is reserved for shadows and highlights, we don't use it and that way we save some colors so the UI looks fine ;-) */ if ((offset >= 0xff0) && (offset <= 0xfff)) return; auxr = ADJUST_COLOR(r + pen_color_adjust[i]); auxg = ADJUST_COLOR(g + pen_color_adjust[i]); auxb = ADJUST_COLOR(b + pen_color_adjust[i]); palette_set_color(4096*i + offset, auxr, auxg, auxb); } } /*************************************************************************** Start/Stop the video hardware emulation. ***************************************************************************/ VIDEO_START( gaelco2 ) { gaelco2_videoram = spriteram16; /* create tilemaps */ pant[0] = tilemap_create(get_tile_info_gaelco2_screen0,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,64,32); pant[1] = tilemap_create(get_tile_info_gaelco2_screen1,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,64,32); if (!pant[0] || !pant[1]) return 1; /* set tilemap properties */ tilemap_set_transparent_pen(pant[0],0); tilemap_set_transparent_pen(pant[1],0); tilemap_set_scroll_rows(pant[0], 512); tilemap_set_scroll_cols(pant[0], 1); tilemap_set_scroll_rows(pant[1], 512); tilemap_set_scroll_cols(pant[1], 1); dual_monitor = 0; return 0; } #ifdef ONE_MONITOR VIDEO_START( gaelco2_dual ) { gaelco2_videoram = spriteram16; /* create tilemaps */ pant[0] = tilemap_create(get_tile_info_gaelco2_screen0_dual,tilemap_scan_rows,TILEMAP_OPAQUE,16,16,64,32); pant[1] = tilemap_create(get_tile_info_gaelco2_screen1_dual,tilemap_scan_rows,TILEMAP_OPAQUE,16,16,64,32); if (!pant[0] || !pant[1]) return 1; /* set tilemap properties */ tilemap_set_scroll_rows(pant[0], 512); tilemap_set_scroll_cols(pant[0], 1); tilemap_set_scroll_rows(pant[1], 512); tilemap_set_scroll_cols(pant[1], 1); dual_monitor = 1; return 0; } #else VIDEO_START( gaelco2_dual ) { gaelco2_videoram = spriteram16; /* create tilemaps */ pant[0] = tilemap_create(get_tile_info_gaelco2_screen0_dual,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,64,32); pant[1] = tilemap_create(get_tile_info_gaelco2_screen1_dual,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,64,32); if (!pant[0] || !pant[1]) return 1; /* set tilemap properties */ tilemap_set_transparent_pen(pant[0],0); tilemap_set_transparent_pen(pant[1],0); tilemap_set_scroll_rows(pant[0], 512); tilemap_set_scroll_cols(pant[0], 1); tilemap_set_scroll_rows(pant[1], 512); tilemap_set_scroll_cols(pant[1], 1); dual_monitor = 1; return 0; } #endif /*************************************************************************** Sprite Format ------------- Word | Bit(s) | Description -----+-FEDCBA98-76543210-+-------------------------- 0 | -------x xxxxxxxx | sprite bank (sprite number bits 18-10) 0 | xxxxxxx- -------- | sprite color (bits 6-0) 1 | -------x xxxxxxxx | y position 1 | ------x- -------- | sprite enable 1 | -----x-- -------- | flipy 1 | ----x--- -------- | flipx 1 | xxxx---- -------- | sprite y size 2 | ------xx xxxxxxxx | x position 2 | ----xx-- -------- | not used? 2 | xxxx---- -------- | sprite x size 3 | xxxxxxxx xxxxxxxx | pointer to more sprite data Each sprite entry has a pointer to more sprite data. The length of data depends on the sprite size (xsize*ysize). Each entry has the following format: Word | Bit(s) | Description -----+-FEDCBA98-76543210-+-------------------------- 0 | ----xxxx xxxxxxxx | sprite number offset (sprite number bits 11-0) 0 | xxxx---- -------- | sprite color offset (bits 3-0) In dual monitor games, the configuration is the same, but MSB of word 0 is used to select target monitor for the sprite, and the palette is splitted for each monitor. Last sprite color entry is used for shadows/highlights ***************************************************************************/ static void gaelco2_draw_sprites(struct mame_bitmap *bitmap, const struct rectangle *cliprect, int mask, int xoffs) { int j, x, y, ex, ey, px, py; const struct GfxElement *gfx = Machine->gfx[0]; /* get sprite ram start and end offsets */ int start_offset = (gaelco2_vregs[1] & 0x10)*0x100; int end_offset = start_offset + 0x1000; /* sprite offset is based on the visible area */ int spr_x_adjust = (Machine->visible_area.max_x - 320 + 1) - (511 - 320 - 1) - ((gaelco2_vregs[0] >> 4) & 0x01) + xoffs; #ifndef ONE_MONITOR if (dual_monitor){ spr_x_adjust = ((Machine->visible_area.max_x/2) - 320 + 1) - (511 - 320 - 1) - ((gaelco2_vregs[0] >> 4) & 0x01) + xoffs; } #endif for (j = start_offset; j < end_offset; j += 8){ int data = buffered_spriteram16[(j/2) + 0]; int data2 = buffered_spriteram16[(j/2) + 1]; int data3 = buffered_spriteram16[(j/2) + 2]; int data4 = buffered_spriteram16[(j/2) + 3]; int sx = data3 & 0x3ff; int sy = data2 & 0x1ff; int xflip = data2 & 0x800; int yflip = data2 & 0x400; int xsize = ((data3 >> 12) & 0x0f) + 1; int ysize = ((data2 >> 12) & 0x0f) + 1; if (dual_monitor && ((data & 0x8000) != mask)) continue; /* if it's enabled, draw it */ if ((data2 & 0x0200) != 0){ for (y = 0; y < ysize; y++){ for (x = 0; x < xsize; x++){ /* for each x,y of the sprite, fetch the sprite data */ int data5 = buffered_spriteram16[((data4/2) + (y*xsize + x)) & 0x7fff]; int number = ((data & 0x1ff) << 10) + (data5 & 0x0fff); int color = ((data >> 9) & 0x7f) + ((data5 >> 12) & 0x0f); int color_effect = dual_monitor ? ((color & 0x3f) == 0x3f) : (color == 0x7f); ex = xflip ? (xsize - 1 - x) : x; ey = yflip ? (ysize - 1 - y) : y; /* normal sprite, pen 0 transparent */ if (color_effect == 0){ drawgfx(bitmap, gfx, number, color, xflip, yflip, ((sx + ex*16) & 0x3ff) + spr_x_adjust, ((sy + ey*16) & 0x1ff), cliprect, TRANSPARENCY_PEN, 0); } else { /* last palette entry is reserved for shadows and highlights */ /* get a pointer to the current sprite's gfx data */ UINT8 *gfx_src = gfx->gfxdata + (number % gfx->total_elements)*gfx->char_modulo; for (py = 0; py < gfx->height; py++){ /* get a pointer to the current line in the screen bitmap */ int ypos = ((sy + ey*16 + py) & 0x1ff); UINT16 *srcy = ((UINT16 *)bitmap->line[ypos]); int gfx_py = yflip ? (gfx->height - 1 - py) : py; if ((ypos < cliprect->min_y) || (ypos > cliprect->max_y)) continue; for (px = 0; px < gfx->width; px++){ /* get current pixel */ int xpos = (((sx + ex*16 + px) & 0x3ff) + spr_x_adjust) & 0x3ff; UINT16 *pixel = srcy + xpos; int src_color = *pixel; int gfx_px = xflip ? (gfx->width - 1 - px) : px; /* get asociated pen for the current sprite pixel */ int gfx_pen = gfx_src[gfx->line_modulo*gfx_py + gfx_px]; if ((gfx_pen == 0) || (gfx_pen >= 16)) continue; if ((xpos < cliprect->min_x) || (xpos > cliprect->max_x)) continue; /* make background color darker or brighter */ *pixel = src_color + 4096*gfx_pen; } } } } } } } } /*************************************************************************** Display Refresh ***************************************************************************/ VIDEO_UPDATE( gaelco2 ) { int i; /* read scroll values */ int scroll0x = gaelco2_videoram[0x2802/2] + 0x14; int scroll1x = gaelco2_videoram[0x2806/2] + 0x10; int scroll0y = gaelco2_videoram[0x2800/2] + 0x01; int scroll1y = gaelco2_videoram[0x2804/2] + 0x01; /* set y scroll registers */ tilemap_set_scrolly(pant[0], 0, scroll0y & 0x1ff); tilemap_set_scrolly(pant[1], 0, scroll1y & 0x1ff); /* set x linescroll registers */ for (i = 0; i < 512; i++){ tilemap_set_scrollx(pant[0], i & 0x1ff, (gaelco2_vregs[0] & 0x8000) ? (gaelco2_videoram[(0x2000/2) + i] + 0x14) & 0x3ff : scroll0x & 0x3ff); tilemap_set_scrollx(pant[1], i & 0x1ff, (gaelco2_vregs[1] & 0x8000) ? (gaelco2_videoram[(0x2400/2) + i] + 0x10) & 0x3ff : scroll1x & 0x3ff); } /* draw screen */ fillbitmap(bitmap, Machine->pens[0], cliprect); tilemap_draw(bitmap, cliprect, pant[1], 0, 0); tilemap_draw(bitmap, cliprect, pant[0], 0, 0); gaelco2_draw_sprites(bitmap, cliprect, 0, 0); } VIDEO_UPDATE( bang ) { /* standard rendering on this hardware */ video_update_gaelco2(bitmap, cliprect); /* draw crosshairs */ { int posx, posy; /* 1P Gun */ posx = readinputport(3)*320/256; posy = readinputport(5)*240/256; draw_crosshair(1, bitmap, posx, posy + 0x0c, cliprect); /* 2P Gun */ posx = readinputport(4)*320/256; posy = readinputport(6)*240/256; draw_crosshair(2, bitmap, posx, posy + 0x0c, cliprect); } } #ifdef ONE_MONITOR VIDEO_UPDATE( gaelco2_dual ) { int i; int xoff0 = 0x14; // intro scenes align better with 0x13, but test screen is definitely 0x14 int xoff1 = xoff0 - 4; int yoff0 = 0x01; int yoff1 = 0x01; /* read scroll values */ int scroll0x = gaelco2_videoram[0x2802/2] + xoff0; int scroll1x = gaelco2_videoram[0x2806/2] + xoff1; int scroll0y = gaelco2_videoram[0x2800/2] + yoff0; int scroll1y = gaelco2_videoram[0x2804/2] + yoff1; /* if linescroll is enabled y-scroll handling changes too? touchgo uses 0x1f0 / 0x1ef between game and intro screens but actual scroll position needs to be different this aligns the crowd with the advertising boards */ if (gaelco2_vregs[0] & 0x8000) { scroll0y += 32; } if (gaelco2_vregs[1] & 0x8000) { scroll1y += 32; } /* set y scroll registers */ tilemap_set_scrolly(pant[0], 0, scroll0y & 0x1ff); tilemap_set_scrolly(pant[1], 0, scroll1y & 0x1ff); /* set x linescroll registers */ for (i = 0; i < 512; i++){ tilemap_set_scrollx(pant[0], i & 0x1ff, (gaelco2_vregs[0] & 0x8000) ? (gaelco2_videoram[(0x2000/2) + i] + xoff0) & 0x3ff : scroll0x & 0x3ff); tilemap_set_scrollx(pant[1], i & 0x1ff, (gaelco2_vregs[1] & 0x8000) ? (gaelco2_videoram[(0x2400/2) + i] + xoff1) & 0x3ff : scroll1x & 0x3ff); } if (readinputport(4) & 0x01){ /* monitor 2 output */ tilemap_draw(bitmap,cliprect,pant[1], 0, 0); gaelco2_draw_sprites(bitmap,cliprect, 0x8000, 0); } else { /* monitor 1 output */ tilemap_draw(bitmap,cliprect,pant[0], 0, 0); gaelco2_draw_sprites(bitmap,cliprect, 0x0000, 0); } } #else VIDEO_UPDATE( gaelco2_dual ) { int i; int xoff0 = 0x14; // intro scenes align better with 0x13, but test screen is definitely 0x14 int xoff1 = xoff0 - 4; int yoff0 = 0x01; int yoff1 = 0x01; /* read scroll values */ int scroll0x = gaelco2_videoram[0x2802/2] + xoff0; int scroll1x = gaelco2_videoram[0x2806/2] + xoff1 - ((Machine->visible_area.max_x/2) + 1); int scroll0y = gaelco2_videoram[0x2800/2] + yoff0; int scroll1y = gaelco2_videoram[0x2804/2] + yoff1; /* if linescroll is enabled y-scroll handling changes too? touchgo uses 0x1f0 / 0x1ef between game and intro screens but actual scroll position needs to be different this aligns the crowd with the advertising boards */ if (gaelco2_vregs[0] & 0x8000) { scroll0y += 32; } if (gaelco2_vregs[1] & 0x8000) { scroll1y += 32; } /* set y scroll registers */ tilemap_set_scrolly(pant[0], 0, scroll0y & 0x1ff); tilemap_set_scrolly(pant[1], 0, scroll1y & 0x1ff); /* set x linescroll registers */ for (i = 0; i < 512; i++){ tilemap_set_scrollx(pant[0], i & 0x1ff, (gaelco2_vregs[0] & 0x8000) ? (gaelco2_videoram[(0x2000/2) + i] + xoff0) & 0x3ff : scroll0x & 0x3ff); tilemap_set_scrollx(pant[1], i & 0x1ff, (gaelco2_vregs[1] & 0x8000) ? (gaelco2_videoram[(0x2400/2) + i] + xoff1) & 0x3ff : scroll1x & 0x3ff); } /* draw screen */ fillbitmap(bitmap, Machine->pens[0], cliprect); { struct rectangle cliprect1, cliprect2; cliprect1.min_x = 0; cliprect1.max_x = Machine->visible_area.max_x/2; cliprect1.min_y = 16; cliprect1.max_y = 256-1; cliprect2.min_x = (Machine->visible_area.max_x/2) + 1; cliprect2.max_x = Machine->visible_area.max_x; cliprect2.min_y = 16; cliprect2.max_y = 256-1; /* monitor 2 output */ tilemap_draw(bitmap,&cliprect2,pant[1], 0, 0); gaelco2_draw_sprites(bitmap,&cliprect2, 0x8000, (Machine->visible_area.max_x/2) + 1); /* monitor 1 output */ tilemap_draw(bitmap,&cliprect1,pant[0], 0, 0); gaelco2_draw_sprites(bitmap,&cliprect1, 0x0000, 0); } } #endif VIDEO_EOF( gaelco2 ) { /* sprites are one frame ahead */ buffer_spriteram16_w(0, 0, 0); }
504719.c
/* Copyright (c) 2013-2018 the Civetweb developers * Copyright (c) 2004-2013 Sergey Lyubka * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #if defined(__GNUC__) || defined(__MINGW32__) #define GCC_VERSION \ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #if GCC_VERSION >= 40500 /* gcc diagnostic pragmas available */ #define GCC_DIAGNOSTIC #endif #endif #if defined(GCC_DIAGNOSTIC) /* Disable unused macros warnings - not all defines are required * for all systems and all compilers. */ #pragma GCC diagnostic ignored "-Wunused-macros" /* A padding warning is just plain useless */ #pragma GCC diagnostic ignored "-Wpadded" #endif #if defined(__clang__) /* GCC does not (yet) support this pragma */ /* We must set some flags for the headers we include. These flags * are reserved ids according to C99, so we need to disable a * warning for that. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wreserved-id-macro" #endif #if defined(_WIN32) #if !defined(_CRT_SECURE_NO_WARNINGS) #define _CRT_SECURE_NO_WARNINGS /* Disable deprecation warning in VS2005 */ #endif #if !defined(_WIN32_WINNT) /* defined for tdm-gcc so we can use getnameinfo */ #define _WIN32_WINNT 0x0501 #endif #else #if !defined(_GNU_SOURCE) #define _GNU_SOURCE /* for setgroups(), pthread_setname_np() */ #endif #if defined(__linux__) && !defined(_XOPEN_SOURCE) #define _XOPEN_SOURCE 600 /* For flockfile() on Linux */ #endif #if !defined(_LARGEFILE_SOURCE) #define _LARGEFILE_SOURCE /* For fseeko(), ftello() */ #endif #if !defined(_FILE_OFFSET_BITS) #define _FILE_OFFSET_BITS 64 /* Use 64-bit file offsets by default */ #endif #if !defined(__STDC_FORMAT_MACROS) #define __STDC_FORMAT_MACROS /* <inttypes.h> wants this for C++ */ #endif #if !defined(__STDC_LIMIT_MACROS) #define __STDC_LIMIT_MACROS /* C++ wants that for INT64_MAX */ #endif #if !defined(_DARWIN_UNLIMITED_SELECT) #define _DARWIN_UNLIMITED_SELECT #endif #if defined(__sun) #define __EXTENSIONS__ /* to expose flockfile and friends in stdio.h */ #define __inline inline /* not recognized on older compiler versions */ #endif #endif #if defined(__clang__) /* Enable reserved-id-macro warning again. */ #pragma GCC diagnostic pop #endif #if defined(USE_LUA) #define USE_TIMERS #endif #if defined(_MSC_VER) /* 'type cast' : conversion from 'int' to 'HANDLE' of greater size */ #pragma warning(disable : 4306) /* conditional expression is constant: introduced by FD_SET(..) */ #pragma warning(disable : 4127) /* non-constant aggregate initializer: issued due to missing C99 support */ #pragma warning(disable : 4204) /* padding added after data member */ #pragma warning(disable : 4820) /* not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */ #pragma warning(disable : 4668) /* no function prototype given: converting '()' to '(void)' */ #pragma warning(disable : 4255) /* function has been selected for automatic inline expansion */ #pragma warning(disable : 4711) #endif /* This code uses static_assert to check some conditions. * Unfortunately some compilers still do not support it, so we have a * replacement function here. */ #if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201100L #define mg_static_assert _Static_assert #elif defined(__cplusplus) && __cplusplus >= 201103L #define mg_static_assert static_assert #else char static_assert_replacement[1]; #define mg_static_assert(cond, txt) \ extern char static_assert_replacement[(cond) ? 1 : -1] #endif mg_static_assert(sizeof(int) == 4 || sizeof(int) == 8, "int data type size check"); mg_static_assert(sizeof(void *) == 4 || sizeof(void *) == 8, "pointer data type size check"); mg_static_assert(sizeof(void *) >= sizeof(int), "data type size check"); /* Alternative queue is well tested and should be the new default */ #if defined(NO_ALTERNATIVE_QUEUE) #if defined(ALTERNATIVE_QUEUE) #error "Define ALTERNATIVE_QUEUE or NO_ALTERNATIVE_QUEUE or none, but not both" #endif #else #define ALTERNATIVE_QUEUE #endif /* DTL -- including winsock2.h works better if lean and mean */ #if !defined(WIN32_LEAN_AND_MEAN) #define WIN32_LEAN_AND_MEAN #endif #if defined(__SYMBIAN32__) /* According to https://en.wikipedia.org/wiki/Symbian#History, * Symbian is no longer maintained since 2014-01-01. * Recent versions of CivetWeb are no longer tested for Symbian. * It makes no sense, to support an abandoned operating system. */ #error "Symbian is no longer maintained. CivetWeb no longer supports Symbian." #define NO_SSL /* SSL is not supported */ #define NO_CGI /* CGI is not supported */ #define PATH_MAX FILENAME_MAX #endif /* __SYMBIAN32__ */ #if !defined(CIVETWEB_HEADER_INCLUDED) /* Include the header file here, so the CivetWeb interface is defined for the * entire implementation, including the following forward definitions. */ #include "civetweb.h" #endif #if !defined(DEBUG_TRACE) #if defined(DEBUG) static void DEBUG_TRACE_FUNC(const char *func, unsigned line, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(3, 4); #define DEBUG_TRACE(fmt, ...) \ DEBUG_TRACE_FUNC(__func__, __LINE__, fmt, __VA_ARGS__) #define NEED_DEBUG_TRACE_FUNC #else #define DEBUG_TRACE(fmt, ...) \ do { \ } while (0) #endif /* DEBUG */ #endif /* DEBUG_TRACE */ #if !defined(DEBUG_ASSERT) #if defined(DEBUG) #define DEBUG_ASSERT(cond) \ do { \ if (!(cond)) { \ DEBUG_TRACE("ASSERTION FAILED: %s", #cond); \ exit(2); /* Exit with error */ \ } \ } while (0) #else #define DEBUG_ASSERT(cond) #endif /* DEBUG */ #endif #if defined(__GNUC__) && defined(GCC_INSTRUMENTATION) void __cyg_profile_func_enter(void *this_fn, void *call_site) __attribute__((no_instrument_function)); void __cyg_profile_func_exit(void *this_fn, void *call_site) __attribute__((no_instrument_function)); void __cyg_profile_func_enter(void *this_fn, void *call_site) { if ((void *)this_fn != (void *)printf) { printf("E %p %p\n", this_fn, call_site); } } void __cyg_profile_func_exit(void *this_fn, void *call_site) { if ((void *)this_fn != (void *)printf) { printf("X %p %p\n", this_fn, call_site); } } #endif #if !defined(IGNORE_UNUSED_RESULT) #define IGNORE_UNUSED_RESULT(a) ((void)((a) && 1)) #endif #if defined(__GNUC__) || defined(__MINGW32__) /* GCC unused function attribute seems fundamentally broken. * Several attempts to tell the compiler "THIS FUNCTION MAY BE USED * OR UNUSED" for individual functions failed. * Either the compiler creates an "unused-function" warning if a * function is not marked with __attribute__((unused)). * On the other hand, if the function is marked with this attribute, * but is used, the compiler raises a completely idiotic * "used-but-marked-unused" warning - and * #pragma GCC diagnostic ignored "-Wused-but-marked-unused" * raises error: unknown option after "#pragma GCC diagnostic". * Disable this warning completely, until the GCC guys sober up * again. */ #pragma GCC diagnostic ignored "-Wunused-function" #define FUNCTION_MAY_BE_UNUSED /* __attribute__((unused)) */ #else #define FUNCTION_MAY_BE_UNUSED #endif /* Some ANSI #includes are not available on Windows CE */ #if !defined(_WIN32_WCE) #include <errno.h> #include <fcntl.h> #include <signal.h> #include <sys/stat.h> #include <sys/types.h> #endif /* !_WIN32_WCE */ #if defined(__clang__) /* When using -Weverything, clang does not accept it's own headers * in a release build configuration. Disable what is too much in * -Weverything. */ #pragma clang diagnostic ignored "-Wdisabled-macro-expansion" #endif #if defined(__GNUC__) || defined(__MINGW32__) /* Who on earth came to the conclusion, using __DATE__ should rise * an "expansion of date or time macro is not reproducible" * warning. That's exactly what was intended by using this macro. * Just disable this nonsense warning. */ /* And disabling them does not work either: * #pragma clang diagnostic ignored "-Wno-error=date-time" * #pragma clang diagnostic ignored "-Wdate-time" * So we just have to disable ALL warnings for some lines * of code. * This seems to be a known GCC bug, not resolved since 2012: * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431 */ #endif #if defined(__MACH__) /* Apple OSX section */ #if defined(__clang__) #if (__clang_major__ == 3) && ((__clang_minor__ == 7) || (__clang_minor__ == 8)) /* Avoid warnings for Xcode 7. It seems it does no longer exist in Xcode 8 */ #pragma clang diagnostic ignored "-Wno-reserved-id-macro" #pragma clang diagnostic ignored "-Wno-keyword-macro" #endif #endif #define CLOCK_MONOTONIC (1) #define CLOCK_REALTIME (2) #include <mach/clock.h> #include <mach/mach.h> #include <mach/mach_time.h> #include <sys/errno.h> #include <sys/time.h> /* clock_gettime is not implemented on OSX prior to 10.12 */ static int _civet_clock_gettime(int clk_id, struct timespec *t) { memset(t, 0, sizeof(*t)); if (clk_id == CLOCK_REALTIME) { struct timeval now; int rv = gettimeofday(&now, NULL); if (rv) { return rv; } t->tv_sec = now.tv_sec; t->tv_nsec = now.tv_usec * 1000; return 0; } else if (clk_id == CLOCK_MONOTONIC) { static uint64_t clock_start_time = 0; static mach_timebase_info_data_t timebase_ifo = {0, 0}; uint64_t now = mach_absolute_time(); if (clock_start_time == 0) { kern_return_t mach_status = mach_timebase_info(&timebase_ifo); DEBUG_ASSERT(mach_status == KERN_SUCCESS); /* appease "unused variable" warning for release builds */ (void)mach_status; clock_start_time = now; } now = (uint64_t)((double)(now - clock_start_time) * (double)timebase_ifo.numer / (double)timebase_ifo.denom); t->tv_sec = now / 1000000000; t->tv_nsec = now % 1000000000; return 0; } return -1; /* EINVAL - Clock ID is unknown */ } /* if clock_gettime is declared, then __CLOCK_AVAILABILITY will be defined */ #if defined(__CLOCK_AVAILABILITY) /* If we compiled with Mac OSX 10.12 or later, then clock_gettime will be * declared but it may be NULL at runtime. So we need to check before using * it. */ static int _civet_safe_clock_gettime(int clk_id, struct timespec *t) { if (clock_gettime) { return clock_gettime(clk_id, t); } return _civet_clock_gettime(clk_id, t); } #define clock_gettime _civet_safe_clock_gettime #else #define clock_gettime _civet_clock_gettime #endif #endif #include <ctype.h> #include <limits.h> #include <stdarg.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> /********************************************************************/ /* CivetWeb configuration defines */ /********************************************************************/ /* Maximum number of threads that can be configured. * The number of threads actually created depends on the "num_threads" * configuration parameter, but this is the upper limit. */ #if !defined(MAX_WORKER_THREADS) #define MAX_WORKER_THREADS (1024 * 64) /* in threads (count) */ #endif /* Timeout interval for select/poll calls. * The timeouts depend on "*_timeout_ms" configuration values, but long * timeouts are split into timouts as small as SOCKET_TIMEOUT_QUANTUM. * This reduces the time required to stop the server. */ #if !defined(SOCKET_TIMEOUT_QUANTUM) #define SOCKET_TIMEOUT_QUANTUM (2000) /* in ms */ #endif /* Do not try to compress files smaller than this limit. */ #if !defined(MG_FILE_COMPRESSION_SIZE_LIMIT) #define MG_FILE_COMPRESSION_SIZE_LIMIT (1024) /* in bytes */ #endif #if !defined(PASSWORDS_FILE_NAME) #define PASSWORDS_FILE_NAME ".htpasswd" #endif /* Initial buffer size for all CGI environment variables. In case there is * not enough space, another block is allocated. */ #if !defined(CGI_ENVIRONMENT_SIZE) #define CGI_ENVIRONMENT_SIZE (4096) /* in bytes */ #endif /* Maximum number of environment variables. */ #if !defined(MAX_CGI_ENVIR_VARS) #define MAX_CGI_ENVIR_VARS (256) /* in variables (count) */ #endif /* General purpose buffer size. */ #if !defined(MG_BUF_LEN) /* in bytes */ #define MG_BUF_LEN (1024 * 8) #endif /* Size of the accepted socket queue (in case the old queue implementation * is used). */ #if !defined(MGSQLEN) #define MGSQLEN (20) /* count */ #endif /********************************************************************/ /* Helper makros */ #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) /* Standard defines */ #if !defined(INT64_MAX) #define INT64_MAX (9223372036854775807) #endif #define SHUTDOWN_RD (0) #define SHUTDOWN_WR (1) #define SHUTDOWN_BOTH (2) mg_static_assert(MAX_WORKER_THREADS >= 1, "worker threads must be a positive number"); mg_static_assert(sizeof(size_t) == 4 || sizeof(size_t) == 8, "size_t data type size check"); #if defined(_WIN32) /* WINDOWS include block */ #include <windows.h> #include <winsock2.h> /* DTL add for SO_EXCLUSIVE */ #include <ws2tcpip.h> typedef const char *SOCK_OPT_TYPE; #if !defined(PATH_MAX) #define W_PATH_MAX (MAX_PATH) /* at most three UTF-8 chars per wchar_t */ #define PATH_MAX (W_PATH_MAX * 3) #else #define W_PATH_MAX ((PATH_MAX + 2) / 3) #endif mg_static_assert(PATH_MAX >= 1, "path length must be a positive number"); #if !defined(_IN_PORT_T) #if !defined(in_port_t) #define in_port_t u_short #endif #endif #if !defined(_WIN32_WCE) #include <direct.h> #include <io.h> #include <process.h> #else /* _WIN32_WCE */ #define NO_CGI /* WinCE has no pipes */ #define NO_POPEN /* WinCE has no popen */ typedef long off_t; #define errno ((int)(GetLastError())) #define strerror(x) (_ultoa(x, (char *)_alloca(sizeof(x) * 3), 10)) #endif /* _WIN32_WCE */ #define MAKEUQUAD(lo, hi) \ ((uint64_t)(((uint32_t)(lo)) | ((uint64_t)((uint32_t)(hi))) << 32)) #define RATE_DIFF (10000000) /* 100 nsecs */ #define EPOCH_DIFF (MAKEUQUAD(0xd53e8000, 0x019db1de)) #define SYS2UNIX_TIME(lo, hi) \ ((time_t)((MAKEUQUAD((lo), (hi)) - EPOCH_DIFF) / RATE_DIFF)) /* Visual Studio 6 does not know __func__ or __FUNCTION__ * The rest of MS compilers use __FUNCTION__, not C99 __func__ * Also use _strtoui64 on modern M$ compilers */ #if defined(_MSC_VER) #if (_MSC_VER < 1300) #define STRX(x) #x #define STR(x) STRX(x) #define __func__ __FILE__ ":" STR(__LINE__) #define strtoull(x, y, z) ((unsigned __int64)_atoi64(x)) #define strtoll(x, y, z) (_atoi64(x)) #else #define __func__ __FUNCTION__ #define strtoull(x, y, z) (_strtoui64(x, y, z)) #define strtoll(x, y, z) (_strtoi64(x, y, z)) #endif #endif /* _MSC_VER */ #define ERRNO ((int)(GetLastError())) #define NO_SOCKLEN_T #if defined(_WIN64) || defined(__MINGW64__) #if !defined(SSL_LIB) #define SSL_LIB "ssleay64.dll" #endif #if !defined(CRYPTO_LIB) #define CRYPTO_LIB "libeay64.dll" #endif #else #if !defined(SSL_LIB) #define SSL_LIB "ssleay32.dll" #endif #if !defined(CRYPTO_LIB) #define CRYPTO_LIB "libeay32.dll" #endif #endif #define O_NONBLOCK (0) #if !defined(W_OK) #define W_OK (2) /* http://msdn.microsoft.com/en-us/library/1w06ktdy.aspx */ #endif #if !defined(EWOULDBLOCK) #define EWOULDBLOCK WSAEWOULDBLOCK #endif /* !EWOULDBLOCK */ #define _POSIX_ #define INT64_FMT "I64d" #define UINT64_FMT "I64u" #define WINCDECL __cdecl #define vsnprintf_impl _vsnprintf #define access _access #define mg_sleep(x) (Sleep(x)) #define pipe(x) _pipe(x, MG_BUF_LEN, _O_BINARY) #if !defined(popen) #define popen(x, y) (_popen(x, y)) #endif #if !defined(pclose) #define pclose(x) (_pclose(x)) #endif #define close(x) (_close(x)) #define dlsym(x, y) (GetProcAddress((HINSTANCE)(x), (y))) #define RTLD_LAZY (0) #define fseeko(x, y, z) ((_lseeki64(_fileno(x), (y), (z)) == -1) ? -1 : 0) #define fdopen(x, y) (_fdopen((x), (y))) #define write(x, y, z) (_write((x), (y), (unsigned)z)) #define read(x, y, z) (_read((x), (y), (unsigned)z)) #define flockfile(x) (EnterCriticalSection(&global_log_file_lock)) #define funlockfile(x) (LeaveCriticalSection(&global_log_file_lock)) #define sleep(x) (Sleep((x)*1000)) #define rmdir(x) (_rmdir(x)) #if defined(_WIN64) || !defined(__MINGW32__) /* Only MinGW 32 bit is missing this function */ #define timegm(x) (_mkgmtime(x)) #else time_t timegm(struct tm *tm); #define NEED_TIMEGM #endif #if !defined(fileno) #define fileno(x) (_fileno(x)) #endif /* !fileno MINGW #defines fileno */ typedef HANDLE pthread_mutex_t; typedef DWORD pthread_key_t; typedef HANDLE pthread_t; typedef struct { CRITICAL_SECTION threadIdSec; struct mg_workerTLS *waiting_thread; /* The chain of threads */ } pthread_cond_t; #if !defined(__clockid_t_defined) typedef DWORD clockid_t; #endif #if !defined(CLOCK_MONOTONIC) #define CLOCK_MONOTONIC (1) #endif #if !defined(CLOCK_REALTIME) #define CLOCK_REALTIME (2) #endif #if !defined(CLOCK_THREAD) #define CLOCK_THREAD (3) #endif #if !defined(CLOCK_PROCESS) #define CLOCK_PROCESS (4) #endif #if defined(_MSC_VER) && (_MSC_VER >= 1900) #define _TIMESPEC_DEFINED #endif #if !defined(_TIMESPEC_DEFINED) struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; #endif #if !defined(WIN_PTHREADS_TIME_H) #define MUST_IMPLEMENT_CLOCK_GETTIME #endif #if defined(MUST_IMPLEMENT_CLOCK_GETTIME) #define clock_gettime mg_clock_gettime static int clock_gettime(clockid_t clk_id, struct timespec *tp) { FILETIME ft; ULARGE_INTEGER li, li2; BOOL ok = FALSE; double d; static double perfcnt_per_sec = 0.0; static BOOL initialized = FALSE; if (!initialized) { QueryPerformanceFrequency((LARGE_INTEGER *)&li); perfcnt_per_sec = 1.0 / li.QuadPart; initialized = TRUE; } if (tp) { memset(tp, 0, sizeof(*tp)); if (clk_id == CLOCK_REALTIME) { /* BEGIN: CLOCK_REALTIME = wall clock (date and time) */ GetSystemTimeAsFileTime(&ft); li.LowPart = ft.dwLowDateTime; li.HighPart = ft.dwHighDateTime; li.QuadPart -= 116444736000000000; /* 1.1.1970 in filedate */ tp->tv_sec = (time_t)(li.QuadPart / 10000000); tp->tv_nsec = (long)(li.QuadPart % 10000000) * 100; ok = TRUE; /* END: CLOCK_REALTIME */ } else if (clk_id == CLOCK_MONOTONIC) { /* BEGIN: CLOCK_MONOTONIC = stopwatch (time differences) */ QueryPerformanceCounter((LARGE_INTEGER *)&li); d = li.QuadPart * perfcnt_per_sec; tp->tv_sec = (time_t)d; d -= (double)tp->tv_sec; tp->tv_nsec = (long)(d * 1.0E9); ok = TRUE; /* END: CLOCK_MONOTONIC */ } else if (clk_id == CLOCK_THREAD) { /* BEGIN: CLOCK_THREAD = CPU usage of thread */ FILETIME t_create, t_exit, t_kernel, t_user; if (GetThreadTimes(GetCurrentThread(), &t_create, &t_exit, &t_kernel, &t_user)) { li.LowPart = t_user.dwLowDateTime; li.HighPart = t_user.dwHighDateTime; li2.LowPart = t_kernel.dwLowDateTime; li2.HighPart = t_kernel.dwHighDateTime; li.QuadPart += li2.QuadPart; tp->tv_sec = (time_t)(li.QuadPart / 10000000); tp->tv_nsec = (long)(li.QuadPart % 10000000) * 100; ok = TRUE; } /* END: CLOCK_THREAD */ } else if (clk_id == CLOCK_PROCESS) { /* BEGIN: CLOCK_PROCESS = CPU usage of process */ FILETIME t_create, t_exit, t_kernel, t_user; if (GetProcessTimes(GetCurrentProcess(), &t_create, &t_exit, &t_kernel, &t_user)) { li.LowPart = t_user.dwLowDateTime; li.HighPart = t_user.dwHighDateTime; li2.LowPart = t_kernel.dwLowDateTime; li2.HighPart = t_kernel.dwHighDateTime; li.QuadPart += li2.QuadPart; tp->tv_sec = (time_t)(li.QuadPart / 10000000); tp->tv_nsec = (long)(li.QuadPart % 10000000) * 100; ok = TRUE; } /* END: CLOCK_PROCESS */ } else { /* BEGIN: unknown clock */ /* ok = FALSE; already set by init */ /* END: unknown clock */ } } return ok ? 0 : -1; } #endif #define pid_t HANDLE /* MINGW typedefs pid_t to int. Using #define here. */ static int pthread_mutex_lock(pthread_mutex_t *); static int pthread_mutex_unlock(pthread_mutex_t *); static void path_to_unicode(const struct mg_connection *conn, const char *path, wchar_t *wbuf, size_t wbuf_len); /* All file operations need to be rewritten to solve #246. */ struct mg_file; static const char * mg_fgets(char *buf, size_t size, struct mg_file *filep, char **p); /* POSIX dirent interface */ struct dirent { char d_name[PATH_MAX]; }; typedef struct DIR { HANDLE handle; WIN32_FIND_DATAW info; struct dirent result; } DIR; #if defined(HAVE_POLL) #define mg_pollfd pollfd #else struct mg_pollfd { SOCKET fd; short events; short revents; }; #endif /* Mark required libraries */ #if defined(_MSC_VER) #pragma comment(lib, "Ws2_32.lib") #endif #else /* defined(_WIN32) - WINDOWS vs UNIX include block */ #include <arpa/inet.h> #include <inttypes.h> #include <netdb.h> #include <netinet/in.h> #include <netinet/tcp.h> #include <stdint.h> #include <sys/poll.h> #include <sys/socket.h> #include <sys/time.h> #include <sys/utsname.h> #include <sys/wait.h> typedef const void *SOCK_OPT_TYPE; #if defined(ANDROID) typedef unsigned short int in_port_t; #endif #include <dirent.h> #include <grp.h> #include <pwd.h> #include <unistd.h> #define vsnprintf_impl vsnprintf #if !defined(NO_SSL_DL) && !defined(NO_SSL) #include <dlfcn.h> #endif #include <pthread.h> #if defined(__MACH__) #define SSL_LIB "libssl.dylib" #define CRYPTO_LIB "libcrypto.dylib" #else #if !defined(SSL_LIB) #define SSL_LIB "libssl.so" #endif #if !defined(CRYPTO_LIB) #define CRYPTO_LIB "libcrypto.so" #endif #endif #if !defined(O_BINARY) #define O_BINARY (0) #endif /* O_BINARY */ #define closesocket(a) (close(a)) #define mg_mkdir(conn, path, mode) (mkdir(path, mode)) #define mg_remove(conn, x) (remove(x)) #define mg_sleep(x) (usleep((x)*1000)) #define mg_opendir(conn, x) (opendir(x)) #define mg_closedir(x) (closedir(x)) #define mg_readdir(x) (readdir(x)) #define ERRNO (errno) #define INVALID_SOCKET (-1) #define INT64_FMT PRId64 #define UINT64_FMT PRIu64 typedef int SOCKET; #define WINCDECL #if defined(__hpux) /* HPUX 11 does not have monotonic, fall back to realtime */ #if !defined(CLOCK_MONOTONIC) #define CLOCK_MONOTONIC CLOCK_REALTIME #endif /* HPUX defines socklen_t incorrectly as size_t which is 64bit on * Itanium. Without defining _XOPEN_SOURCE or _XOPEN_SOURCE_EXTENDED * the prototypes use int* rather than socklen_t* which matches the * actual library expectation. When called with the wrong size arg * accept() returns a zero client inet addr and check_acl() always * fails. Since socklen_t is widely used below, just force replace * their typedef with int. - DTL */ #define socklen_t int #endif /* hpux */ #define mg_pollfd pollfd #endif /* defined(_WIN32) - WINDOWS vs UNIX include block */ /* Maximum queue length for pending connections. This value is passed as * parameter to the "listen" socket call. */ #if !defined(SOMAXCONN) /* This symbol may be defined in winsock2.h so this must after that include */ #define SOMAXCONN (100) /* in pending connections (count) */ #endif /* In case our C library is missing "timegm", provide an implementation */ #if defined(NEED_TIMEGM) static inline int is_leap(int y) { return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; } static inline int count_leap(int y) { return (y - 1969) / 4 - (y - 1901) / 100 + (y - 1601) / 400; } time_t timegm(struct tm *tm) { static const unsigned short ydays[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; int year = tm->tm_year + 1900; int mon = tm->tm_mon; int mday = tm->tm_mday - 1; int hour = tm->tm_hour; int min = tm->tm_min; int sec = tm->tm_sec; if (year < 1970 || mon < 0 || mon > 11 || mday < 0 || (mday >= ydays[mon + 1] - ydays[mon] + (mon == 1 && is_leap(year) ? 1 : 0)) || hour < 0 || hour > 23 || min < 0 || min > 59 || sec < 0 || sec > 60) return -1; time_t res = year - 1970; res *= 365; res += mday; res += ydays[mon] + (mon > 1 && is_leap(year) ? 1 : 0); res += count_leap(year); res *= 24; res += hour; res *= 60; res += min; res *= 60; res += sec; return res; } #endif /* NEED_TIMEGM */ /* va_copy should always be a macro, C99 and C++11 - DTL */ #if !defined(va_copy) #define va_copy(x, y) ((x) = (y)) #endif #if defined(_WIN32) /* Create substitutes for POSIX functions in Win32. */ #if defined(GCC_DIAGNOSTIC) /* Show no warning in case system functions are not used. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #endif static CRITICAL_SECTION global_log_file_lock; FUNCTION_MAY_BE_UNUSED static DWORD pthread_self(void) { return GetCurrentThreadId(); } FUNCTION_MAY_BE_UNUSED static int pthread_key_create( pthread_key_t *key, void (*_ignored)(void *) /* destructor not supported for Windows */ ) { (void)_ignored; if ((key != 0)) { *key = TlsAlloc(); return (*key != TLS_OUT_OF_INDEXES) ? 0 : -1; } return -2; } FUNCTION_MAY_BE_UNUSED static int pthread_key_delete(pthread_key_t key) { return TlsFree(key) ? 0 : 1; } FUNCTION_MAY_BE_UNUSED static int pthread_setspecific(pthread_key_t key, void *value) { return TlsSetValue(key, value) ? 0 : 1; } FUNCTION_MAY_BE_UNUSED static void * pthread_getspecific(pthread_key_t key) { return TlsGetValue(key); } #if defined(GCC_DIAGNOSTIC) /* Enable unused function warning again */ #pragma GCC diagnostic pop #endif static struct pthread_mutex_undefined_struct *pthread_mutex_attr = NULL; #else static pthread_mutexattr_t pthread_mutex_attr; #endif /* _WIN32 */ #if defined(_WIN32_WCE) /* Create substitutes for POSIX functions in Win32. */ #if defined(GCC_DIAGNOSTIC) /* Show no warning in case system functions are not used. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #endif FUNCTION_MAY_BE_UNUSED static time_t time(time_t *ptime) { time_t t; SYSTEMTIME st; FILETIME ft; GetSystemTime(&st); SystemTimeToFileTime(&st, &ft); t = SYS2UNIX_TIME(ft.dwLowDateTime, ft.dwHighDateTime); if (ptime != NULL) { *ptime = t; } return t; } FUNCTION_MAY_BE_UNUSED static struct tm * localtime_s(const time_t *ptime, struct tm *ptm) { int64_t t = ((int64_t)*ptime) * RATE_DIFF + EPOCH_DIFF; FILETIME ft, lft; SYSTEMTIME st; TIME_ZONE_INFORMATION tzinfo; if (ptm == NULL) { return NULL; } *(int64_t *)&ft = t; FileTimeToLocalFileTime(&ft, &lft); FileTimeToSystemTime(&lft, &st); ptm->tm_year = st.wYear - 1900; ptm->tm_mon = st.wMonth - 1; ptm->tm_wday = st.wDayOfWeek; ptm->tm_mday = st.wDay; ptm->tm_hour = st.wHour; ptm->tm_min = st.wMinute; ptm->tm_sec = st.wSecond; ptm->tm_yday = 0; /* hope nobody uses this */ ptm->tm_isdst = (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_DAYLIGHT) ? 1 : 0; return ptm; } FUNCTION_MAY_BE_UNUSED static struct tm * gmtime_s(const time_t *ptime, struct tm *ptm) { /* FIXME(lsm): fix this. */ return localtime_s(ptime, ptm); } static int mg_atomic_inc(volatile int *addr); static struct tm tm_array[MAX_WORKER_THREADS]; static int tm_index = 0; FUNCTION_MAY_BE_UNUSED static struct tm * localtime(const time_t *ptime) { int i = mg_atomic_inc(&tm_index) % (sizeof(tm_array) / sizeof(tm_array[0])); return localtime_s(ptime, tm_array + i); } FUNCTION_MAY_BE_UNUSED static struct tm * gmtime(const time_t *ptime) { int i = mg_atomic_inc(&tm_index) % ARRAY_SIZE(tm_array); return gmtime_s(ptime, tm_array + i); } FUNCTION_MAY_BE_UNUSED static size_t strftime(char *dst, size_t dst_size, const char *fmt, const struct tm *tm) { /* TODO: (void)mg_snprintf(NULL, dst, dst_size, "implement strftime() * for WinCE"); */ return 0; } #define _beginthreadex(psec, stack, func, prm, flags, ptid) \ (uintptr_t) CreateThread(psec, stack, func, prm, flags, ptid) #define remove(f) mg_remove(NULL, f) FUNCTION_MAY_BE_UNUSED static int rename(const char *a, const char *b) { wchar_t wa[W_PATH_MAX]; wchar_t wb[W_PATH_MAX]; path_to_unicode(NULL, a, wa, ARRAY_SIZE(wa)); path_to_unicode(NULL, b, wb, ARRAY_SIZE(wb)); return MoveFileW(wa, wb) ? 0 : -1; } struct stat { int64_t st_size; time_t st_mtime; }; FUNCTION_MAY_BE_UNUSED static int stat(const char *name, struct stat *st) { wchar_t wbuf[W_PATH_MAX]; WIN32_FILE_ATTRIBUTE_DATA attr; time_t creation_time, write_time; path_to_unicode(NULL, name, wbuf, ARRAY_SIZE(wbuf)); memset(&attr, 0, sizeof(attr)); GetFileAttributesExW(wbuf, GetFileExInfoStandard, &attr); st->st_size = (((int64_t)attr.nFileSizeHigh) << 32) + (int64_t)attr.nFileSizeLow; write_time = SYS2UNIX_TIME(attr.ftLastWriteTime.dwLowDateTime, attr.ftLastWriteTime.dwHighDateTime); creation_time = SYS2UNIX_TIME(attr.ftCreationTime.dwLowDateTime, attr.ftCreationTime.dwHighDateTime); if (creation_time > write_time) { st->st_mtime = creation_time; } else { st->st_mtime = write_time; } return 0; } #define access(x, a) 1 /* not required anyway */ /* WinCE-TODO: define stat, remove, rename, _rmdir, _lseeki64 */ /* Values from errno.h in Windows SDK (Visual Studio). */ #define EEXIST 17 #define EACCES 13 #define ENOENT 2 #if defined(GCC_DIAGNOSTIC) /* Enable unused function warning again */ #pragma GCC diagnostic pop #endif #endif /* defined(_WIN32_WCE) */ #if defined(GCC_DIAGNOSTIC) /* Show no warning in case system functions are not used. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #endif /* defined(GCC_DIAGNOSTIC) */ #if defined(__clang__) /* Show no warning in case system functions are not used. */ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-function" #endif static pthread_mutex_t global_lock_mutex; #if defined(_WIN32) /* Forward declaration for Windows */ FUNCTION_MAY_BE_UNUSED static int pthread_mutex_lock(pthread_mutex_t *mutex); FUNCTION_MAY_BE_UNUSED static int pthread_mutex_unlock(pthread_mutex_t *mutex); #endif FUNCTION_MAY_BE_UNUSED static void mg_global_lock(void) { (void)pthread_mutex_lock(&global_lock_mutex); } FUNCTION_MAY_BE_UNUSED static void mg_global_unlock(void) { (void)pthread_mutex_unlock(&global_lock_mutex); } FUNCTION_MAY_BE_UNUSED static int mg_atomic_inc(volatile int *addr) { int ret; #if defined(_WIN32) && !defined(NO_ATOMICS) /* Depending on the SDK, this function uses either * (volatile unsigned int *) or (volatile LONG *), * so whatever you use, the other SDK is likely to raise a warning. */ ret = InterlockedIncrement((volatile long *)addr); #elif defined(__GNUC__) \ && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0))) \ && !defined(NO_ATOMICS) ret = __sync_add_and_fetch(addr, 1); #else mg_global_lock(); ret = (++(*addr)); mg_global_unlock(); #endif return ret; } FUNCTION_MAY_BE_UNUSED static int mg_atomic_dec(volatile int *addr) { int ret; #if defined(_WIN32) && !defined(NO_ATOMICS) /* Depending on the SDK, this function uses either * (volatile unsigned int *) or (volatile LONG *), * so whatever you use, the other SDK is likely to raise a warning. */ ret = InterlockedDecrement((volatile long *)addr); #elif defined(__GNUC__) \ && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0))) \ && !defined(NO_ATOMICS) ret = __sync_sub_and_fetch(addr, 1); #else mg_global_lock(); ret = (--(*addr)); mg_global_unlock(); #endif return ret; } #if defined(USE_SERVER_STATS) static int64_t mg_atomic_add(volatile int64_t *addr, int64_t value) { int64_t ret; #if defined(_WIN64) && !defined(NO_ATOMICS) ret = InterlockedAdd64(addr, value); #elif defined(__GNUC__) \ && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0))) \ && !defined(NO_ATOMICS) ret = __sync_add_and_fetch(addr, value); #else mg_global_lock(); *addr += value; ret = (*addr); mg_global_unlock(); #endif return ret; } #endif #if defined(GCC_DIAGNOSTIC) /* Show no warning in case system functions are not used. */ #pragma GCC diagnostic pop #endif /* defined(GCC_DIAGNOSTIC) */ #if defined(__clang__) /* Show no warning in case system functions are not used. */ #pragma clang diagnostic pop #endif #if defined(USE_SERVER_STATS) struct mg_memory_stat { volatile int64_t totalMemUsed; volatile int64_t maxMemUsed; volatile int blockCount; }; static struct mg_memory_stat *get_memory_stat(struct mg_context *ctx); static void * mg_malloc_ex(size_t size, struct mg_context *ctx, const char *file, unsigned line) { void *data = malloc(size + 2 * sizeof(uintptr_t)); void *memory = 0; struct mg_memory_stat *mstat = get_memory_stat(ctx); #if defined(MEMORY_DEBUGGING) char mallocStr[256]; #else (void)file; (void)line; #endif if (data) { int64_t mmem = mg_atomic_add(&mstat->totalMemUsed, (int64_t)size); if (mmem > mstat->maxMemUsed) { /* could use atomic compare exchange, but this * seems overkill for statistics data */ mstat->maxMemUsed = mmem; } mg_atomic_inc(&mstat->blockCount); ((uintptr_t *)data)[0] = size; ((uintptr_t *)data)[1] = (uintptr_t)mstat; memory = (void *)(((char *)data) + 2 * sizeof(uintptr_t)); } #if defined(MEMORY_DEBUGGING) sprintf(mallocStr, "MEM: %p %5lu alloc %7lu %4lu --- %s:%u\n", memory, (unsigned long)size, (unsigned long)mstat->totalMemUsed, (unsigned long)mstat->blockCount, file, line); #if defined(_WIN32) OutputDebugStringA(mallocStr); #else DEBUG_TRACE("%s", mallocStr); #endif #endif return memory; } static void * mg_calloc_ex(size_t count, size_t size, struct mg_context *ctx, const char *file, unsigned line) { void *data = mg_malloc_ex(size * count, ctx, file, line); if (data) { memset(data, 0, size * count); } return data; } static void mg_free_ex(void *memory, const char *file, unsigned line) { void *data = (void *)(((char *)memory) - 2 * sizeof(uintptr_t)); #if defined(MEMORY_DEBUGGING) char mallocStr[256]; #else (void)file; (void)line; #endif if (memory) { uintptr_t size = ((uintptr_t *)data)[0]; struct mg_memory_stat *mstat = (struct mg_memory_stat *)(((uintptr_t *)data)[1]); mg_atomic_add(&mstat->totalMemUsed, -(int64_t)size); mg_atomic_dec(&mstat->blockCount); #if defined(MEMORY_DEBUGGING) sprintf(mallocStr, "MEM: %p %5lu free %7lu %4lu --- %s:%u\n", memory, (unsigned long)size, (unsigned long)mstat->totalMemUsed, (unsigned long)mstat->blockCount, file, line); #if defined(_WIN32) OutputDebugStringA(mallocStr); #else DEBUG_TRACE("%s", mallocStr); #endif #endif free(data); } } static void * mg_realloc_ex(void *memory, size_t newsize, struct mg_context *ctx, const char *file, unsigned line) { void *data; void *_realloc; uintptr_t oldsize; #if defined(MEMORY_DEBUGGING) char mallocStr[256]; #else (void)file; (void)line; #endif if (newsize) { if (memory) { /* Reallocate existing block */ struct mg_memory_stat *mstat; data = (void *)(((char *)memory) - 2 * sizeof(uintptr_t)); oldsize = ((uintptr_t *)data)[0]; mstat = (struct mg_memory_stat *)((uintptr_t *)data)[1]; _realloc = realloc(data, newsize + 2 * sizeof(uintptr_t)); if (_realloc) { data = _realloc; mg_atomic_add(&mstat->totalMemUsed, -(int64_t)oldsize); #if defined(MEMORY_DEBUGGING) sprintf(mallocStr, "MEM: %p %5lu r-free %7lu %4lu --- %s:%u\n", memory, (unsigned long)oldsize, (unsigned long)mstat->totalMemUsed, (unsigned long)mstat->blockCount, file, line); #if defined(_WIN32) OutputDebugStringA(mallocStr); #else DEBUG_TRACE("%s", mallocStr); #endif #endif mg_atomic_add(&mstat->totalMemUsed, (int64_t)newsize); #if defined(MEMORY_DEBUGGING) sprintf(mallocStr, "MEM: %p %5lu r-alloc %7lu %4lu --- %s:%u\n", memory, (unsigned long)newsize, (unsigned long)mstat->totalMemUsed, (unsigned long)mstat->blockCount, file, line); #if defined(_WIN32) OutputDebugStringA(mallocStr); #else DEBUG_TRACE("%s", mallocStr); #endif #endif *(uintptr_t *)data = newsize; data = (void *)(((char *)data) + 2 * sizeof(uintptr_t)); } else { #if defined(MEMORY_DEBUGGING) #if defined(_WIN32) OutputDebugStringA("MEM: realloc failed\n"); #else DEBUG_TRACE("%s", "MEM: realloc failed\n"); #endif #endif return _realloc; } } else { /* Allocate new block */ data = mg_malloc_ex(newsize, ctx, file, line); } } else { /* Free existing block */ data = 0; mg_free_ex(memory, file, line); } return data; } #define mg_malloc(a) mg_malloc_ex(a, NULL, __FILE__, __LINE__) #define mg_calloc(a, b) mg_calloc_ex(a, b, NULL, __FILE__, __LINE__) #define mg_realloc(a, b) mg_realloc_ex(a, b, NULL, __FILE__, __LINE__) #define mg_free(a) mg_free_ex(a, __FILE__, __LINE__) #define mg_malloc_ctx(a, c) mg_malloc_ex(a, c, __FILE__, __LINE__) #define mg_calloc_ctx(a, b, c) mg_calloc_ex(a, b, c, __FILE__, __LINE__) #define mg_realloc_ctx(a, b, c) mg_realloc_ex(a, b, c, __FILE__, __LINE__) #else /* USE_SERVER_STATS */ static __inline void * mg_malloc(size_t a) { return malloc(a); } static __inline void * mg_calloc(size_t a, size_t b) { return calloc(a, b); } static __inline void * mg_realloc(void *a, size_t b) { return realloc(a, b); } static __inline void mg_free(void *a) { free(a); } #define mg_malloc_ctx(a, c) mg_malloc(a) #define mg_calloc_ctx(a, b, c) mg_calloc(a, b) #define mg_realloc_ctx(a, b, c) mg_realloc(a, b) #define mg_free_ctx(a, c) mg_free(a) #endif /* USE_SERVER_STATS */ static void mg_vsnprintf(const struct mg_connection *conn, int *truncated, char *buf, size_t buflen, const char *fmt, va_list ap); static void mg_snprintf(const struct mg_connection *conn, int *truncated, char *buf, size_t buflen, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(5, 6); /* This following lines are just meant as a reminder to use the mg-functions * for memory management */ #if defined(malloc) #undef malloc #endif #if defined(calloc) #undef calloc #endif #if defined(realloc) #undef realloc #endif #if defined(free) #undef free #endif #if defined(snprintf) #undef snprintf #endif #if defined(vsnprintf) #undef vsnprintf #endif #define malloc DO_NOT_USE_THIS_FUNCTION__USE_mg_malloc #define calloc DO_NOT_USE_THIS_FUNCTION__USE_mg_calloc #define realloc DO_NOT_USE_THIS_FUNCTION__USE_mg_realloc #define free DO_NOT_USE_THIS_FUNCTION__USE_mg_free #define snprintf DO_NOT_USE_THIS_FUNCTION__USE_mg_snprintf #if defined(_WIN32) /* vsnprintf must not be used in any system, * but this define only works well for Windows. */ #define vsnprintf DO_NOT_USE_THIS_FUNCTION__USE_mg_vsnprintf #endif /* mg_init_library counter */ static int mg_init_library_called = 0; #if !defined(NO_SSL) static int mg_ssl_initialized = 0; #endif static pthread_key_t sTlsKey; /* Thread local storage index */ static int thread_idx_max = 0; #if defined(MG_LEGACY_INTERFACE) #define MG_ALLOW_USING_GET_REQUEST_INFO_FOR_RESPONSE #endif struct mg_workerTLS { int is_master; unsigned long thread_idx; #if defined(_WIN32) HANDLE pthread_cond_helper_mutex; struct mg_workerTLS *next_waiting_thread; #endif #if defined(MG_ALLOW_USING_GET_REQUEST_INFO_FOR_RESPONSE) char txtbuf[4]; #endif }; #if defined(GCC_DIAGNOSTIC) /* Show no warning in case system functions are not used. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #endif /* defined(GCC_DIAGNOSTIC) */ #if defined(__clang__) /* Show no warning in case system functions are not used. */ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-function" #endif /* Get a unique thread ID as unsigned long, independent from the data type * of thread IDs defined by the operating system API. * If two calls to mg_current_thread_id return the same value, they calls * are done from the same thread. If they return different values, they are * done from different threads. (Provided this function is used in the same * process context and threads are not repeatedly created and deleted, but * CivetWeb does not do that). * This function must match the signature required for SSL id callbacks: * CRYPTO_set_id_callback */ FUNCTION_MAY_BE_UNUSED static unsigned long mg_current_thread_id(void) { #if defined(_WIN32) return GetCurrentThreadId(); #else #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" /* For every compiler, either "sizeof(pthread_t) > sizeof(unsigned long)" * or not, so one of the two conditions will be unreachable by construction. * Unfortunately the C standard does not define a way to check this at * compile time, since the #if preprocessor conditions can not use the sizeof * operator as an argument. */ #endif if (sizeof(pthread_t) > sizeof(unsigned long)) { /* This is the problematic case for CRYPTO_set_id_callback: * The OS pthread_t can not be cast to unsigned long. */ struct mg_workerTLS *tls = (struct mg_workerTLS *)pthread_getspecific(sTlsKey); if (tls == NULL) { /* SSL called from an unknown thread: Create some thread index. */ tls = (struct mg_workerTLS *)mg_malloc(sizeof(struct mg_workerTLS)); tls->is_master = -2; /* -2 means "3rd party thread" */ tls->thread_idx = (unsigned)mg_atomic_inc(&thread_idx_max); pthread_setspecific(sTlsKey, tls); } return tls->thread_idx; } else { /* pthread_t may be any data type, so a simple cast to unsigned long * can rise a warning/error, depending on the platform. * Here memcpy is used as an anything-to-anything cast. */ unsigned long ret = 0; pthread_t t = pthread_self(); memcpy(&ret, &t, sizeof(pthread_t)); return ret; } #if defined(__clang__) #pragma clang diagnostic pop #endif #endif } FUNCTION_MAY_BE_UNUSED static uint64_t mg_get_current_time_ns(void) { struct timespec tsnow; clock_gettime(CLOCK_REALTIME, &tsnow); return (((uint64_t)tsnow.tv_sec) * 1000000000) + (uint64_t)tsnow.tv_nsec; } #if defined(GCC_DIAGNOSTIC) /* Show no warning in case system functions are not used. */ #pragma GCC diagnostic pop #endif /* defined(GCC_DIAGNOSTIC) */ #if defined(__clang__) /* Show no warning in case system functions are not used. */ #pragma clang diagnostic pop #endif #if defined(NEED_DEBUG_TRACE_FUNC) static void DEBUG_TRACE_FUNC(const char *func, unsigned line, const char *fmt, ...) { va_list args; uint64_t nsnow; static uint64_t nslast; struct timespec tsnow; /* Get some operating system independent thread id */ unsigned long thread_id = mg_current_thread_id(); clock_gettime(CLOCK_REALTIME, &tsnow); nsnow = ((uint64_t)tsnow.tv_sec) * ((uint64_t)1000000000) + ((uint64_t)tsnow.tv_nsec); if (!nslast) { nslast = nsnow; } flockfile(stdout); printf("*** %lu.%09lu %12" INT64_FMT " %lu %s:%u: ", (unsigned long)tsnow.tv_sec, (unsigned long)tsnow.tv_nsec, nsnow - nslast, thread_id, func, line); va_start(args, fmt); vprintf(fmt, args); va_end(args); putchar('\n'); fflush(stdout); funlockfile(stdout); nslast = nsnow; } #endif /* NEED_DEBUG_TRACE_FUNC */ #define MD5_STATIC static #include "md5.inl" /* Darwin prior to 7.0 and Win32 do not have socklen_t */ #if defined(NO_SOCKLEN_T) typedef int socklen_t; #endif /* NO_SOCKLEN_T */ #define IP_ADDR_STR_LEN (50) /* IPv6 hex string is 46 chars */ #if !defined(MSG_NOSIGNAL) #define MSG_NOSIGNAL (0) #endif #if defined(NO_SSL) typedef struct SSL SSL; /* dummy for SSL argument to push/pull */ typedef struct SSL_CTX SSL_CTX; #else #if defined(NO_SSL_DL) #include <openssl/bn.h> #include <openssl/conf.h> #include <openssl/crypto.h> #include <openssl/dh.h> #include <openssl/engine.h> #include <openssl/err.h> #include <openssl/opensslv.h> #include <openssl/pem.h> #include <openssl/ssl.h> #include <openssl/tls1.h> #include <openssl/x509.h> #if defined(WOLFSSL_VERSION) /* Additional defines for WolfSSL, see * https://github.com/civetweb/civetweb/issues/583 */ #include "wolfssl_extras.inl" #endif #if (OPENSSL_VERSION_NUMBER >= 0x10100000L) /* If OpenSSL headers are included, automatically select the API version */ #if !defined(OPENSSL_API_1_1) #define OPENSSL_API_1_1 #endif #define OPENSSL_REMOVE_THREAD_STATE() #else #define OPENSSL_REMOVE_THREAD_STATE() ERR_remove_thread_state(NULL) #endif #else /* SSL loaded dynamically from DLL. * I put the prototypes here to be independent from OpenSSL source * installation. */ typedef struct ssl_st SSL; typedef struct ssl_method_st SSL_METHOD; typedef struct ssl_ctx_st SSL_CTX; typedef struct x509_store_ctx_st X509_STORE_CTX; typedef struct x509_name X509_NAME; typedef struct asn1_integer ASN1_INTEGER; typedef struct bignum BIGNUM; typedef struct ossl_init_settings_st OPENSSL_INIT_SETTINGS; typedef struct evp_md EVP_MD; typedef struct x509 X509; #define SSL_CTRL_OPTIONS (32) #define SSL_CTRL_CLEAR_OPTIONS (77) #define SSL_CTRL_SET_ECDH_AUTO (94) #define OPENSSL_INIT_NO_LOAD_SSL_STRINGS 0x00100000L #define OPENSSL_INIT_LOAD_SSL_STRINGS 0x00200000L #define OPENSSL_INIT_LOAD_CRYPTO_STRINGS 0x00000002L #define SSL_VERIFY_NONE (0) #define SSL_VERIFY_PEER (1) #define SSL_VERIFY_FAIL_IF_NO_PEER_CERT (2) #define SSL_VERIFY_CLIENT_ONCE (4) #define SSL_OP_ALL ((long)(0x80000BFFUL)) #define SSL_OP_NO_SSLv2 (0x01000000L) #define SSL_OP_NO_SSLv3 (0x02000000L) #define SSL_OP_NO_TLSv1 (0x04000000L) #define SSL_OP_NO_TLSv1_2 (0x08000000L) #define SSL_OP_NO_TLSv1_1 (0x10000000L) #define SSL_OP_SINGLE_DH_USE (0x00100000L) #define SSL_OP_CIPHER_SERVER_PREFERENCE (0x00400000L) #define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION (0x00010000L) #define SSL_OP_NO_COMPRESSION (0x00020000L) #define SSL_CB_HANDSHAKE_START (0x10) #define SSL_CB_HANDSHAKE_DONE (0x20) #define SSL_ERROR_NONE (0) #define SSL_ERROR_SSL (1) #define SSL_ERROR_WANT_READ (2) #define SSL_ERROR_WANT_WRITE (3) #define SSL_ERROR_WANT_X509_LOOKUP (4) #define SSL_ERROR_SYSCALL (5) /* see errno */ #define SSL_ERROR_ZERO_RETURN (6) #define SSL_ERROR_WANT_CONNECT (7) #define SSL_ERROR_WANT_ACCEPT (8) #define TLSEXT_TYPE_server_name (0) #define TLSEXT_NAMETYPE_host_name (0) #define SSL_TLSEXT_ERR_OK (0) #define SSL_TLSEXT_ERR_ALERT_WARNING (1) #define SSL_TLSEXT_ERR_ALERT_FATAL (2) #define SSL_TLSEXT_ERR_NOACK (3) struct ssl_func { const char *name; /* SSL function name */ void (*ptr)(void); /* Function pointer */ }; #if defined(OPENSSL_API_1_1) #define SSL_free (*(void (*)(SSL *))ssl_sw[0].ptr) #define SSL_accept (*(int (*)(SSL *))ssl_sw[1].ptr) #define SSL_connect (*(int (*)(SSL *))ssl_sw[2].ptr) #define SSL_read (*(int (*)(SSL *, void *, int))ssl_sw[3].ptr) #define SSL_write (*(int (*)(SSL *, const void *, int))ssl_sw[4].ptr) #define SSL_get_error (*(int (*)(SSL *, int))ssl_sw[5].ptr) #define SSL_set_fd (*(int (*)(SSL *, SOCKET))ssl_sw[6].ptr) #define SSL_new (*(SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr) #define SSL_CTX_new (*(SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr) #define TLS_server_method (*(SSL_METHOD * (*)(void)) ssl_sw[9].ptr) #define OPENSSL_init_ssl \ (*(int (*)(uint64_t opts, \ const OPENSSL_INIT_SETTINGS *settings))ssl_sw[10] \ .ptr) #define SSL_CTX_use_PrivateKey_file \ (*(int (*)(SSL_CTX *, const char *, int))ssl_sw[11].ptr) #define SSL_CTX_use_certificate_file \ (*(int (*)(SSL_CTX *, const char *, int))ssl_sw[12].ptr) #define SSL_CTX_set_default_passwd_cb \ (*(void (*)(SSL_CTX *, mg_callback_t))ssl_sw[13].ptr) #define SSL_CTX_free (*(void (*)(SSL_CTX *))ssl_sw[14].ptr) #define SSL_CTX_use_certificate_chain_file \ (*(int (*)(SSL_CTX *, const char *))ssl_sw[15].ptr) #define TLS_client_method (*(SSL_METHOD * (*)(void)) ssl_sw[16].ptr) #define SSL_pending (*(int (*)(SSL *))ssl_sw[17].ptr) #define SSL_CTX_set_verify \ (*(void (*)(SSL_CTX *, \ int, \ int (*verify_callback)(int, X509_STORE_CTX *)))ssl_sw[18] \ .ptr) #define SSL_shutdown (*(int (*)(SSL *))ssl_sw[19].ptr) #define SSL_CTX_load_verify_locations \ (*(int (*)(SSL_CTX *, const char *, const char *))ssl_sw[20].ptr) #define SSL_CTX_set_default_verify_paths (*(int (*)(SSL_CTX *))ssl_sw[21].ptr) #define SSL_CTX_set_verify_depth (*(void (*)(SSL_CTX *, int))ssl_sw[22].ptr) #define SSL_get_peer_certificate (*(X509 * (*)(SSL *)) ssl_sw[23].ptr) #define SSL_get_version (*(const char *(*)(SSL *))ssl_sw[24].ptr) #define SSL_get_current_cipher (*(SSL_CIPHER * (*)(SSL *)) ssl_sw[25].ptr) #define SSL_CIPHER_get_name \ (*(const char *(*)(const SSL_CIPHER *))ssl_sw[26].ptr) #define SSL_CTX_check_private_key (*(int (*)(SSL_CTX *))ssl_sw[27].ptr) #define SSL_CTX_set_session_id_context \ (*(int (*)(SSL_CTX *, const unsigned char *, unsigned int))ssl_sw[28].ptr) #define SSL_CTX_ctrl (*(long (*)(SSL_CTX *, int, long, void *))ssl_sw[29].ptr) #define SSL_CTX_set_cipher_list \ (*(int (*)(SSL_CTX *, const char *))ssl_sw[30].ptr) #define SSL_CTX_set_options \ (*(unsigned long (*)(SSL_CTX *, unsigned long))ssl_sw[31].ptr) #define SSL_CTX_set_info_callback \ (*(void (*)(SSL_CTX * ctx, void (*callback)(const SSL *, int, int))) \ ssl_sw[32] \ .ptr) #define SSL_get_ex_data (*(char *(*)(const SSL *, int))ssl_sw[33].ptr) #define SSL_set_ex_data (*(void (*)(SSL *, int, char *))ssl_sw[34].ptr) #define SSL_CTX_callback_ctrl \ (*(long (*)(SSL_CTX *, int, void (*)(void)))ssl_sw[35].ptr) #define SSL_get_servername \ (*(const char *(*)(const SSL *, int type))ssl_sw[36].ptr) #define SSL_set_SSL_CTX (*(SSL_CTX * (*)(SSL *, SSL_CTX *)) ssl_sw[37].ptr) #define SSL_ctrl (*(long (*)(SSL *, int, long, void *))ssl_sw[38].ptr) #define SSL_CTX_clear_options(ctx, op) \ SSL_CTX_ctrl((ctx), SSL_CTRL_CLEAR_OPTIONS, (op), NULL) #define SSL_CTX_set_ecdh_auto(ctx, onoff) \ SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff, NULL) #define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53 #define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54 #define SSL_CTRL_SET_TLSEXT_HOSTNAME 55 #define SSL_CTX_set_tlsext_servername_callback(ctx, cb) \ SSL_CTX_callback_ctrl(ctx, \ SSL_CTRL_SET_TLSEXT_SERVERNAME_CB, \ (void (*)(void))cb) #define SSL_CTX_set_tlsext_servername_arg(ctx, arg) \ SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG, 0, (void *)arg) #define SSL_set_tlsext_host_name(ctx, arg) \ SSL_ctrl(ctx, SSL_CTRL_SET_TLSEXT_HOSTNAME, 0, (void *)arg) #define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore) #define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter) #define SSL_set_app_data(s, arg) (SSL_set_ex_data(s, 0, (char *)arg)) #define SSL_get_app_data(s) (SSL_get_ex_data(s, 0)) #define ERR_get_error (*(unsigned long (*)(void))crypto_sw[0].ptr) #define ERR_error_string (*(char *(*)(unsigned long, char *))crypto_sw[1].ptr) #define CONF_modules_unload (*(void (*)(int))crypto_sw[2].ptr) #define X509_free (*(void (*)(X509 *))crypto_sw[3].ptr) #define X509_get_subject_name (*(X509_NAME * (*)(X509 *)) crypto_sw[4].ptr) #define X509_get_issuer_name (*(X509_NAME * (*)(X509 *)) crypto_sw[5].ptr) #define X509_NAME_oneline \ (*(char *(*)(X509_NAME *, char *, int))crypto_sw[6].ptr) #define X509_get_serialNumber (*(ASN1_INTEGER * (*)(X509 *)) crypto_sw[7].ptr) #define EVP_get_digestbyname \ (*(const EVP_MD *(*)(const char *))crypto_sw[8].ptr) #define EVP_Digest \ (*(int (*)( \ const void *, size_t, void *, unsigned int *, const EVP_MD *, void *)) \ crypto_sw[9] \ .ptr) #define i2d_X509 (*(int (*)(X509 *, unsigned char **))crypto_sw[10].ptr) #define BN_bn2hex (*(char *(*)(const BIGNUM *a))crypto_sw[11].ptr) #define ASN1_INTEGER_to_BN \ (*(BIGNUM * (*)(const ASN1_INTEGER *ai, BIGNUM *bn)) crypto_sw[12].ptr) #define BN_free (*(void (*)(const BIGNUM *a))crypto_sw[13].ptr) #define CRYPTO_free (*(void (*)(void *addr))crypto_sw[14].ptr) #define OPENSSL_free(a) CRYPTO_free(a) #define OPENSSL_REMOVE_THREAD_STATE() /* init_ssl_ctx() function updates this array. * It loads SSL library dynamically and changes NULLs to the actual addresses * of respective functions. The macros above (like SSL_connect()) are really * just calling these functions indirectly via the pointer. */ static struct ssl_func ssl_sw[] = {{"SSL_free", NULL}, {"SSL_accept", NULL}, {"SSL_connect", NULL}, {"SSL_read", NULL}, {"SSL_write", NULL}, {"SSL_get_error", NULL}, {"SSL_set_fd", NULL}, {"SSL_new", NULL}, {"SSL_CTX_new", NULL}, {"TLS_server_method", NULL}, {"OPENSSL_init_ssl", NULL}, {"SSL_CTX_use_PrivateKey_file", NULL}, {"SSL_CTX_use_certificate_file", NULL}, {"SSL_CTX_set_default_passwd_cb", NULL}, {"SSL_CTX_free", NULL}, {"SSL_CTX_use_certificate_chain_file", NULL}, {"TLS_client_method", NULL}, {"SSL_pending", NULL}, {"SSL_CTX_set_verify", NULL}, {"SSL_shutdown", NULL}, {"SSL_CTX_load_verify_locations", NULL}, {"SSL_CTX_set_default_verify_paths", NULL}, {"SSL_CTX_set_verify_depth", NULL}, {"SSL_get_peer_certificate", NULL}, {"SSL_get_version", NULL}, {"SSL_get_current_cipher", NULL}, {"SSL_CIPHER_get_name", NULL}, {"SSL_CTX_check_private_key", NULL}, {"SSL_CTX_set_session_id_context", NULL}, {"SSL_CTX_ctrl", NULL}, {"SSL_CTX_set_cipher_list", NULL}, {"SSL_CTX_set_options", NULL}, {"SSL_CTX_set_info_callback", NULL}, {"SSL_get_ex_data", NULL}, {"SSL_set_ex_data", NULL}, {"SSL_CTX_callback_ctrl", NULL}, {"SSL_get_servername", NULL}, {"SSL_set_SSL_CTX", NULL}, {"SSL_ctrl", NULL}, {NULL, NULL}}; /* Similar array as ssl_sw. These functions could be located in different * lib. */ static struct ssl_func crypto_sw[] = {{"ERR_get_error", NULL}, {"ERR_error_string", NULL}, {"CONF_modules_unload", NULL}, {"X509_free", NULL}, {"X509_get_subject_name", NULL}, {"X509_get_issuer_name", NULL}, {"X509_NAME_oneline", NULL}, {"X509_get_serialNumber", NULL}, {"EVP_get_digestbyname", NULL}, {"EVP_Digest", NULL}, {"i2d_X509", NULL}, {"BN_bn2hex", NULL}, {"ASN1_INTEGER_to_BN", NULL}, {"BN_free", NULL}, {"CRYPTO_free", NULL}, {NULL, NULL}}; #else #define SSL_free (*(void (*)(SSL *))ssl_sw[0].ptr) #define SSL_accept (*(int (*)(SSL *))ssl_sw[1].ptr) #define SSL_connect (*(int (*)(SSL *))ssl_sw[2].ptr) #define SSL_read (*(int (*)(SSL *, void *, int))ssl_sw[3].ptr) #define SSL_write (*(int (*)(SSL *, const void *, int))ssl_sw[4].ptr) #define SSL_get_error (*(int (*)(SSL *, int))ssl_sw[5].ptr) #define SSL_set_fd (*(int (*)(SSL *, SOCKET))ssl_sw[6].ptr) #define SSL_new (*(SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr) #define SSL_CTX_new (*(SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr) #define SSLv23_server_method (*(SSL_METHOD * (*)(void)) ssl_sw[9].ptr) #define SSL_library_init (*(int (*)(void))ssl_sw[10].ptr) #define SSL_CTX_use_PrivateKey_file \ (*(int (*)(SSL_CTX *, const char *, int))ssl_sw[11].ptr) #define SSL_CTX_use_certificate_file \ (*(int (*)(SSL_CTX *, const char *, int))ssl_sw[12].ptr) #define SSL_CTX_set_default_passwd_cb \ (*(void (*)(SSL_CTX *, mg_callback_t))ssl_sw[13].ptr) #define SSL_CTX_free (*(void (*)(SSL_CTX *))ssl_sw[14].ptr) #define SSL_load_error_strings (*(void (*)(void))ssl_sw[15].ptr) #define SSL_CTX_use_certificate_chain_file \ (*(int (*)(SSL_CTX *, const char *))ssl_sw[16].ptr) #define SSLv23_client_method (*(SSL_METHOD * (*)(void)) ssl_sw[17].ptr) #define SSL_pending (*(int (*)(SSL *))ssl_sw[18].ptr) #define SSL_CTX_set_verify \ (*(void (*)(SSL_CTX *, \ int, \ int (*verify_callback)(int, X509_STORE_CTX *)))ssl_sw[19] \ .ptr) #define SSL_shutdown (*(int (*)(SSL *))ssl_sw[20].ptr) #define SSL_CTX_load_verify_locations \ (*(int (*)(SSL_CTX *, const char *, const char *))ssl_sw[21].ptr) #define SSL_CTX_set_default_verify_paths (*(int (*)(SSL_CTX *))ssl_sw[22].ptr) #define SSL_CTX_set_verify_depth (*(void (*)(SSL_CTX *, int))ssl_sw[23].ptr) #define SSL_get_peer_certificate (*(X509 * (*)(SSL *)) ssl_sw[24].ptr) #define SSL_get_version (*(const char *(*)(SSL *))ssl_sw[25].ptr) #define SSL_get_current_cipher (*(SSL_CIPHER * (*)(SSL *)) ssl_sw[26].ptr) #define SSL_CIPHER_get_name \ (*(const char *(*)(const SSL_CIPHER *))ssl_sw[27].ptr) #define SSL_CTX_check_private_key (*(int (*)(SSL_CTX *))ssl_sw[28].ptr) #define SSL_CTX_set_session_id_context \ (*(int (*)(SSL_CTX *, const unsigned char *, unsigned int))ssl_sw[29].ptr) #define SSL_CTX_ctrl (*(long (*)(SSL_CTX *, int, long, void *))ssl_sw[30].ptr) #define SSL_CTX_set_cipher_list \ (*(int (*)(SSL_CTX *, const char *))ssl_sw[31].ptr) #define SSL_CTX_set_info_callback \ (*(void (*)(SSL_CTX *, void (*callback)(const SSL *, int, int)))ssl_sw[32] \ .ptr) #define SSL_get_ex_data (*(char *(*)(const SSL *, int))ssl_sw[33].ptr) #define SSL_set_ex_data (*(void (*)(SSL *, int, char *))ssl_sw[34].ptr) #define SSL_CTX_callback_ctrl \ (*(long (*)(SSL_CTX *, int, void (*)(void)))ssl_sw[35].ptr) #define SSL_get_servername \ (*(const char *(*)(const SSL *, int type))ssl_sw[36].ptr) #define SSL_set_SSL_CTX (*(SSL_CTX * (*)(SSL *, SSL_CTX *)) ssl_sw[37].ptr) #define SSL_ctrl (*(long (*)(SSL *, int, long, void *))ssl_sw[38].ptr) #define SSL_CTX_set_options(ctx, op) \ SSL_CTX_ctrl((ctx), SSL_CTRL_OPTIONS, (op), NULL) #define SSL_CTX_clear_options(ctx, op) \ SSL_CTX_ctrl((ctx), SSL_CTRL_CLEAR_OPTIONS, (op), NULL) #define SSL_CTX_set_ecdh_auto(ctx, onoff) \ SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff, NULL) #define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53 #define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54 #define SSL_CTRL_SET_TLSEXT_HOSTNAME 55 #define SSL_CTX_set_tlsext_servername_callback(ctx, cb) \ SSL_CTX_callback_ctrl(ctx, \ SSL_CTRL_SET_TLSEXT_SERVERNAME_CB, \ (void (*)(void))cb) #define SSL_CTX_set_tlsext_servername_arg(ctx, arg) \ SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG, 0, (void *)arg) #define SSL_set_tlsext_host_name(ctx, arg) \ SSL_ctrl(ctx, SSL_CTRL_SET_TLSEXT_HOSTNAME, 0, (void *)arg) #define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore) #define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter) #define SSL_set_app_data(s, arg) (SSL_set_ex_data(s, 0, (char *)arg)) #define SSL_get_app_data(s) (SSL_get_ex_data(s, 0)) #define CRYPTO_num_locks (*(int (*)(void))crypto_sw[0].ptr) #define CRYPTO_set_locking_callback \ (*(void (*)(void (*)(int, int, const char *, int)))crypto_sw[1].ptr) #define CRYPTO_set_id_callback \ (*(void (*)(unsigned long (*)(void)))crypto_sw[2].ptr) #define ERR_get_error (*(unsigned long (*)(void))crypto_sw[3].ptr) #define ERR_error_string (*(char *(*)(unsigned long, char *))crypto_sw[4].ptr) #define ERR_remove_state (*(void (*)(unsigned long))crypto_sw[5].ptr) #define ERR_free_strings (*(void (*)(void))crypto_sw[6].ptr) #define ENGINE_cleanup (*(void (*)(void))crypto_sw[7].ptr) #define CONF_modules_unload (*(void (*)(int))crypto_sw[8].ptr) #define CRYPTO_cleanup_all_ex_data (*(void (*)(void))crypto_sw[9].ptr) #define EVP_cleanup (*(void (*)(void))crypto_sw[10].ptr) #define X509_free (*(void (*)(X509 *))crypto_sw[11].ptr) #define X509_get_subject_name (*(X509_NAME * (*)(X509 *)) crypto_sw[12].ptr) #define X509_get_issuer_name (*(X509_NAME * (*)(X509 *)) crypto_sw[13].ptr) #define X509_NAME_oneline \ (*(char *(*)(X509_NAME *, char *, int))crypto_sw[14].ptr) #define X509_get_serialNumber (*(ASN1_INTEGER * (*)(X509 *)) crypto_sw[15].ptr) #define i2c_ASN1_INTEGER \ (*(int (*)(ASN1_INTEGER *, unsigned char **))crypto_sw[16].ptr) #define EVP_get_digestbyname \ (*(const EVP_MD *(*)(const char *))crypto_sw[17].ptr) #define EVP_Digest \ (*(int (*)( \ const void *, size_t, void *, unsigned int *, const EVP_MD *, void *)) \ crypto_sw[18] \ .ptr) #define i2d_X509 (*(int (*)(X509 *, unsigned char **))crypto_sw[19].ptr) #define BN_bn2hex (*(char *(*)(const BIGNUM *a))crypto_sw[20].ptr) #define ASN1_INTEGER_to_BN \ (*(BIGNUM * (*)(const ASN1_INTEGER *ai, BIGNUM *bn)) crypto_sw[21].ptr) #define BN_free (*(void (*)(const BIGNUM *a))crypto_sw[22].ptr) #define CRYPTO_free (*(void (*)(void *addr))crypto_sw[23].ptr) #define OPENSSL_free(a) CRYPTO_free(a) /* use here ERR_remove_state, * while on some platforms function is not included into library due to * deprication */ #define OPENSSL_REMOVE_THREAD_STATE() ERR_remove_state(0) /* init_ssl_ctx() function updates this array. * It loads SSL library dynamically and changes NULLs to the actual addresses * of respective functions. The macros above (like SSL_connect()) are really * just calling these functions indirectly via the pointer. */ static struct ssl_func ssl_sw[] = {{"SSL_free", NULL}, {"SSL_accept", NULL}, {"SSL_connect", NULL}, {"SSL_read", NULL}, {"SSL_write", NULL}, {"SSL_get_error", NULL}, {"SSL_set_fd", NULL}, {"SSL_new", NULL}, {"SSL_CTX_new", NULL}, {"SSLv23_server_method", NULL}, {"SSL_library_init", NULL}, {"SSL_CTX_use_PrivateKey_file", NULL}, {"SSL_CTX_use_certificate_file", NULL}, {"SSL_CTX_set_default_passwd_cb", NULL}, {"SSL_CTX_free", NULL}, {"SSL_load_error_strings", NULL}, {"SSL_CTX_use_certificate_chain_file", NULL}, {"SSLv23_client_method", NULL}, {"SSL_pending", NULL}, {"SSL_CTX_set_verify", NULL}, {"SSL_shutdown", NULL}, {"SSL_CTX_load_verify_locations", NULL}, {"SSL_CTX_set_default_verify_paths", NULL}, {"SSL_CTX_set_verify_depth", NULL}, {"SSL_get_peer_certificate", NULL}, {"SSL_get_version", NULL}, {"SSL_get_current_cipher", NULL}, {"SSL_CIPHER_get_name", NULL}, {"SSL_CTX_check_private_key", NULL}, {"SSL_CTX_set_session_id_context", NULL}, {"SSL_CTX_ctrl", NULL}, {"SSL_CTX_set_cipher_list", NULL}, {"SSL_CTX_set_info_callback", NULL}, {"SSL_get_ex_data", NULL}, {"SSL_set_ex_data", NULL}, {"SSL_CTX_callback_ctrl", NULL}, {"SSL_get_servername", NULL}, {"SSL_set_SSL_CTX", NULL}, {"SSL_ctrl", NULL}, {NULL, NULL}}; /* Similar array as ssl_sw. These functions could be located in different * lib. */ static struct ssl_func crypto_sw[] = {{"CRYPTO_num_locks", NULL}, {"CRYPTO_set_locking_callback", NULL}, {"CRYPTO_set_id_callback", NULL}, {"ERR_get_error", NULL}, {"ERR_error_string", NULL}, {"ERR_remove_state", NULL}, {"ERR_free_strings", NULL}, {"ENGINE_cleanup", NULL}, {"CONF_modules_unload", NULL}, {"CRYPTO_cleanup_all_ex_data", NULL}, {"EVP_cleanup", NULL}, {"X509_free", NULL}, {"X509_get_subject_name", NULL}, {"X509_get_issuer_name", NULL}, {"X509_NAME_oneline", NULL}, {"X509_get_serialNumber", NULL}, {"i2c_ASN1_INTEGER", NULL}, {"EVP_get_digestbyname", NULL}, {"EVP_Digest", NULL}, {"i2d_X509", NULL}, {"BN_bn2hex", NULL}, {"ASN1_INTEGER_to_BN", NULL}, {"BN_free", NULL}, {"CRYPTO_free", NULL}, {NULL, NULL}}; #endif /* OPENSSL_API_1_1 */ #endif /* NO_SSL_DL */ #endif /* NO_SSL */ #if !defined(NO_CACHING) static const char *month_names[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; #endif /* !NO_CACHING */ /* Unified socket address. For IPv6 support, add IPv6 address structure in * the * union u. */ union usa { struct sockaddr sa; struct sockaddr_in sin; #if defined(USE_IPV6) struct sockaddr_in6 sin6; #endif }; /* Describes a string (chunk of memory). */ struct vec { const char *ptr; size_t len; }; struct mg_file_stat { /* File properties filled by mg_stat: */ uint64_t size; time_t last_modified; int is_directory; /* Set to 1 if mg_stat is called for a directory */ int is_gzipped; /* Set to 1 if the content is gzipped, in which * case we need a "Content-Eencoding: gzip" header */ int location; /* 0 = nowhere, 1 = on disk, 2 = in memory */ }; struct mg_file_in_memory { char *p; uint32_t pos; char mode; }; struct mg_file_access { /* File properties filled by mg_fopen: */ FILE *fp; #if defined(MG_USE_OPEN_FILE) /* TODO (low): Remove obsolete "file in memory" implementation. * In an "early 2017" discussion at Google groups * https://groups.google.com/forum/#!topic/civetweb/h9HT4CmeYqI * we decided to get rid of this feature (after some fade-out * phase). */ const char *membuf; #endif }; struct mg_file { struct mg_file_stat stat; struct mg_file_access access; }; #if defined(MG_USE_OPEN_FILE) #define STRUCT_FILE_INITIALIZER \ { \ {(uint64_t)0, (time_t)0, 0, 0, 0}, \ { \ (FILE *)NULL, (const char *)NULL \ } \ } #else #define STRUCT_FILE_INITIALIZER \ { \ {(uint64_t)0, (time_t)0, 0, 0, 0}, \ { \ (FILE *)NULL \ } \ } #endif /* Describes listening socket, or socket which was accept()-ed by the master * thread and queued for future handling by the worker thread. */ struct socket { SOCKET sock; /* Listening socket */ union usa lsa; /* Local socket address */ union usa rsa; /* Remote socket address */ unsigned char is_ssl; /* Is port SSL-ed */ unsigned char ssl_redir; /* Is port supposed to redirect everything to SSL * port */ unsigned char in_use; /* 0: invalid, 1: valid, 2: free */ }; /* Enum const for all options must be in sync with * static struct mg_option config_options[] * This is tested in the unit test (test/private.c) * "Private Config Options" */ enum { /* Once for each server */ LISTENING_PORTS, NUM_THREADS, RUN_AS_USER, CONFIG_TCP_NODELAY, /* Prepended CONFIG_ to avoid conflict with the * socket option typedef TCP_NODELAY. */ MAX_REQUEST_SIZE, LINGER_TIMEOUT, #if defined(__linux__) ALLOW_SENDFILE_CALL, #endif #if defined(_WIN32) CASE_SENSITIVE_FILES, #endif THROTTLE, ACCESS_LOG_FILE, ERROR_LOG_FILE, ENABLE_KEEP_ALIVE, REQUEST_TIMEOUT, KEEP_ALIVE_TIMEOUT, #if defined(USE_WEBSOCKET) WEBSOCKET_TIMEOUT, ENABLE_WEBSOCKET_PING_PONG, #endif DECODE_URL, #if defined(USE_LUA) LUA_BACKGROUND_SCRIPT, LUA_BACKGROUND_SCRIPT_PARAMS, #endif #if defined(USE_TIMERS) CGI_TIMEOUT, #endif /* Once for each domain */ DOCUMENT_ROOT, CGI_EXTENSIONS, CGI_ENVIRONMENT, PUT_DELETE_PASSWORDS_FILE, CGI_INTERPRETER, PROTECT_URI, AUTHENTICATION_DOMAIN, ENABLE_AUTH_DOMAIN_CHECK, SSI_EXTENSIONS, ENABLE_DIRECTORY_LISTING, GLOBAL_PASSWORDS_FILE, INDEX_FILES, ACCESS_CONTROL_LIST, EXTRA_MIME_TYPES, SSL_CERTIFICATE, SSL_CERTIFICATE_CHAIN, URL_REWRITE_PATTERN, HIDE_FILES, SSL_DO_VERIFY_PEER, SSL_CA_PATH, SSL_CA_FILE, SSL_VERIFY_DEPTH, SSL_DEFAULT_VERIFY_PATHS, SSL_CIPHER_LIST, SSL_PROTOCOL_VERSION, SSL_SHORT_TRUST, #if defined(USE_LUA) LUA_PRELOAD_FILE, LUA_SCRIPT_EXTENSIONS, LUA_SERVER_PAGE_EXTENSIONS, #if defined(MG_EXPERIMENTAL_INTERFACES) LUA_DEBUG_PARAMS, #endif #endif #if defined(USE_DUKTAPE) DUKTAPE_SCRIPT_EXTENSIONS, #endif #if defined(USE_WEBSOCKET) WEBSOCKET_ROOT, #endif #if defined(USE_LUA) && defined(USE_WEBSOCKET) LUA_WEBSOCKET_EXTENSIONS, #endif ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_HEADERS, ERROR_PAGES, #if !defined(NO_CACHING) STATIC_FILE_MAX_AGE, #endif #if !defined(NO_SSL) STRICT_HTTPS_MAX_AGE, #endif ADDITIONAL_HEADER, ALLOW_INDEX_SCRIPT_SUB_RES, #if defined(DAEMONIZE) ENABLE_DAEMONIZE, #endif NUM_OPTIONS }; /* Config option name, config types, default value. * Must be in the same order as the enum const above. */ static const struct mg_option config_options[] = { /* Once for each server */ {"listening_ports", MG_CONFIG_TYPE_STRING_LIST, "8080"}, {"num_threads", MG_CONFIG_TYPE_NUMBER, "50"}, {"run_as_user", MG_CONFIG_TYPE_STRING, NULL}, {"tcp_nodelay", MG_CONFIG_TYPE_NUMBER, "0"}, {"max_request_size", MG_CONFIG_TYPE_NUMBER, "16384"}, {"linger_timeout_ms", MG_CONFIG_TYPE_NUMBER, NULL}, #if defined(__linux__) {"allow_sendfile_call", MG_CONFIG_TYPE_BOOLEAN, "yes"}, #endif #if defined(_WIN32) {"case_sensitive", MG_CONFIG_TYPE_BOOLEAN, "no"}, #endif {"throttle", MG_CONFIG_TYPE_STRING_LIST, NULL}, {"access_log_file", MG_CONFIG_TYPE_FILE, NULL}, {"error_log_file", MG_CONFIG_TYPE_FILE, NULL}, {"enable_keep_alive", MG_CONFIG_TYPE_BOOLEAN, "no"}, {"request_timeout_ms", MG_CONFIG_TYPE_NUMBER, "30000"}, {"keep_alive_timeout_ms", MG_CONFIG_TYPE_NUMBER, "500"}, #if defined(USE_WEBSOCKET) {"websocket_timeout_ms", MG_CONFIG_TYPE_NUMBER, NULL}, {"enable_websocket_ping_pong", MG_CONFIG_TYPE_BOOLEAN, "no"}, #endif {"decode_url", MG_CONFIG_TYPE_BOOLEAN, "yes"}, #if defined(USE_LUA) {"lua_background_script", MG_CONFIG_TYPE_FILE, NULL}, {"lua_background_script_params", MG_CONFIG_TYPE_STRING_LIST, NULL}, #endif #if defined(USE_TIMERS) {"cgi_timeout_ms", MG_CONFIG_TYPE_NUMBER, NULL}, #endif /* Once for each domain */ {"document_root", MG_CONFIG_TYPE_DIRECTORY, NULL}, {"cgi_pattern", MG_CONFIG_TYPE_EXT_PATTERN, "**.cgi$|**.pl$|**.php$"}, {"cgi_environment", MG_CONFIG_TYPE_STRING_LIST, NULL}, {"put_delete_auth_file", MG_CONFIG_TYPE_FILE, NULL}, {"cgi_interpreter", MG_CONFIG_TYPE_FILE, NULL}, {"protect_uri", MG_CONFIG_TYPE_STRING_LIST, NULL}, {"authentication_domain", MG_CONFIG_TYPE_STRING, "mydomain.com"}, {"enable_auth_domain_check", MG_CONFIG_TYPE_BOOLEAN, "yes"}, {"ssi_pattern", MG_CONFIG_TYPE_EXT_PATTERN, "**.shtml$|**.shtm$"}, {"enable_directory_listing", MG_CONFIG_TYPE_BOOLEAN, "yes"}, {"global_auth_file", MG_CONFIG_TYPE_FILE, NULL}, {"index_files", MG_CONFIG_TYPE_STRING_LIST, #if defined(USE_LUA) "index.xhtml,index.html,index.htm," "index.lp,index.lsp,index.lua,index.cgi," "index.shtml,index.php"}, #else "index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php"}, #endif {"access_control_list", MG_CONFIG_TYPE_STRING_LIST, NULL}, {"extra_mime_types", MG_CONFIG_TYPE_STRING_LIST, NULL}, {"ssl_certificate", MG_CONFIG_TYPE_FILE, NULL}, {"ssl_certificate_chain", MG_CONFIG_TYPE_FILE, NULL}, {"url_rewrite_patterns", MG_CONFIG_TYPE_STRING_LIST, NULL}, {"hide_files_patterns", MG_CONFIG_TYPE_EXT_PATTERN, NULL}, {"ssl_verify_peer", MG_CONFIG_TYPE_YES_NO_OPTIONAL, "no"}, {"ssl_ca_path", MG_CONFIG_TYPE_DIRECTORY, NULL}, {"ssl_ca_file", MG_CONFIG_TYPE_FILE, NULL}, {"ssl_verify_depth", MG_CONFIG_TYPE_NUMBER, "9"}, {"ssl_default_verify_paths", MG_CONFIG_TYPE_BOOLEAN, "yes"}, {"ssl_cipher_list", MG_CONFIG_TYPE_STRING, NULL}, {"ssl_protocol_version", MG_CONFIG_TYPE_NUMBER, "0"}, {"ssl_short_trust", MG_CONFIG_TYPE_BOOLEAN, "no"}, #if defined(USE_LUA) {"lua_preload_file", MG_CONFIG_TYPE_FILE, NULL}, {"lua_script_pattern", MG_CONFIG_TYPE_EXT_PATTERN, "**.lua$"}, {"lua_server_page_pattern", MG_CONFIG_TYPE_EXT_PATTERN, "**.lp$|**.lsp$"}, #if defined(MG_EXPERIMENTAL_INTERFACES) {"lua_debug", MG_CONFIG_TYPE_STRING, NULL}, #endif #endif #if defined(USE_DUKTAPE) /* The support for duktape is still in alpha version state. * The name of this config option might change. */ {"duktape_script_pattern", MG_CONFIG_TYPE_EXT_PATTERN, "**.ssjs$"}, #endif #if defined(USE_WEBSOCKET) {"websocket_root", MG_CONFIG_TYPE_DIRECTORY, NULL}, #endif #if defined(USE_LUA) && defined(USE_WEBSOCKET) {"lua_websocket_pattern", MG_CONFIG_TYPE_EXT_PATTERN, "**.lua$"}, #endif {"access_control_allow_origin", MG_CONFIG_TYPE_STRING, "*"}, {"access_control_allow_methods", MG_CONFIG_TYPE_STRING, "*"}, {"access_control_allow_headers", MG_CONFIG_TYPE_STRING, "*"}, {"error_pages", MG_CONFIG_TYPE_DIRECTORY, NULL}, #if !defined(NO_CACHING) {"static_file_max_age", MG_CONFIG_TYPE_NUMBER, "3600"}, #endif #if !defined(NO_SSL) {"strict_transport_security_max_age", MG_CONFIG_TYPE_NUMBER, NULL}, #endif {"additional_header", MG_CONFIG_TYPE_STRING_MULTILINE, NULL}, {"allow_index_script_resource", MG_CONFIG_TYPE_BOOLEAN, "no"}, #if defined(DAEMONIZE) {"daemonize", MG_CONFIG_TYPE_BOOLEAN, "no"}, #endif {NULL, MG_CONFIG_TYPE_UNKNOWN, NULL}}; /* Check if the config_options and the corresponding enum have compatible * sizes. */ mg_static_assert((sizeof(config_options) / sizeof(config_options[0])) == (NUM_OPTIONS + 1), "config_options and enum not sync"); enum { REQUEST_HANDLER, WEBSOCKET_HANDLER, AUTH_HANDLER }; struct mg_handler_info { /* Name/Pattern of the URI. */ char *uri; size_t uri_len; /* handler type */ int handler_type; /* Handler for http/https or authorization requests. */ mg_request_handler handler; unsigned int refcount; pthread_mutex_t refcount_mutex; /* Protects refcount */ pthread_cond_t refcount_cond; /* Signaled when handler refcount is decremented */ /* Handler for ws/wss (websocket) requests. */ mg_websocket_connect_handler connect_handler; mg_websocket_ready_handler ready_handler; mg_websocket_data_handler data_handler; mg_websocket_close_handler close_handler; /* accepted subprotocols for ws/wss requests. */ struct mg_websocket_subprotocols *subprotocols; /* Handler for authorization requests */ mg_authorization_handler auth_handler; /* User supplied argument for the handler function. */ void *cbdata; /* next handler in a linked list */ struct mg_handler_info *next; }; enum { CONTEXT_INVALID, CONTEXT_SERVER, CONTEXT_HTTP_CLIENT, CONTEXT_WS_CLIENT }; struct mg_domain_context { SSL_CTX *ssl_ctx; /* SSL context */ char *config[NUM_OPTIONS]; /* Civetweb configuration parameters */ struct mg_handler_info *handlers; /* linked list of uri handlers */ /* Server nonce */ uint64_t auth_nonce_mask; /* Mask for all nonce values */ unsigned long nonce_count; /* Used nonces, used for authentication */ #if defined(USE_LUA) && defined(USE_WEBSOCKET) /* linked list of shared lua websockets */ struct mg_shared_lua_websocket_list *shared_lua_websockets; #endif /* Linked list of domains */ struct mg_domain_context *next; }; struct mg_context { /* Part 1 - Physical context: * This holds threads, ports, timeouts, ... * set for the entire server, independent from the * addressed hostname. */ /* Connection related */ int context_type; /* See CONTEXT_* above */ struct socket *listening_sockets; struct mg_pollfd *listening_socket_fds; unsigned int num_listening_sockets; struct mg_connection *worker_connections; /* The connection struct, pre- * allocated for each worker */ #if defined(USE_SERVER_STATS) int active_connections; int max_connections; int64_t total_connections; int64_t total_requests; int64_t total_data_read; int64_t total_data_written; #endif /* Thread related */ volatile int stop_flag; /* Should we stop event loop */ pthread_mutex_t thread_mutex; /* Protects (max|num)_threads */ pthread_t masterthreadid; /* The master thread ID */ unsigned int cfg_worker_threads; /* The number of configured worker threads. */ pthread_t *worker_threadids; /* The worker thread IDs */ /* Connection to thread dispatching */ #if defined(ALTERNATIVE_QUEUE) struct socket *client_socks; void **client_wait_events; #else struct socket queue[MGSQLEN]; /* Accepted sockets */ volatile int sq_head; /* Head of the socket queue */ volatile int sq_tail; /* Tail of the socket queue */ pthread_cond_t sq_full; /* Signaled when socket is produced */ pthread_cond_t sq_empty; /* Signaled when socket is consumed */ #endif /* Memory related */ unsigned int max_request_size; /* The max request size */ #if defined(USE_SERVER_STATS) struct mg_memory_stat ctx_memory; #endif /* Operating system related */ char *systemName; /* What operating system is running */ time_t start_time; /* Server start time, used for authentication * and for diagnstics. */ #if defined(USE_TIMERS) struct ttimers *timers; #endif /* Lua specific: Background operations and shared websockets */ #if defined(USE_LUA) void *lua_background_state; #endif /* Server nonce */ pthread_mutex_t nonce_mutex; /* Protects nonce_count */ /* Server callbacks */ struct mg_callbacks callbacks; /* User-defined callback function */ void *user_data; /* User-defined data */ /* Part 2 - Logical domain: * This holds hostname, TLS certificate, document root, ... * set for a domain hosted at the server. * There may be multiple domains hosted at one physical server. * The default domain "dd" is the first element of a list of * domains. */ struct mg_domain_context dd; /* default domain */ }; #if defined(USE_SERVER_STATS) static struct mg_memory_stat mg_common_memory = {0, 0, 0}; static struct mg_memory_stat * get_memory_stat(struct mg_context *ctx) { if (ctx) { return &(ctx->ctx_memory); } return &mg_common_memory; } #endif enum { CONNECTION_TYPE_INVALID, CONNECTION_TYPE_REQUEST, CONNECTION_TYPE_RESPONSE }; struct mg_connection { int connection_type; /* see CONNECTION_TYPE_* above */ struct mg_request_info request_info; struct mg_response_info response_info; struct mg_context *phys_ctx; struct mg_domain_context *dom_ctx; #if defined(USE_SERVER_STATS) int conn_state; /* 0 = undef, numerical value may change in different * versions. For the current definition, see * mg_get_connection_info_impl */ #endif const char *host; /* Host (HTTP/1.1 header or SNI) */ SSL *ssl; /* SSL descriptor */ SSL_CTX *client_ssl_ctx; /* SSL context for client connections */ struct socket client; /* Connected client */ time_t conn_birth_time; /* Time (wall clock) when connection was * established */ struct timespec req_time; /* Time (since system start) when the request * was received */ int64_t num_bytes_sent; /* Total bytes sent to client */ int64_t content_len; /* Content-Length header value */ int64_t consumed_content; /* How many bytes of content have been read */ int is_chunked; /* Transfer-Encoding is chunked: * 0 = not chunked, * 1 = chunked, do data read yet, * 2 = chunked, some data read, * 3 = chunked, all data read */ size_t chunk_remainder; /* Unread data from the last chunk */ char *buf; /* Buffer for received data */ char *path_info; /* PATH_INFO part of the URL */ int must_close; /* 1 if connection must be closed */ int accept_gzip; /* 1 if gzip encoding is accepted */ int in_error_handler; /* 1 if in handler for user defined error * pages */ #if defined(USE_WEBSOCKET) int in_websocket_handling; /* 1 if in read_websocket */ #endif int handled_requests; /* Number of requests handled by this connection */ int buf_size; /* Buffer size */ int request_len; /* Size of the request + headers in a buffer */ int data_len; /* Total size of data in a buffer */ int status_code; /* HTTP reply status code, e.g. 200 */ int throttle; /* Throttling, bytes/sec. <= 0 means no * throttle */ time_t last_throttle_time; /* Last time throttled data was sent */ int64_t last_throttle_bytes; /* Bytes sent this second */ pthread_mutex_t mutex; /* Used by mg_(un)lock_connection to ensure * atomic transmissions for websockets */ #if defined(USE_LUA) && defined(USE_WEBSOCKET) void *lua_websocket_state; /* Lua_State for a websocket connection */ #endif int thread_index; /* Thread index within ctx */ }; /* Directory entry */ struct de { struct mg_connection *conn; char *file_name; struct mg_file_stat file; }; #if defined(USE_WEBSOCKET) static int is_websocket_protocol(const struct mg_connection *conn); #else #define is_websocket_protocol(conn) (0) #endif #define mg_cry_internal(conn, fmt, ...) \ mg_cry_internal_wrap(conn, __func__, __LINE__, fmt, __VA_ARGS__) static void mg_cry_internal_wrap(const struct mg_connection *conn, const char *func, unsigned line, const char *fmt, ...) PRINTF_ARGS(4, 5); #if !defined(NO_THREAD_NAME) #if defined(_WIN32) && defined(_MSC_VER) /* Set the thread name for debugging purposes in Visual Studio * http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx */ #pragma pack(push, 8) typedef struct tagTHREADNAME_INFO { DWORD dwType; /* Must be 0x1000. */ LPCSTR szName; /* Pointer to name (in user addr space). */ DWORD dwThreadID; /* Thread ID (-1=caller thread). */ DWORD dwFlags; /* Reserved for future use, must be zero. */ } THREADNAME_INFO; #pragma pack(pop) #elif defined(__linux__) #include <sys/prctl.h> #include <sys/sendfile.h> #if defined(ALTERNATIVE_QUEUE) #include <sys/eventfd.h> #endif /* ALTERNATIVE_QUEUE */ #if defined(ALTERNATIVE_QUEUE) static void * event_create(void) { int evhdl = eventfd(0, EFD_CLOEXEC); int *ret; if (evhdl == -1) { /* Linux uses -1 on error, Windows NULL. */ /* However, Linux does not return 0 on success either. */ return 0; } ret = (int *)mg_malloc(sizeof(int)); if (ret) { *ret = evhdl; } else { (void)close(evhdl); } return (void *)ret; } static int event_wait(void *eventhdl) { uint64_t u; int evhdl, s; if (!eventhdl) { /* error */ return 0; } evhdl = *(int *)eventhdl; s = (int)read(evhdl, &u, sizeof(u)); if (s != sizeof(u)) { /* error */ return 0; } (void)u; /* the value is not required */ return 1; } static int event_signal(void *eventhdl) { uint64_t u = 1; int evhdl, s; if (!eventhdl) { /* error */ return 0; } evhdl = *(int *)eventhdl; s = (int)write(evhdl, &u, sizeof(u)); if (s != sizeof(u)) { /* error */ return 0; } return 1; } static void event_destroy(void *eventhdl) { int evhdl; if (!eventhdl) { /* error */ return; } evhdl = *(int *)eventhdl; close(evhdl); mg_free(eventhdl); } #endif #endif #if !defined(__linux__) && !defined(_WIN32) && defined(ALTERNATIVE_QUEUE) struct posix_event { pthread_mutex_t mutex; pthread_cond_t cond; int signaled; }; static void * event_create(void) { struct posix_event *ret = mg_malloc(sizeof(struct posix_event)); if (ret == 0) { /* out of memory */ return 0; } if (0 != pthread_mutex_init(&(ret->mutex), NULL)) { /* pthread mutex not available */ mg_free(ret); return 0; } if (0 != pthread_cond_init(&(ret->cond), NULL)) { /* pthread cond not available */ pthread_mutex_destroy(&(ret->mutex)); mg_free(ret); return 0; } ret->signaled = 0; return (void *)ret; } static int event_wait(void *eventhdl) { struct posix_event *ev = (struct posix_event *)eventhdl; pthread_mutex_lock(&(ev->mutex)); while (!ev->signaled) { pthread_cond_wait(&(ev->cond), &(ev->mutex)); } ev->signaled = 0; pthread_mutex_unlock(&(ev->mutex)); return 1; } static int event_signal(void *eventhdl) { struct posix_event *ev = (struct posix_event *)eventhdl; pthread_mutex_lock(&(ev->mutex)); pthread_cond_signal(&(ev->cond)); ev->signaled = 1; pthread_mutex_unlock(&(ev->mutex)); return 1; } static void event_destroy(void *eventhdl) { struct posix_event *ev = (struct posix_event *)eventhdl; pthread_cond_destroy(&(ev->cond)); pthread_mutex_destroy(&(ev->mutex)); mg_free(ev); } #endif static void mg_set_thread_name(const char *name) { char threadName[16 + 1]; /* 16 = Max. thread length in Linux/OSX/.. */ mg_snprintf( NULL, NULL, threadName, sizeof(threadName), "civetweb-%s", name); #if defined(_WIN32) #if defined(_MSC_VER) /* Windows and Visual Studio Compiler */ __try { THREADNAME_INFO info; info.dwType = 0x1000; info.szName = threadName; info.dwThreadID = ~0U; info.dwFlags = 0; RaiseException(0x406D1388, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info); } __except (EXCEPTION_EXECUTE_HANDLER) { } #elif defined(__MINGW32__) /* No option known to set thread name for MinGW */ #endif #elif defined(_GNU_SOURCE) && defined(__GLIBC__) \ && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12))) /* pthread_setname_np first appeared in glibc in version 2.12*/ #if defined(__MACH__) /* OS X only current thread name can be changed */ (void)pthread_setname_np(threadName); #else (void)pthread_setname_np(pthread_self(), threadName); #endif #elif defined(__linux__) /* on linux we can use the old prctl function */ (void)prctl(PR_SET_NAME, threadName, 0, 0, 0); #endif } #else /* !defined(NO_THREAD_NAME) */ void mg_set_thread_name(const char *threadName) { } #endif #if defined(MG_LEGACY_INTERFACE) const char ** mg_get_valid_option_names(void) { /* This function is deprecated. Use mg_get_valid_options instead. */ static const char *data[2 * sizeof(config_options) / sizeof(config_options[0])] = {0}; int i; for (i = 0; config_options[i].name != NULL; i++) { data[i * 2] = config_options[i].name; data[i * 2 + 1] = config_options[i].default_value; } return data; } #endif const struct mg_option * mg_get_valid_options(void) { return config_options; } /* Do not open file (used in is_file_in_memory) */ #define MG_FOPEN_MODE_NONE (0) /* Open file for read only access */ #define MG_FOPEN_MODE_READ (1) /* Open file for writing, create and overwrite */ #define MG_FOPEN_MODE_WRITE (2) /* Open file for writing, create and append */ #define MG_FOPEN_MODE_APPEND (4) /* If a file is in memory, set all "stat" members and the membuf pointer of * output filep and return 1, otherwise return 0 and don't modify anything. */ static int open_file_in_memory(const struct mg_connection *conn, const char *path, struct mg_file *filep, int mode) { #if defined(MG_USE_OPEN_FILE) size_t size = 0; const char *buf = NULL; if (!conn) { return 0; } if ((mode != MG_FOPEN_MODE_NONE) && (mode != MG_FOPEN_MODE_READ)) { return 0; } if (conn->phys_ctx->callbacks.open_file) { buf = conn->phys_ctx->callbacks.open_file(conn, path, &size); if (buf != NULL) { if (filep == NULL) { /* This is a file in memory, but we cannot store the * properties * now. * Called from "is_file_in_memory" function. */ return 1; } /* NOTE: override filep->size only on success. Otherwise, it * might * break constructs like if (!mg_stat() || !mg_fopen()) ... */ filep->access.membuf = buf; filep->access.fp = NULL; /* Size was set by the callback */ filep->stat.size = size; /* Assume the data may change during runtime by setting * last_modified = now */ filep->stat.last_modified = time(NULL); filep->stat.is_directory = 0; filep->stat.is_gzipped = 0; } } return (buf != NULL); #else (void)conn; (void)path; (void)filep; (void)mode; return 0; #endif } static int is_file_in_memory(const struct mg_connection *conn, const char *path) { return open_file_in_memory(conn, path, NULL, MG_FOPEN_MODE_NONE); } static int is_file_opened(const struct mg_file_access *fileacc) { if (!fileacc) { return 0; } #if defined(MG_USE_OPEN_FILE) return (fileacc->membuf != NULL) || (fileacc->fp != NULL); #else return (fileacc->fp != NULL); #endif } static int mg_stat(const struct mg_connection *conn, const char *path, struct mg_file_stat *filep); /* mg_fopen will open a file either in memory or on the disk. * The input parameter path is a string in UTF-8 encoding. * The input parameter mode is MG_FOPEN_MODE_* * On success, either fp or membuf will be set in the output * struct file. All status members will also be set. * The function returns 1 on success, 0 on error. */ static int mg_fopen(const struct mg_connection *conn, const char *path, int mode, struct mg_file *filep) { int found; if (!filep) { return 0; } filep->access.fp = NULL; #if defined(MG_USE_OPEN_FILE) filep->access.membuf = NULL; #endif if (!is_file_in_memory(conn, path)) { /* filep is initialized in mg_stat: all fields with memset to, * some fields like size and modification date with values */ found = mg_stat(conn, path, &(filep->stat)); if ((mode == MG_FOPEN_MODE_READ) && (!found)) { /* file does not exist and will not be created */ return 0; } #if defined(_WIN32) { wchar_t wbuf[W_PATH_MAX]; path_to_unicode(conn, path, wbuf, ARRAY_SIZE(wbuf)); switch (mode) { case MG_FOPEN_MODE_READ: filep->access.fp = _wfopen(wbuf, L"rb"); break; case MG_FOPEN_MODE_WRITE: filep->access.fp = _wfopen(wbuf, L"wb"); break; case MG_FOPEN_MODE_APPEND: filep->access.fp = _wfopen(wbuf, L"ab"); break; } } #else /* Linux et al already use unicode. No need to convert. */ switch (mode) { case MG_FOPEN_MODE_READ: filep->access.fp = fopen(path, "r"); break; case MG_FOPEN_MODE_WRITE: filep->access.fp = fopen(path, "w"); break; case MG_FOPEN_MODE_APPEND: filep->access.fp = fopen(path, "a"); break; } #endif if (!found) { /* File did not exist before fopen was called. * Maybe it has been created now. Get stat info * like creation time now. */ found = mg_stat(conn, path, &(filep->stat)); (void)found; } /* file is on disk */ return (filep->access.fp != NULL); } else { #if defined(MG_USE_OPEN_FILE) /* is_file_in_memory returned true */ if (open_file_in_memory(conn, path, filep, mode)) { /* file is in memory */ return (filep->access.membuf != NULL); } #endif } /* Open failed */ return 0; } /* return 0 on success, just like fclose */ static int mg_fclose(struct mg_file_access *fileacc) { int ret = -1; if (fileacc != NULL) { if (fileacc->fp != NULL) { ret = fclose(fileacc->fp); #if defined(MG_USE_OPEN_FILE) } else if (fileacc->membuf != NULL) { ret = 0; #endif } /* reset all members of fileacc */ memset(fileacc, 0, sizeof(*fileacc)); } return ret; } static void mg_strlcpy(register char *dst, register const char *src, size_t n) { for (; *src != '\0' && n > 1; n--) { *dst++ = *src++; } *dst = '\0'; } static int lowercase(const char *s) { return tolower((unsigned char)*s); } int mg_strncasecmp(const char *s1, const char *s2, size_t len) { int diff = 0; if (len > 0) { do { diff = lowercase(s1++) - lowercase(s2++); } while (diff == 0 && s1[-1] != '\0' && --len > 0); } return diff; } int mg_strcasecmp(const char *s1, const char *s2) { int diff; do { diff = lowercase(s1++) - lowercase(s2++); } while (diff == 0 && s1[-1] != '\0'); return diff; } static char * mg_strndup_ctx(const char *ptr, size_t len, struct mg_context *ctx) { char *p; (void)ctx; /* Avoid Visual Studio warning if USE_SERVER_STATS is not * defined */ if ((p = (char *)mg_malloc_ctx(len + 1, ctx)) != NULL) { mg_strlcpy(p, ptr, len + 1); } return p; } static char * mg_strdup_ctx(const char *str, struct mg_context *ctx) { return mg_strndup_ctx(str, strlen(str), ctx); } static char * mg_strdup(const char *str) { return mg_strndup_ctx(str, strlen(str), NULL); } static const char * mg_strcasestr(const char *big_str, const char *small_str) { size_t i, big_len = strlen(big_str), small_len = strlen(small_str); if (big_len >= small_len) { for (i = 0; i <= (big_len - small_len); i++) { if (mg_strncasecmp(big_str + i, small_str, small_len) == 0) { return big_str + i; } } } return NULL; } /* Return null terminated string of given maximum length. * Report errors if length is exceeded. */ static void mg_vsnprintf(const struct mg_connection *conn, int *truncated, char *buf, size_t buflen, const char *fmt, va_list ap) { int n, ok; if (buflen == 0) { if (truncated) { *truncated = 1; } return; } #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wformat-nonliteral" /* Using fmt as a non-literal is intended here, since it is mostly called * indirectly by mg_snprintf */ #endif n = (int)vsnprintf_impl(buf, buflen, fmt, ap); ok = (n >= 0) && ((size_t)n < buflen); #if defined(__clang__) #pragma clang diagnostic pop #endif if (ok) { if (truncated) { *truncated = 0; } } else { if (truncated) { *truncated = 1; } mg_cry_internal(conn, "truncating vsnprintf buffer: [%.*s]", (int)((buflen > 200) ? 200 : (buflen - 1)), buf); n = (int)buflen - 1; } buf[n] = '\0'; } static void mg_snprintf(const struct mg_connection *conn, int *truncated, char *buf, size_t buflen, const char *fmt, ...) { va_list ap; va_start(ap, fmt); mg_vsnprintf(conn, truncated, buf, buflen, fmt, ap); va_end(ap); } static int get_option_index(const char *name) { int i; for (i = 0; config_options[i].name != NULL; i++) { if (strcmp(config_options[i].name, name) == 0) { return i; } } return -1; } const char * mg_get_option(const struct mg_context *ctx, const char *name) { int i; if ((i = get_option_index(name)) == -1) { return NULL; } else if (!ctx || ctx->dd.config[i] == NULL) { return ""; } else { return ctx->dd.config[i]; } } #define mg_get_option DO_NOT_USE_THIS_FUNCTION_INTERNALLY__access_directly struct mg_context * mg_get_context(const struct mg_connection *conn) { return (conn == NULL) ? (struct mg_context *)NULL : (conn->phys_ctx); } void * mg_get_user_data(const struct mg_context *ctx) { return (ctx == NULL) ? NULL : ctx->user_data; } void mg_set_user_connection_data(struct mg_connection *conn, void *data) { if (conn != NULL) { conn->request_info.conn_data = data; } } void * mg_get_user_connection_data(const struct mg_connection *conn) { if (conn != NULL) { return conn->request_info.conn_data; } return NULL; } #if defined(MG_LEGACY_INTERFACE) /* Deprecated: Use mg_get_server_ports instead. */ size_t mg_get_ports(const struct mg_context *ctx, size_t size, int *ports, int *ssl) { size_t i; if (!ctx) { return 0; } for (i = 0; i < size && i < ctx->num_listening_sockets; i++) { ssl[i] = ctx->listening_sockets[i].is_ssl; ports[i] = #if defined(USE_IPV6) (ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET6) ? ntohs(ctx->listening_sockets[i].lsa.sin6.sin6_port) : #endif ntohs(ctx->listening_sockets[i].lsa.sin.sin_port); } return i; } #endif int mg_get_server_ports(const struct mg_context *ctx, int size, struct mg_server_ports *ports) { int i, cnt = 0; if (size <= 0) { return -1; } memset(ports, 0, sizeof(*ports) * (size_t)size); if (!ctx) { return -1; } if (!ctx->listening_sockets) { return -1; } for (i = 0; (i < size) && (i < (int)ctx->num_listening_sockets); i++) { ports[cnt].port = #if defined(USE_IPV6) (ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET6) ? ntohs(ctx->listening_sockets[i].lsa.sin6.sin6_port) : #endif ntohs(ctx->listening_sockets[i].lsa.sin.sin_port); ports[cnt].is_ssl = ctx->listening_sockets[i].is_ssl; ports[cnt].is_redirect = ctx->listening_sockets[i].ssl_redir; if (ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET) { /* IPv4 */ ports[cnt].protocol = 1; cnt++; } else if (ctx->listening_sockets[i].lsa.sa.sa_family == AF_INET6) { /* IPv6 */ ports[cnt].protocol = 3; cnt++; } } return cnt; } static void sockaddr_to_string(char *buf, size_t len, const union usa *usa) { buf[0] = '\0'; if (!usa) { return; } if (usa->sa.sa_family == AF_INET) { getnameinfo(&usa->sa, sizeof(usa->sin), buf, (unsigned)len, NULL, 0, NI_NUMERICHOST); } #if defined(USE_IPV6) else if (usa->sa.sa_family == AF_INET6) { getnameinfo(&usa->sa, sizeof(usa->sin6), buf, (unsigned)len, NULL, 0, NI_NUMERICHOST); } #endif } /* Convert time_t to a string. According to RFC2616, Sec 14.18, this must be * included in all responses other than 100, 101, 5xx. */ static void gmt_time_string(char *buf, size_t buf_len, time_t *t) { #if !defined(REENTRANT_TIME) struct tm *tm; tm = ((t != NULL) ? gmtime(t) : NULL); if (tm != NULL) { #else struct tm _tm; struct tm *tm = &_tm; if (t != NULL) { gmtime_r(t, tm); #endif strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S GMT", tm); } else { mg_strlcpy(buf, "Thu, 01 Jan 1970 00:00:00 GMT", buf_len); buf[buf_len - 1] = '\0'; } } /* difftime for struct timespec. Return value is in seconds. */ static double mg_difftimespec(const struct timespec *ts_now, const struct timespec *ts_before) { return (double)(ts_now->tv_nsec - ts_before->tv_nsec) * 1.0E-9 + (double)(ts_now->tv_sec - ts_before->tv_sec); } #if defined(MG_EXTERNAL_FUNCTION_mg_cry_internal_impl) static void mg_cry_internal_impl(const struct mg_connection *conn, const char *func, unsigned line, const char *fmt, va_list ap); #include "external_mg_cry_internal_impl.inl" #else /* Print error message to the opened error log stream. */ static void mg_cry_internal_impl(const struct mg_connection *conn, const char *func, unsigned line, const char *fmt, va_list ap) { char buf[MG_BUF_LEN], src_addr[IP_ADDR_STR_LEN]; struct mg_file fi; time_t timestamp; /* Unused, in the RELEASE build */ (void)func; (void)line; #if defined(GCC_DIAGNOSTIC) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif IGNORE_UNUSED_RESULT(vsnprintf_impl(buf, sizeof(buf), fmt, ap)); #if defined(GCC_DIAGNOSTIC) #pragma GCC diagnostic pop #endif buf[sizeof(buf) - 1] = 0; DEBUG_TRACE("mg_cry called from %s:%u: %s", func, line, buf); if (!conn) { puts(buf); return; } /* Do not lock when getting the callback value, here and below. * I suppose this is fine, since function cannot disappear in the * same way string option can. */ if ((conn->phys_ctx->callbacks.log_message == NULL) || (conn->phys_ctx->callbacks.log_message(conn, buf) == 0)) { if (conn->dom_ctx->config[ERROR_LOG_FILE] != NULL) { if (mg_fopen(conn, conn->dom_ctx->config[ERROR_LOG_FILE], MG_FOPEN_MODE_APPEND, &fi) == 0) { fi.access.fp = NULL; } } else { fi.access.fp = NULL; } if (fi.access.fp != NULL) { flockfile(fi.access.fp); timestamp = time(NULL); sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa); fprintf(fi.access.fp, "[%010lu] [error] [client %s] ", (unsigned long)timestamp, src_addr); if (conn->request_info.request_method != NULL) { fprintf(fi.access.fp, "%s %s: ", conn->request_info.request_method, conn->request_info.request_uri ? conn->request_info.request_uri : ""); } fprintf(fi.access.fp, "%s", buf); fputc('\n', fi.access.fp); fflush(fi.access.fp); funlockfile(fi.access.fp); (void)mg_fclose(&fi.access); /* Ignore errors. We can't call * mg_cry here anyway ;-) */ } } } #endif /* Externally provided function */ static void mg_cry_internal_wrap(const struct mg_connection *conn, const char *func, unsigned line, const char *fmt, ...) { va_list ap; va_start(ap, fmt); mg_cry_internal_impl(conn, func, line, fmt, ap); va_end(ap); } void mg_cry(const struct mg_connection *conn, const char *fmt, ...) { va_list ap; va_start(ap, fmt); mg_cry_internal_impl(conn, "user", 0, fmt, ap); va_end(ap); } #define mg_cry DO_NOT_USE_THIS_FUNCTION__USE_mg_cry_internal /* Return fake connection structure. Used for logging, if connection * is not applicable at the moment of logging. */ static struct mg_connection * fc(struct mg_context *ctx) { static struct mg_connection fake_connection; fake_connection.phys_ctx = ctx; fake_connection.dom_ctx = &(ctx->dd); return &fake_connection; } const char * mg_version(void) { return CIVETWEB_VERSION; } const struct mg_request_info * mg_get_request_info(const struct mg_connection *conn) { if (!conn) { return NULL; } #if defined(MG_ALLOW_USING_GET_REQUEST_INFO_FOR_RESPONSE) if (conn->connection_type == CONNECTION_TYPE_RESPONSE) { char txt[16]; struct mg_workerTLS *tls = (struct mg_workerTLS *)pthread_getspecific(sTlsKey); sprintf(txt, "%03i", conn->response_info.status_code); if (strlen(txt) == 3) { memcpy(tls->txtbuf, txt, 4); } else { strcpy(tls->txtbuf, "ERR"); } ((struct mg_connection *)conn)->request_info.local_uri = ((struct mg_connection *)conn)->request_info.request_uri = tls->txtbuf; /* use thread safe buffer */ ((struct mg_connection *)conn)->request_info.num_headers = conn->response_info.num_headers; memcpy(((struct mg_connection *)conn)->request_info.http_headers, conn->response_info.http_headers, sizeof(conn->response_info.http_headers)); } else #endif if (conn->connection_type != CONNECTION_TYPE_REQUEST) { return NULL; } return &conn->request_info; } const struct mg_response_info * mg_get_response_info(const struct mg_connection *conn) { if (!conn) { return NULL; } if (conn->connection_type != CONNECTION_TYPE_RESPONSE) { return NULL; } return &conn->response_info; } static const char * get_proto_name(const struct mg_connection *conn) { #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" /* Depending on USE_WEBSOCKET and NO_SSL, some oft the protocols might be * not supported. Clang raises an "unreachable code" warning for parts of ?: * unreachable, but splitting into four different #ifdef clauses here is more * complicated. */ #endif const struct mg_request_info *ri = &conn->request_info; const char *proto = (is_websocket_protocol(conn) ? (ri->is_ssl ? "wss" : "ws") : (ri->is_ssl ? "https" : "http")); return proto; #if defined(__clang__) #pragma clang diagnostic pop #endif } int mg_get_request_link(const struct mg_connection *conn, char *buf, size_t buflen) { if ((buflen < 1) || (buf == 0) || (conn == 0)) { return -1; } else { int truncated = 0; const struct mg_request_info *ri = &conn->request_info; const char *proto = get_proto_name(conn); if (ri->local_uri == NULL) { return -1; } if ((ri->request_uri != NULL) && (0 != strcmp(ri->local_uri, ri->request_uri))) { /* The request uri is different from the local uri. * This is usually if an absolute URI, including server * name has been provided. */ mg_snprintf(conn, &truncated, buf, buflen, "%s://%s", proto, ri->request_uri); if (truncated) { return -1; } return 0; } else { /* The common case is a relative URI, so we have to * construct an absolute URI from server name and port */ #if defined(USE_IPV6) int is_ipv6 = (conn->client.lsa.sa.sa_family == AF_INET6); int port = is_ipv6 ? htons(conn->client.lsa.sin6.sin6_port) : htons(conn->client.lsa.sin.sin_port); #else int port = htons(conn->client.lsa.sin.sin_port); #endif int def_port = ri->is_ssl ? 443 : 80; int auth_domain_check_enabled = conn->dom_ctx->config[ENABLE_AUTH_DOMAIN_CHECK] && (!mg_strcasecmp( conn->dom_ctx->config[ENABLE_AUTH_DOMAIN_CHECK], "yes")); const char *server_domain = conn->dom_ctx->config[AUTHENTICATION_DOMAIN]; char portstr[16]; char server_ip[48]; if (port != def_port) { sprintf(portstr, ":%u", (unsigned)port); } else { portstr[0] = 0; } if (!auth_domain_check_enabled || !server_domain) { sockaddr_to_string(server_ip, sizeof(server_ip), &conn->client.lsa); server_domain = server_ip; } mg_snprintf(conn, &truncated, buf, buflen, "%s://%s%s%s", proto, server_domain, portstr, ri->local_uri); if (truncated) { return -1; } return 0; } } } /* Skip the characters until one of the delimiters characters found. * 0-terminate resulting word. Skip the delimiter and following whitespaces. * Advance pointer to buffer to the next word. Return found 0-terminated * word. * Delimiters can be quoted with quotechar. */ static char * skip_quoted(char **buf, const char *delimiters, const char *whitespace, char quotechar) { char *p, *begin_word, *end_word, *end_whitespace; begin_word = *buf; end_word = begin_word + strcspn(begin_word, delimiters); /* Check for quotechar */ if (end_word > begin_word) { p = end_word - 1; while (*p == quotechar) { /* While the delimiter is quoted, look for the next delimiter. */ /* This happens, e.g., in calls from parse_auth_header, * if the user name contains a " character. */ /* If there is anything beyond end_word, copy it. */ if (*end_word != '\0') { size_t end_off = strcspn(end_word + 1, delimiters); memmove(p, end_word, end_off + 1); p += end_off; /* p must correspond to end_word - 1 */ end_word += end_off + 1; } else { *p = '\0'; break; } } for (p++; p < end_word; p++) { *p = '\0'; } } if (*end_word == '\0') { *buf = end_word; } else { #if defined(GCC_DIAGNOSTIC) /* Disable spurious conversion warning for GCC */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-conversion" #endif /* defined(GCC_DIAGNOSTIC) */ end_whitespace = end_word + strspn(&end_word[1], whitespace) + 1; #if defined(GCC_DIAGNOSTIC) #pragma GCC diagnostic pop #endif /* defined(GCC_DIAGNOSTIC) */ for (p = end_word; p < end_whitespace; p++) { *p = '\0'; } *buf = end_whitespace; } return begin_word; } /* Return HTTP header value, or NULL if not found. */ static const char * get_header(const struct mg_header *hdr, int num_hdr, const char *name) { int i; for (i = 0; i < num_hdr; i++) { if (!mg_strcasecmp(name, hdr[i].name)) { return hdr[i].value; } } return NULL; } #if defined(USE_WEBSOCKET) /* Retrieve requested HTTP header multiple values, and return the number of * found occurrences */ static int get_req_headers(const struct mg_request_info *ri, const char *name, const char **output, int output_max_size) { int i; int cnt = 0; if (ri) { for (i = 0; i < ri->num_headers && cnt < output_max_size; i++) { if (!mg_strcasecmp(name, ri->http_headers[i].name)) { output[cnt++] = ri->http_headers[i].value; } } } return cnt; } #endif const char * mg_get_header(const struct mg_connection *conn, const char *name) { if (!conn) { return NULL; } if (conn->connection_type == CONNECTION_TYPE_REQUEST) { return get_header(conn->request_info.http_headers, conn->request_info.num_headers, name); } if (conn->connection_type == CONNECTION_TYPE_RESPONSE) { return get_header(conn->response_info.http_headers, conn->response_info.num_headers, name); } return NULL; } static const char * get_http_version(const struct mg_connection *conn) { if (!conn) { return NULL; } if (conn->connection_type == CONNECTION_TYPE_REQUEST) { return conn->request_info.http_version; } if (conn->connection_type == CONNECTION_TYPE_RESPONSE) { return conn->response_info.http_version; } return NULL; } /* A helper function for traversing a comma separated list of values. * It returns a list pointer shifted to the next value, or NULL if the end * of the list found. * Value is stored in val vector. If value has form "x=y", then eq_val * vector is initialized to point to the "y" part, and val vector length * is adjusted to point only to "x". */ static const char * next_option(const char *list, struct vec *val, struct vec *eq_val) { int end; reparse: if (val == NULL || list == NULL || *list == '\0') { /* End of the list */ return NULL; } /* Skip over leading LWS */ while (*list == ' ' || *list == '\t') list++; val->ptr = list; if ((list = strchr(val->ptr, ',')) != NULL) { /* Comma found. Store length and shift the list ptr */ val->len = ((size_t)(list - val->ptr)); list++; } else { /* This value is the last one */ list = val->ptr + strlen(val->ptr); val->len = ((size_t)(list - val->ptr)); } /* Adjust length for trailing LWS */ end = (int)val->len - 1; while (end >= 0 && ((val->ptr[end] == ' ') || (val->ptr[end] == '\t'))) end--; val->len = (size_t)(end + 1); if (val->len == 0) { /* Ignore any empty entries. */ goto reparse; } if (eq_val != NULL) { /* Value has form "x=y", adjust pointers and lengths * so that val points to "x", and eq_val points to "y". */ eq_val->len = 0; eq_val->ptr = (const char *)memchr(val->ptr, '=', val->len); if (eq_val->ptr != NULL) { eq_val->ptr++; /* Skip over '=' character */ eq_val->len = ((size_t)(val->ptr - eq_val->ptr)) + val->len; val->len = ((size_t)(eq_val->ptr - val->ptr)) - 1; } } return list; } /* A helper function for checking if a comma separated list of values * contains * the given option (case insensitvely). * 'header' can be NULL, in which case false is returned. */ static int header_has_option(const char *header, const char *option) { struct vec opt_vec; struct vec eq_vec; DEBUG_ASSERT(option != NULL); DEBUG_ASSERT(option[0] != '\0'); while ((header = next_option(header, &opt_vec, &eq_vec)) != NULL) { if (mg_strncasecmp(option, opt_vec.ptr, opt_vec.len) == 0) return 1; } return 0; } /* Perform case-insensitive match of string against pattern */ static ptrdiff_t match_prefix(const char *pattern, size_t pattern_len, const char *str) { const char *or_str; ptrdiff_t i, j, len, res; if ((or_str = (const char *)memchr(pattern, '|', pattern_len)) != NULL) { res = match_prefix(pattern, (size_t)(or_str - pattern), str); return (res > 0) ? res : match_prefix(or_str + 1, (size_t)((pattern + pattern_len) - (or_str + 1)), str); } for (i = 0, j = 0; (i < (ptrdiff_t)pattern_len); i++, j++) { if ((pattern[i] == '?') && (str[j] != '\0')) { continue; } else if (pattern[i] == '$') { return (str[j] == '\0') ? j : -1; } else if (pattern[i] == '*') { i++; if (pattern[i] == '*') { i++; len = strlen(str + j); } else { len = strcspn(str + j, "/"); } if (i == (ptrdiff_t)pattern_len) { return j + len; } do { res = match_prefix(pattern + i, pattern_len - i, str + j + len); } while (res == -1 && len-- > 0); return (res == -1) ? -1 : j + res + len; } else if (lowercase(&pattern[i]) != lowercase(&str[j])) { return -1; } } return (ptrdiff_t)j; } /* HTTP 1.1 assumes keep alive if "Connection:" header is not set * This function must tolerate situations when connection info is not * set up, for example if request parsing failed. */ static int should_keep_alive(const struct mg_connection *conn) { const char *http_version; const char *header; /* First satisfy needs of the server */ if ((conn == NULL) || conn->must_close) { /* Close, if civetweb framework needs to close */ return 0; } if (mg_strcasecmp(conn->dom_ctx->config[ENABLE_KEEP_ALIVE], "yes") != 0) { /* Close, if keep alive is not enabled */ return 0; } /* Check explicit wish of the client */ header = mg_get_header(conn, "Connection"); if (header) { /* If there is a connection header from the client, obey */ if (header_has_option(header, "keep-alive")) { return 1; } return 0; } /* Use default of the standard */ http_version = get_http_version(conn); if (http_version && (0 == strcmp(http_version, "1.1"))) { /* HTTP 1.1 default is keep alive */ return 1; } /* HTTP 1.0 (and earlier) default is to close the connection */ return 0; } static int should_decode_url(const struct mg_connection *conn) { if (!conn || !conn->dom_ctx) { return 0; } return (mg_strcasecmp(conn->dom_ctx->config[DECODE_URL], "yes") == 0); } static const char * suggest_connection_header(const struct mg_connection *conn) { return should_keep_alive(conn) ? "keep-alive" : "close"; } static int send_no_cache_header(struct mg_connection *conn) { /* Send all current and obsolete cache opt-out directives. */ return mg_printf(conn, "Cache-Control: no-cache, no-store, " "must-revalidate, private, max-age=0\r\n" "Pragma: no-cache\r\n" "Expires: 0\r\n"); } static int send_static_cache_header(struct mg_connection *conn) { #if !defined(NO_CACHING) /* Read the server config to check how long a file may be cached. * The configuration is in seconds. */ int max_age = atoi(conn->dom_ctx->config[STATIC_FILE_MAX_AGE]); if (max_age <= 0) { /* 0 means "do not cache". All values <0 are reserved * and may be used differently in the future. */ /* If a file should not be cached, do not only send * max-age=0, but also pragmas and Expires headers. */ return send_no_cache_header(conn); } /* Use "Cache-Control: max-age" instead of "Expires" header. * Reason: see https://www.mnot.net/blog/2007/05/15/expires_max-age */ /* See also https://www.mnot.net/cache_docs/ */ /* According to RFC 2616, Section 14.21, caching times should not exceed * one year. A year with 365 days corresponds to 31536000 seconds, a * leap * year to 31622400 seconds. For the moment, we just send whatever has * been configured, still the behavior for >1 year should be considered * as undefined. */ return mg_printf(conn, "Cache-Control: max-age=%u\r\n", (unsigned)max_age); #else /* NO_CACHING */ return send_no_cache_header(conn); #endif /* !NO_CACHING */ } static int send_additional_header(struct mg_connection *conn) { int i = 0; const char *header = conn->dom_ctx->config[ADDITIONAL_HEADER]; #if !defined(NO_SSL) if (conn->dom_ctx->config[STRICT_HTTPS_MAX_AGE]) { int max_age = atoi(conn->dom_ctx->config[STRICT_HTTPS_MAX_AGE]); if (max_age >= 0) { i += mg_printf(conn, "Strict-Transport-Security: max-age=%u\r\n", (unsigned)max_age); } } #endif if (header && header[0]) { i += mg_printf(conn, "%s\r\n", header); } return i; } static void handle_file_based_request(struct mg_connection *conn, const char *path, struct mg_file *filep); const char * mg_get_response_code_text(const struct mg_connection *conn, int response_code) { /* See IANA HTTP status code assignment: * http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml */ switch (response_code) { /* RFC2616 Section 10.1 - Informational 1xx */ case 100: return "Continue"; /* RFC2616 Section 10.1.1 */ case 101: return "Switching Protocols"; /* RFC2616 Section 10.1.2 */ case 102: return "Processing"; /* RFC2518 Section 10.1 */ /* RFC2616 Section 10.2 - Successful 2xx */ case 200: return "OK"; /* RFC2616 Section 10.2.1 */ case 201: return "Created"; /* RFC2616 Section 10.2.2 */ case 202: return "Accepted"; /* RFC2616 Section 10.2.3 */ case 203: return "Non-Authoritative Information"; /* RFC2616 Section 10.2.4 */ case 204: return "No Content"; /* RFC2616 Section 10.2.5 */ case 205: return "Reset Content"; /* RFC2616 Section 10.2.6 */ case 206: return "Partial Content"; /* RFC2616 Section 10.2.7 */ case 207: return "Multi-Status"; /* RFC2518 Section 10.2, RFC4918 Section 11.1 */ case 208: return "Already Reported"; /* RFC5842 Section 7.1 */ case 226: return "IM used"; /* RFC3229 Section 10.4.1 */ /* RFC2616 Section 10.3 - Redirection 3xx */ case 300: return "Multiple Choices"; /* RFC2616 Section 10.3.1 */ case 301: return "Moved Permanently"; /* RFC2616 Section 10.3.2 */ case 302: return "Found"; /* RFC2616 Section 10.3.3 */ case 303: return "See Other"; /* RFC2616 Section 10.3.4 */ case 304: return "Not Modified"; /* RFC2616 Section 10.3.5 */ case 305: return "Use Proxy"; /* RFC2616 Section 10.3.6 */ case 307: return "Temporary Redirect"; /* RFC2616 Section 10.3.8 */ case 308: return "Permanent Redirect"; /* RFC7238 Section 3 */ /* RFC2616 Section 10.4 - Client Error 4xx */ case 400: return "Bad Request"; /* RFC2616 Section 10.4.1 */ case 401: return "Unauthorized"; /* RFC2616 Section 10.4.2 */ case 402: return "Payment Required"; /* RFC2616 Section 10.4.3 */ case 403: return "Forbidden"; /* RFC2616 Section 10.4.4 */ case 404: return "Not Found"; /* RFC2616 Section 10.4.5 */ case 405: return "Method Not Allowed"; /* RFC2616 Section 10.4.6 */ case 406: return "Not Acceptable"; /* RFC2616 Section 10.4.7 */ case 407: return "Proxy Authentication Required"; /* RFC2616 Section 10.4.8 */ case 408: return "Request Time-out"; /* RFC2616 Section 10.4.9 */ case 409: return "Conflict"; /* RFC2616 Section 10.4.10 */ case 410: return "Gone"; /* RFC2616 Section 10.4.11 */ case 411: return "Length Required"; /* RFC2616 Section 10.4.12 */ case 412: return "Precondition Failed"; /* RFC2616 Section 10.4.13 */ case 413: return "Request Entity Too Large"; /* RFC2616 Section 10.4.14 */ case 414: return "Request-URI Too Large"; /* RFC2616 Section 10.4.15 */ case 415: return "Unsupported Media Type"; /* RFC2616 Section 10.4.16 */ case 416: return "Requested range not satisfiable"; /* RFC2616 Section 10.4.17 */ case 417: return "Expectation Failed"; /* RFC2616 Section 10.4.18 */ case 421: return "Misdirected Request"; /* RFC7540 Section 9.1.2 */ case 422: return "Unproccessable entity"; /* RFC2518 Section 10.3, RFC4918 * Section 11.2 */ case 423: return "Locked"; /* RFC2518 Section 10.4, RFC4918 Section 11.3 */ case 424: return "Failed Dependency"; /* RFC2518 Section 10.5, RFC4918 * Section 11.4 */ case 426: return "Upgrade Required"; /* RFC 2817 Section 4 */ case 428: return "Precondition Required"; /* RFC 6585, Section 3 */ case 429: return "Too Many Requests"; /* RFC 6585, Section 4 */ case 431: return "Request Header Fields Too Large"; /* RFC 6585, Section 5 */ case 451: return "Unavailable For Legal Reasons"; /* draft-tbray-http-legally-restricted-status-05, * Section 3 */ /* RFC2616 Section 10.5 - Server Error 5xx */ case 500: return "Internal Server Error"; /* RFC2616 Section 10.5.1 */ case 501: return "Not Implemented"; /* RFC2616 Section 10.5.2 */ case 502: return "Bad Gateway"; /* RFC2616 Section 10.5.3 */ case 503: return "Service Unavailable"; /* RFC2616 Section 10.5.4 */ case 504: return "Gateway Time-out"; /* RFC2616 Section 10.5.5 */ case 505: return "HTTP Version not supported"; /* RFC2616 Section 10.5.6 */ case 506: return "Variant Also Negotiates"; /* RFC 2295, Section 8.1 */ case 507: return "Insufficient Storage"; /* RFC2518 Section 10.6, RFC4918 * Section 11.5 */ case 508: return "Loop Detected"; /* RFC5842 Section 7.1 */ case 510: return "Not Extended"; /* RFC 2774, Section 7 */ case 511: return "Network Authentication Required"; /* RFC 6585, Section 6 */ /* Other status codes, not shown in the IANA HTTP status code * assignment. * E.g., "de facto" standards due to common use, ... */ case 418: return "I am a teapot"; /* RFC2324 Section 2.3.2 */ case 419: return "Authentication Timeout"; /* common use */ case 420: return "Enhance Your Calm"; /* common use */ case 440: return "Login Timeout"; /* common use */ case 509: return "Bandwidth Limit Exceeded"; /* common use */ default: /* This error code is unknown. This should not happen. */ if (conn) { mg_cry_internal(conn, "Unknown HTTP response code: %u", response_code); } /* Return at least a category according to RFC 2616 Section 10. */ if (response_code >= 100 && response_code < 200) { /* Unknown informational status code */ return "Information"; } if (response_code >= 200 && response_code < 300) { /* Unknown success code */ return "Success"; } if (response_code >= 300 && response_code < 400) { /* Unknown redirection code */ return "Redirection"; } if (response_code >= 400 && response_code < 500) { /* Unknown request error code */ return "Client Error"; } if (response_code >= 500 && response_code < 600) { /* Unknown server error code */ return "Server Error"; } /* Response code not even within reasonable range */ return ""; } } static int mg_send_http_error_impl(struct mg_connection *conn, int status, const char *fmt, va_list args) { char errmsg_buf[MG_BUF_LEN]; char path_buf[PATH_MAX]; va_list ap; int len, i, page_handler_found, scope, truncated, has_body; char date[64]; time_t curtime = time(NULL); const char *error_handler = NULL; struct mg_file error_page_file = STRUCT_FILE_INITIALIZER; const char *error_page_file_ext, *tstr; int handled_by_callback = 0; const char *status_text = mg_get_response_code_text(conn, status); if ((conn == NULL) || (fmt == NULL)) { return -2; } /* Set status (for log) */ conn->status_code = status; /* Errors 1xx, 204 and 304 MUST NOT send a body */ has_body = ((status > 199) && (status != 204) && (status != 304)); /* Prepare message in buf, if required */ if (has_body || (!conn->in_error_handler && (conn->phys_ctx->callbacks.http_error != NULL))) { /* Store error message in errmsg_buf */ va_copy(ap, args); mg_vsnprintf(conn, NULL, errmsg_buf, sizeof(errmsg_buf), fmt, ap); va_end(ap); /* In a debug build, print all html errors */ DEBUG_TRACE("Error %i - [%s]", status, errmsg_buf); } /* If there is a http_error callback, call it. * But don't do it recursively, if callback calls mg_send_http_error again. */ if (!conn->in_error_handler && (conn->phys_ctx->callbacks.http_error != NULL)) { /* Mark in_error_handler to avoid recursion and call user callback. */ conn->in_error_handler = 1; handled_by_callback = (conn->phys_ctx->callbacks.http_error(conn, status, errmsg_buf) == 0); conn->in_error_handler = 0; } if (!handled_by_callback) { /* Check for recursion */ if (conn->in_error_handler) { DEBUG_TRACE( "Recursion when handling error %u - fall back to default", status); } else { /* Send user defined error pages, if defined */ error_handler = conn->dom_ctx->config[ERROR_PAGES]; error_page_file_ext = conn->dom_ctx->config[INDEX_FILES]; page_handler_found = 0; if (error_handler != NULL) { for (scope = 1; (scope <= 3) && !page_handler_found; scope++) { switch (scope) { case 1: /* Handler for specific error, e.g. 404 error */ mg_snprintf(conn, &truncated, path_buf, sizeof(path_buf) - 32, "%serror%03u.", error_handler, status); break; case 2: /* Handler for error group, e.g., 5xx error * handler * for all server errors (500-599) */ mg_snprintf(conn, &truncated, path_buf, sizeof(path_buf) - 32, "%serror%01uxx.", error_handler, status / 100); break; default: /* Handler for all errors */ mg_snprintf(conn, &truncated, path_buf, sizeof(path_buf) - 32, "%serror.", error_handler); break; } /* String truncation in buf may only occur if * error_handler is too long. This string is * from the config, not from a client. */ (void)truncated; len = (int)strlen(path_buf); tstr = strchr(error_page_file_ext, '.'); while (tstr) { for (i = 1; (i < 32) && (tstr[i] != 0) && (tstr[i] != ','); i++) { /* buffer overrun is not possible here, since * (i < 32) && (len < sizeof(path_buf) - 32) * ==> (i + len) < sizeof(path_buf) */ path_buf[len + i - 1] = tstr[i]; } /* buffer overrun is not possible here, since * (i <= 32) && (len < sizeof(path_buf) - 32) * ==> (i + len) <= sizeof(path_buf) */ path_buf[len + i - 1] = 0; if (mg_stat(conn, path_buf, &error_page_file.stat)) { DEBUG_TRACE("Check error page %s - found", path_buf); page_handler_found = 1; break; } DEBUG_TRACE("Check error page %s - not found", path_buf); tstr = strchr(tstr + i, '.'); } } } if (page_handler_found) { conn->in_error_handler = 1; handle_file_based_request(conn, path_buf, &error_page_file); conn->in_error_handler = 0; return 0; } } /* No custom error page. Send default error page. */ gmt_time_string(date, sizeof(date), &curtime); conn->must_close = 1; mg_printf(conn, "HTTP/1.1 %d %s\r\n", status, status_text); send_no_cache_header(conn); send_additional_header(conn); if (has_body) { mg_printf(conn, "%s", "Content-Type: text/plain; charset=utf-8\r\n"); } mg_printf(conn, "Date: %s\r\n" "Connection: close\r\n\r\n", date); /* HTTP responses 1xx, 204 and 304 MUST NOT send a body */ if (has_body) { /* For other errors, send a generic error message. */ mg_printf(conn, "Error %d: %s\n", status, status_text); mg_write(conn, errmsg_buf, strlen(errmsg_buf)); } else { /* No body allowed. Close the connection. */ DEBUG_TRACE("Error %i", status); } } return 0; } int mg_send_http_error(struct mg_connection *conn, int status, const char *fmt, ...) { va_list ap; int ret; va_start(ap, fmt); ret = mg_send_http_error_impl(conn, status, fmt, ap); va_end(ap); return ret; } int mg_send_http_ok(struct mg_connection *conn, const char *mime_type, long long content_length) { char date[64]; time_t curtime = time(NULL); if ((mime_type == NULL) || (*mime_type == 0)) { /* Parameter error */ return -2; } gmt_time_string(date, sizeof(date), &curtime); mg_printf(conn, "HTTP/1.1 200 OK\r\n" "Content-Type: %s\r\n" "Date: %s\r\n" "Connection: %s\r\n", mime_type, date, suggest_connection_header(conn)); send_no_cache_header(conn); send_additional_header(conn); if (content_length < 0) { mg_printf(conn, "Transfer-Encoding: chunked\r\n\r\n"); } else { mg_printf(conn, "Content-Length: %" UINT64_FMT "\r\n\r\n", (uint64_t)content_length); } return 0; } int mg_send_http_redirect(struct mg_connection *conn, const char *target_url, int redirect_code) { /* Send a 30x redirect response. * * Redirect types (status codes): * * Status | Perm/Temp | Method | Version * 301 | permanent | POST->GET undefined | HTTP/1.0 * 302 | temporary | POST->GET undefined | HTTP/1.0 * 303 | temporary | always use GET | HTTP/1.1 * 307 | temporary | always keep method | HTTP/1.1 * 308 | permanent | always keep method | HTTP/1.1 */ const char *redirect_text; int ret; size_t content_len = 0; char reply[MG_BUF_LEN]; /* In case redirect_code=0, use 307. */ if (redirect_code == 0) { redirect_code = 307; } /* In case redirect_code is none of the above, return error. */ if ((redirect_code != 301) && (redirect_code != 302) && (redirect_code != 303) && (redirect_code != 307) && (redirect_code != 308)) { /* Parameter error */ return -2; } /* Get proper text for response code */ redirect_text = mg_get_response_code_text(conn, redirect_code); /* If target_url is not defined, redirect to "/". */ if ((target_url == NULL) || (*target_url == 0)) { target_url = "/"; } #if defined(MG_SEND_REDIRECT_BODY) /* TODO: condition name? */ /* Prepare a response body with a hyperlink. * * According to RFC2616 (and RFC1945 before): * Unless the request method was HEAD, the entity of the * response SHOULD contain a short hypertext note with a hyperlink to * the new URI(s). * * However, this response body is not useful in M2M communication. * Probably the original reason in the RFC was, clients not supporting * a 30x HTTP redirect could still show the HTML page and let the user * press the link. Since current browsers support 30x HTTP, the additional * HTML body does not seem to make sense anymore. * * The new RFC7231 (Section 6.4) does no longer recommend it ("SHOULD"), * but it only notes: * The server's response payload usually contains a short * hypertext note with a hyperlink to the new URI(s). * * Deactivated by default. If you need the 30x body, set the define. */ mg_snprintf( conn, NULL /* ignore truncation */, reply, sizeof(reply), "<html><head>%s</head><body><a href=\"%s\">%s</a></body></html>", redirect_text, target_url, target_url); content_len = strlen(reply); #else reply[0] = 0; #endif /* Do not send any additional header. For all other options, * including caching, there are suitable defaults. */ ret = mg_printf(conn, "HTTP/1.1 %i %s\r\n" "Location: %s\r\n" "Content-Length: %u\r\n" "Connection: %s\r\n\r\n", redirect_code, redirect_text, target_url, (unsigned int)content_len, suggest_connection_header(conn)); /* Send response body */ if (ret > 0) { /* ... unless it is a HEAD request */ if (0 != strcmp(conn->request_info.request_method, "HEAD")) { ret = mg_write(conn, reply, content_len); } } return (ret > 0) ? ret : -1; } #if defined(_WIN32) /* Create substitutes for POSIX functions in Win32. */ #if defined(GCC_DIAGNOSTIC) /* Show no warning in case system functions are not used. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #endif FUNCTION_MAY_BE_UNUSED static int pthread_mutex_init(pthread_mutex_t *mutex, void *unused) { (void)unused; *mutex = CreateMutex(NULL, FALSE, NULL); return (*mutex == NULL) ? -1 : 0; } FUNCTION_MAY_BE_UNUSED static int pthread_mutex_destroy(pthread_mutex_t *mutex) { return (CloseHandle(*mutex) == 0) ? -1 : 0; } FUNCTION_MAY_BE_UNUSED static int pthread_mutex_lock(pthread_mutex_t *mutex) { return (WaitForSingleObject(*mutex, (DWORD)INFINITE) == WAIT_OBJECT_0) ? 0 : -1; } #if defined(ENABLE_UNUSED_PTHREAD_FUNCTIONS) FUNCTION_MAY_BE_UNUSED static int pthread_mutex_trylock(pthread_mutex_t *mutex) { switch (WaitForSingleObject(*mutex, 0)) { case WAIT_OBJECT_0: return 0; case WAIT_TIMEOUT: return -2; /* EBUSY */ } return -1; } #endif FUNCTION_MAY_BE_UNUSED static int pthread_mutex_unlock(pthread_mutex_t *mutex) { return (ReleaseMutex(*mutex) == 0) ? -1 : 0; } FUNCTION_MAY_BE_UNUSED static int pthread_cond_init(pthread_cond_t *cv, const void *unused) { (void)unused; InitializeCriticalSection(&cv->threadIdSec); cv->waiting_thread = NULL; return 0; } FUNCTION_MAY_BE_UNUSED static int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t *mutex, FUNCTION_MAY_BE_UNUSED const struct timespec *abstime) { struct mg_workerTLS **ptls, *tls = (struct mg_workerTLS *)pthread_getspecific(sTlsKey); int ok; int64_t nsnow, nswaitabs, nswaitrel; DWORD mswaitrel; EnterCriticalSection(&cv->threadIdSec); /* Add this thread to cv's waiting list */ ptls = &cv->waiting_thread; for (; *ptls != NULL; ptls = &(*ptls)->next_waiting_thread) ; tls->next_waiting_thread = NULL; *ptls = tls; LeaveCriticalSection(&cv->threadIdSec); if (abstime) { nsnow = mg_get_current_time_ns(); nswaitabs = (((int64_t)abstime->tv_sec) * 1000000000) + abstime->tv_nsec; nswaitrel = nswaitabs - nsnow; if (nswaitrel < 0) { nswaitrel = 0; } mswaitrel = (DWORD)(nswaitrel / 1000000); } else { mswaitrel = (DWORD)INFINITE; } pthread_mutex_unlock(mutex); ok = (WAIT_OBJECT_0 == WaitForSingleObject(tls->pthread_cond_helper_mutex, mswaitrel)); if (!ok) { ok = 1; EnterCriticalSection(&cv->threadIdSec); ptls = &cv->waiting_thread; for (; *ptls != NULL; ptls = &(*ptls)->next_waiting_thread) { if (*ptls == tls) { *ptls = tls->next_waiting_thread; ok = 0; break; } } LeaveCriticalSection(&cv->threadIdSec); if (ok) { WaitForSingleObject(tls->pthread_cond_helper_mutex, (DWORD)INFINITE); } } /* This thread has been removed from cv's waiting list */ pthread_mutex_lock(mutex); return ok ? 0 : -1; } FUNCTION_MAY_BE_UNUSED static int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex) { return pthread_cond_timedwait(cv, mutex, NULL); } FUNCTION_MAY_BE_UNUSED static int pthread_cond_signal(pthread_cond_t *cv) { HANDLE wkup = NULL; BOOL ok = FALSE; EnterCriticalSection(&cv->threadIdSec); if (cv->waiting_thread) { wkup = cv->waiting_thread->pthread_cond_helper_mutex; cv->waiting_thread = cv->waiting_thread->next_waiting_thread; ok = SetEvent(wkup); DEBUG_ASSERT(ok); } LeaveCriticalSection(&cv->threadIdSec); return ok ? 0 : 1; } FUNCTION_MAY_BE_UNUSED static int pthread_cond_broadcast(pthread_cond_t *cv) { EnterCriticalSection(&cv->threadIdSec); while (cv->waiting_thread) { pthread_cond_signal(cv); } LeaveCriticalSection(&cv->threadIdSec); return 0; } FUNCTION_MAY_BE_UNUSED static int pthread_cond_destroy(pthread_cond_t *cv) { EnterCriticalSection(&cv->threadIdSec); DEBUG_ASSERT(cv->waiting_thread == NULL); LeaveCriticalSection(&cv->threadIdSec); DeleteCriticalSection(&cv->threadIdSec); return 0; } #if defined(ALTERNATIVE_QUEUE) FUNCTION_MAY_BE_UNUSED static void * event_create(void) { return (void *)CreateEvent(NULL, FALSE, FALSE, NULL); } FUNCTION_MAY_BE_UNUSED static int event_wait(void *eventhdl) { int res = WaitForSingleObject((HANDLE)eventhdl, (DWORD)INFINITE); return (res == WAIT_OBJECT_0); } FUNCTION_MAY_BE_UNUSED static int event_signal(void *eventhdl) { return (int)SetEvent((HANDLE)eventhdl); } FUNCTION_MAY_BE_UNUSED static void event_destroy(void *eventhdl) { CloseHandle((HANDLE)eventhdl); } #endif #if defined(GCC_DIAGNOSTIC) /* Enable unused function warning again */ #pragma GCC diagnostic pop #endif /* For Windows, change all slashes to backslashes in path names. */ static void change_slashes_to_backslashes(char *path) { int i; for (i = 0; path[i] != '\0'; i++) { if (path[i] == '/') { path[i] = '\\'; } /* remove double backslash (check i > 0 to preserve UNC paths, * like \\server\file.txt) */ if ((path[i] == '\\') && (i > 0)) { while ((path[i + 1] == '\\') || (path[i + 1] == '/')) { (void)memmove(path + i + 1, path + i + 2, strlen(path + i + 1)); } } } } static int mg_wcscasecmp(const wchar_t *s1, const wchar_t *s2) { int diff; do { diff = ((*s1 >= L'A') && (*s1 <= L'Z') ? (*s1 - L'A' + L'a') : *s1) - ((*s2 >= L'A') && (*s2 <= L'Z') ? (*s2 - L'A' + L'a') : *s2); s1++; s2++; } while ((diff == 0) && (s1[-1] != L'\0')); return diff; } /* Encode 'path' which is assumed UTF-8 string, into UNICODE string. * wbuf and wbuf_len is a target buffer and its length. */ static void path_to_unicode(const struct mg_connection *conn, const char *path, wchar_t *wbuf, size_t wbuf_len) { char buf[PATH_MAX], buf2[PATH_MAX]; wchar_t wbuf2[W_PATH_MAX + 1]; DWORD long_len, err; int (*fcompare)(const wchar_t *, const wchar_t *) = mg_wcscasecmp; mg_strlcpy(buf, path, sizeof(buf)); change_slashes_to_backslashes(buf); /* Convert to Unicode and back. If doubly-converted string does not * match the original, something is fishy, reject. */ memset(wbuf, 0, wbuf_len * sizeof(wchar_t)); MultiByteToWideChar(CP_UTF8, 0, buf, -1, wbuf, (int)wbuf_len); WideCharToMultiByte( CP_UTF8, 0, wbuf, (int)wbuf_len, buf2, sizeof(buf2), NULL, NULL); if (strcmp(buf, buf2) != 0) { wbuf[0] = L'\0'; } /* Windows file systems are not case sensitive, but you can still use * uppercase and lowercase letters (on all modern file systems). * The server can check if the URI uses the same upper/lowercase * letters an the file system, effectively making Windows servers * case sensitive (like Linux servers are). It is still not possible * to use two files with the same name in different cases on Windows * (like /a and /A) - this would be possible in Linux. * As a default, Windows is not case sensitive, but the case sensitive * file name check can be activated by an additional configuration. */ if (conn) { if (conn->dom_ctx->config[CASE_SENSITIVE_FILES] && !mg_strcasecmp(conn->dom_ctx->config[CASE_SENSITIVE_FILES], "yes")) { /* Use case sensitive compare function */ fcompare = wcscmp; } } (void)conn; /* conn is currently unused */ #if !defined(_WIN32_WCE) /* Only accept a full file path, not a Windows short (8.3) path. */ memset(wbuf2, 0, ARRAY_SIZE(wbuf2) * sizeof(wchar_t)); long_len = GetLongPathNameW(wbuf, wbuf2, ARRAY_SIZE(wbuf2) - 1); if (long_len == 0) { err = GetLastError(); if (err == ERROR_FILE_NOT_FOUND) { /* File does not exist. This is not always a problem here. */ return; } } if ((long_len >= ARRAY_SIZE(wbuf2)) || (fcompare(wbuf, wbuf2) != 0)) { /* Short name is used. */ wbuf[0] = L'\0'; } #else (void)long_len; (void)wbuf2; (void)err; if (strchr(path, '~')) { wbuf[0] = L'\0'; } #endif } static int mg_stat(const struct mg_connection *conn, const char *path, struct mg_file_stat *filep) { wchar_t wbuf[W_PATH_MAX]; WIN32_FILE_ATTRIBUTE_DATA info; time_t creation_time; size_t len; if (!filep) { return 0; } memset(filep, 0, sizeof(*filep)); if (conn && is_file_in_memory(conn, path)) { /* filep->is_directory = 0; filep->gzipped = 0; .. already done by * memset */ /* Quick fix (for 1.9.x): */ /* mg_stat must fill all fields, also for files in memory */ struct mg_file tmp_file = STRUCT_FILE_INITIALIZER; open_file_in_memory(conn, path, &tmp_file, MG_FOPEN_MODE_NONE); filep->size = tmp_file.stat.size; filep->location = 2; /* TODO: for 1.10: restructure how files in memory are handled */ /* The "file in memory" feature is a candidate for deletion. * Please join the discussion at * https://groups.google.com/forum/#!topic/civetweb/h9HT4CmeYqI */ filep->last_modified = time(NULL); /* TODO */ /* last_modified = now ... assumes the file may change during * runtime, * so every mg_fopen call may return different data */ /* last_modified = conn->phys_ctx.start_time; * May be used it the data does not change during runtime. This * allows * browser caching. Since we do not know, we have to assume the file * in memory may change. */ return 1; } path_to_unicode(conn, path, wbuf, ARRAY_SIZE(wbuf)); /* Windows happily opens files with some garbage at the end of file name. * For example, fopen("a.cgi ", "r") on Windows successfully opens * "a.cgi", despite one would expect an error back. */ len = strlen(path); if ((len > 0) && (path[len - 1] != ' ') && (path[len - 1] != '.') && (GetFileAttributesExW(wbuf, GetFileExInfoStandard, &info) != 0)) { filep->size = MAKEUQUAD(info.nFileSizeLow, info.nFileSizeHigh); filep->last_modified = SYS2UNIX_TIME(info.ftLastWriteTime.dwLowDateTime, info.ftLastWriteTime.dwHighDateTime); /* On Windows, the file creation time can be higher than the * modification time, e.g. when a file is copied. * Since the Last-Modified timestamp is used for caching * it should be based on the most recent timestamp. */ creation_time = SYS2UNIX_TIME(info.ftCreationTime.dwLowDateTime, info.ftCreationTime.dwHighDateTime); if (creation_time > filep->last_modified) { filep->last_modified = creation_time; } filep->is_directory = info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; return 1; } return 0; } static int mg_remove(const struct mg_connection *conn, const char *path) { wchar_t wbuf[W_PATH_MAX]; path_to_unicode(conn, path, wbuf, ARRAY_SIZE(wbuf)); return DeleteFileW(wbuf) ? 0 : -1; } static int mg_mkdir(const struct mg_connection *conn, const char *path, int mode) { wchar_t wbuf[W_PATH_MAX]; (void)mode; path_to_unicode(conn, path, wbuf, ARRAY_SIZE(wbuf)); return CreateDirectoryW(wbuf, NULL) ? 0 : -1; } /* Create substitutes for POSIX functions in Win32. */ #if defined(GCC_DIAGNOSTIC) /* Show no warning in case system functions are not used. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #endif /* Implementation of POSIX opendir/closedir/readdir for Windows. */ FUNCTION_MAY_BE_UNUSED static DIR * mg_opendir(const struct mg_connection *conn, const char *name) { DIR *dir = NULL; wchar_t wpath[W_PATH_MAX]; DWORD attrs; if (name == NULL) { SetLastError(ERROR_BAD_ARGUMENTS); } else if ((dir = (DIR *)mg_malloc(sizeof(*dir))) == NULL) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); } else { path_to_unicode(conn, name, wpath, ARRAY_SIZE(wpath)); attrs = GetFileAttributesW(wpath); if ((wcslen(wpath) + 2 < ARRAY_SIZE(wpath)) && (attrs != 0xFFFFFFFF) && ((attrs & FILE_ATTRIBUTE_DIRECTORY) != 0)) { (void)wcscat(wpath, L"\\*"); dir->handle = FindFirstFileW(wpath, &dir->info); dir->result.d_name[0] = '\0'; } else { mg_free(dir); dir = NULL; } } return dir; } FUNCTION_MAY_BE_UNUSED static int mg_closedir(DIR *dir) { int result = 0; if (dir != NULL) { if (dir->handle != INVALID_HANDLE_VALUE) result = FindClose(dir->handle) ? 0 : -1; mg_free(dir); } else { result = -1; SetLastError(ERROR_BAD_ARGUMENTS); } return result; } FUNCTION_MAY_BE_UNUSED static struct dirent * mg_readdir(DIR *dir) { struct dirent *result = 0; if (dir) { if (dir->handle != INVALID_HANDLE_VALUE) { result = &dir->result; (void)WideCharToMultiByte(CP_UTF8, 0, dir->info.cFileName, -1, result->d_name, sizeof(result->d_name), NULL, NULL); if (!FindNextFileW(dir->handle, &dir->info)) { (void)FindClose(dir->handle); dir->handle = INVALID_HANDLE_VALUE; } } else { SetLastError(ERROR_FILE_NOT_FOUND); } } else { SetLastError(ERROR_BAD_ARGUMENTS); } return result; } #if !defined(HAVE_POLL) #undef POLLIN #undef POLLPRI #undef POLLOUT #define POLLIN (1) /* Data ready - read will not block. */ #define POLLPRI (2) /* Priority data ready. */ #define POLLOUT (4) /* Send queue not full - write will not block. */ FUNCTION_MAY_BE_UNUSED static int poll(struct mg_pollfd *pfd, unsigned int n, int milliseconds) { struct timeval tv; fd_set rset; fd_set wset; unsigned int i; int result; SOCKET maxfd = 0; memset(&tv, 0, sizeof(tv)); tv.tv_sec = milliseconds / 1000; tv.tv_usec = (milliseconds % 1000) * 1000; FD_ZERO(&rset); FD_ZERO(&wset); for (i = 0; i < n; i++) { if (pfd[i].events & POLLIN) { FD_SET((SOCKET)pfd[i].fd, &rset); } else if (pfd[i].events & POLLOUT) { FD_SET((SOCKET)pfd[i].fd, &wset); } pfd[i].revents = 0; if (pfd[i].fd > maxfd) { maxfd = pfd[i].fd; } } if ((result = select((int)maxfd + 1, &rset, &wset, NULL, &tv)) > 0) { for (i = 0; i < n; i++) { if (FD_ISSET(pfd[i].fd, &rset)) { pfd[i].revents |= POLLIN; } if (FD_ISSET(pfd[i].fd, &wset)) { pfd[i].revents |= POLLOUT; } } } /* We should subtract the time used in select from remaining * "milliseconds", in particular if called from mg_poll with a * timeout quantum. * Unfortunately, the remaining time is not stored in "tv" in all * implementations, so the result in "tv" must be considered undefined. * See http://man7.org/linux/man-pages/man2/select.2.html */ return result; } #endif /* HAVE_POLL */ #if defined(GCC_DIAGNOSTIC) /* Enable unused function warning again */ #pragma GCC diagnostic pop #endif static void set_close_on_exec(SOCKET sock, struct mg_connection *conn /* may be null */) { (void)conn; /* Unused. */ #if defined(_WIN32_WCE) (void)sock; #else (void)SetHandleInformation((HANDLE)(intptr_t)sock, HANDLE_FLAG_INHERIT, 0); #endif } int mg_start_thread(mg_thread_func_t f, void *p) { #if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) /* Compile-time option to control stack size, e.g. * -DUSE_STACK_SIZE=16384 */ return ((_beginthread((void(__cdecl *)(void *))f, USE_STACK_SIZE, p) == ((uintptr_t)(-1L))) ? -1 : 0); #else return ( (_beginthread((void(__cdecl *)(void *))f, 0, p) == ((uintptr_t)(-1L))) ? -1 : 0); #endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */ } /* Start a thread storing the thread context. */ static int mg_start_thread_with_id(unsigned(__stdcall *f)(void *), void *p, pthread_t *threadidptr) { uintptr_t uip; HANDLE threadhandle; int result = -1; uip = _beginthreadex(NULL, 0, (unsigned(__stdcall *)(void *))f, p, 0, NULL); threadhandle = (HANDLE)uip; if ((uip != (uintptr_t)(-1L)) && (threadidptr != NULL)) { *threadidptr = threadhandle; result = 0; } return result; } /* Wait for a thread to finish. */ static int mg_join_thread(pthread_t threadid) { int result; DWORD dwevent; result = -1; dwevent = WaitForSingleObject(threadid, (DWORD)INFINITE); if (dwevent == WAIT_FAILED) { DEBUG_TRACE("WaitForSingleObject() failed, error %d", ERRNO); } else { if (dwevent == WAIT_OBJECT_0) { CloseHandle(threadid); result = 0; } } return result; } #if !defined(NO_SSL_DL) && !defined(NO_SSL) /* If SSL is loaded dynamically, dlopen/dlclose is required. */ /* Create substitutes for POSIX functions in Win32. */ #if defined(GCC_DIAGNOSTIC) /* Show no warning in case system functions are not used. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #endif FUNCTION_MAY_BE_UNUSED static HANDLE dlopen(const char *dll_name, int flags) { wchar_t wbuf[W_PATH_MAX]; (void)flags; path_to_unicode(NULL, dll_name, wbuf, ARRAY_SIZE(wbuf)); return LoadLibraryW(wbuf); } FUNCTION_MAY_BE_UNUSED static int dlclose(void *handle) { int result; if (FreeLibrary((HMODULE)handle) != 0) { result = 0; } else { result = -1; } return result; } #if defined(GCC_DIAGNOSTIC) /* Enable unused function warning again */ #pragma GCC diagnostic pop #endif #endif #if !defined(NO_CGI) #define SIGKILL (0) static int kill(pid_t pid, int sig_num) { (void)TerminateProcess((HANDLE)pid, (UINT)sig_num); (void)CloseHandle((HANDLE)pid); return 0; } #if !defined(WNOHANG) #define WNOHANG (1) #endif static pid_t waitpid(pid_t pid, int *status, int flags) { DWORD timeout = INFINITE; DWORD waitres; (void)status; /* Currently not used by any client here */ if ((flags | WNOHANG) == WNOHANG) { timeout = 0; } waitres = WaitForSingleObject((HANDLE)pid, timeout); if (waitres == WAIT_OBJECT_0) { return pid; } if (waitres == WAIT_TIMEOUT) { return 0; } return (pid_t)-1; } static void trim_trailing_whitespaces(char *s) { char *e = s + strlen(s); while ((e > s) && isspace((unsigned char)e[-1])) { *(--e) = '\0'; } } static pid_t spawn_process(struct mg_connection *conn, const char *prog, char *envblk, char *envp[], int fdin[2], int fdout[2], int fderr[2], const char *dir) { HANDLE me; char *p, *interp, full_interp[PATH_MAX], full_dir[PATH_MAX], cmdline[PATH_MAX], buf[PATH_MAX]; int truncated; struct mg_file file = STRUCT_FILE_INITIALIZER; STARTUPINFOA si; PROCESS_INFORMATION pi = {0}; (void)envp; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; me = GetCurrentProcess(); DuplicateHandle(me, (HANDLE)_get_osfhandle(fdin[0]), me, &si.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS); DuplicateHandle(me, (HANDLE)_get_osfhandle(fdout[1]), me, &si.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS); DuplicateHandle(me, (HANDLE)_get_osfhandle(fderr[1]), me, &si.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS); /* Mark handles that should not be inherited. See * https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx */ SetHandleInformation((HANDLE)_get_osfhandle(fdin[1]), HANDLE_FLAG_INHERIT, 0); SetHandleInformation((HANDLE)_get_osfhandle(fdout[0]), HANDLE_FLAG_INHERIT, 0); SetHandleInformation((HANDLE)_get_osfhandle(fderr[0]), HANDLE_FLAG_INHERIT, 0); /* If CGI file is a script, try to read the interpreter line */ interp = conn->dom_ctx->config[CGI_INTERPRETER]; if (interp == NULL) { buf[0] = buf[1] = '\0'; /* Read the first line of the script into the buffer */ mg_snprintf( conn, &truncated, cmdline, sizeof(cmdline), "%s/%s", dir, prog); if (truncated) { pi.hProcess = (pid_t)-1; goto spawn_cleanup; } if (mg_fopen(conn, cmdline, MG_FOPEN_MODE_READ, &file)) { #if defined(MG_USE_OPEN_FILE) p = (char *)file.access.membuf; #else p = (char *)NULL; #endif mg_fgets(buf, sizeof(buf), &file, &p); (void)mg_fclose(&file.access); /* ignore error on read only file */ buf[sizeof(buf) - 1] = '\0'; } if ((buf[0] == '#') && (buf[1] == '!')) { trim_trailing_whitespaces(buf + 2); } else { buf[2] = '\0'; } interp = buf + 2; } if (interp[0] != '\0') { GetFullPathNameA(interp, sizeof(full_interp), full_interp, NULL); interp = full_interp; } GetFullPathNameA(dir, sizeof(full_dir), full_dir, NULL); if (interp[0] != '\0') { mg_snprintf(conn, &truncated, cmdline, sizeof(cmdline), "\"%s\" \"%s\\%s\"", interp, full_dir, prog); } else { mg_snprintf(conn, &truncated, cmdline, sizeof(cmdline), "\"%s\\%s\"", full_dir, prog); } if (truncated) { pi.hProcess = (pid_t)-1; goto spawn_cleanup; } DEBUG_TRACE("Running [%s]", cmdline); if (CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, CREATE_NEW_PROCESS_GROUP, envblk, NULL, &si, &pi) == 0) { mg_cry_internal( conn, "%s: CreateProcess(%s): %ld", __func__, cmdline, (long)ERRNO); pi.hProcess = (pid_t)-1; /* goto spawn_cleanup; */ } spawn_cleanup: (void)CloseHandle(si.hStdOutput); (void)CloseHandle(si.hStdError); (void)CloseHandle(si.hStdInput); if (pi.hThread != NULL) { (void)CloseHandle(pi.hThread); } return (pid_t)pi.hProcess; } #endif /* !NO_CGI */ static int set_blocking_mode(SOCKET sock) { unsigned long non_blocking = 0; return ioctlsocket(sock, (long)FIONBIO, &non_blocking); } static int set_non_blocking_mode(SOCKET sock) { unsigned long non_blocking = 1; return ioctlsocket(sock, (long)FIONBIO, &non_blocking); } #else static int mg_stat(const struct mg_connection *conn, const char *path, struct mg_file_stat *filep) { struct stat st; if (!filep) { return 0; } memset(filep, 0, sizeof(*filep)); if (conn && is_file_in_memory(conn, path)) { /* Quick fix (for 1.9.x): */ /* mg_stat must fill all fields, also for files in memory */ struct mg_file tmp_file = STRUCT_FILE_INITIALIZER; open_file_in_memory(conn, path, &tmp_file, MG_FOPEN_MODE_NONE); filep->size = tmp_file.stat.size; filep->last_modified = time(NULL); filep->location = 2; /* TODO: remove legacy "files in memory" feature */ return 1; } if (0 == stat(path, &st)) { filep->size = (uint64_t)(st.st_size); filep->last_modified = st.st_mtime; filep->is_directory = S_ISDIR(st.st_mode); return 1; } return 0; } static void set_close_on_exec(SOCKET fd, struct mg_connection *conn /* may be null */) { if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { if (conn) { mg_cry_internal(conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, strerror(ERRNO)); } } } int mg_start_thread(mg_thread_func_t func, void *param) { pthread_t thread_id; pthread_attr_t attr; int result; (void)pthread_attr_init(&attr); (void)pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); #if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) /* Compile-time option to control stack size, * e.g. -DUSE_STACK_SIZE=16384 */ (void)pthread_attr_setstacksize(&attr, USE_STACK_SIZE); #endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */ result = pthread_create(&thread_id, &attr, func, param); pthread_attr_destroy(&attr); return result; } /* Start a thread storing the thread context. */ static int mg_start_thread_with_id(mg_thread_func_t func, void *param, pthread_t *threadidptr) { pthread_t thread_id; pthread_attr_t attr; int result; (void)pthread_attr_init(&attr); #if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) /* Compile-time option to control stack size, * e.g. -DUSE_STACK_SIZE=16384 */ (void)pthread_attr_setstacksize(&attr, USE_STACK_SIZE); #endif /* defined(USE_STACK_SIZE) && USE_STACK_SIZE > 1 */ result = pthread_create(&thread_id, &attr, func, param); pthread_attr_destroy(&attr); if ((result == 0) && (threadidptr != NULL)) { *threadidptr = thread_id; } return result; } /* Wait for a thread to finish. */ static int mg_join_thread(pthread_t threadid) { int result; result = pthread_join(threadid, NULL); return result; } #if !defined(NO_CGI) static pid_t spawn_process(struct mg_connection *conn, const char *prog, char *envblk, char *envp[], int fdin[2], int fdout[2], int fderr[2], const char *dir) { pid_t pid; const char *interp; (void)envblk; if (conn == NULL) { return 0; } if ((pid = fork()) == -1) { /* Parent */ mg_send_http_error(conn, 500, "Error: Creating CGI process\nfork(): %s", strerror(ERRNO)); } else if (pid == 0) { /* Child */ if (chdir(dir) != 0) { mg_cry_internal( conn, "%s: chdir(%s): %s", __func__, dir, strerror(ERRNO)); } else if (dup2(fdin[0], 0) == -1) { mg_cry_internal(conn, "%s: dup2(%d, 0): %s", __func__, fdin[0], strerror(ERRNO)); } else if (dup2(fdout[1], 1) == -1) { mg_cry_internal(conn, "%s: dup2(%d, 1): %s", __func__, fdout[1], strerror(ERRNO)); } else if (dup2(fderr[1], 2) == -1) { mg_cry_internal(conn, "%s: dup2(%d, 2): %s", __func__, fderr[1], strerror(ERRNO)); } else { /* Keep stderr and stdout in two different pipes. * Stdout will be sent back to the client, * stderr should go into a server error log. */ (void)close(fdin[0]); (void)close(fdout[1]); (void)close(fderr[1]); /* Close write end fdin and read end fdout and fderr */ (void)close(fdin[1]); (void)close(fdout[0]); (void)close(fderr[0]); /* After exec, all signal handlers are restored to their default * values, with one exception of SIGCHLD. According to * POSIX.1-2001 and Linux's implementation, SIGCHLD's handler * will leave unchanged after exec if it was set to be ignored. * Restore it to default action. */ signal(SIGCHLD, SIG_DFL); interp = conn->dom_ctx->config[CGI_INTERPRETER]; if (interp == NULL) { (void)execle(prog, prog, NULL, envp); mg_cry_internal(conn, "%s: execle(%s): %s", __func__, prog, strerror(ERRNO)); } else { (void)execle(interp, interp, prog, NULL, envp); mg_cry_internal(conn, "%s: execle(%s %s): %s", __func__, interp, prog, strerror(ERRNO)); } } exit(EXIT_FAILURE); } return pid; } #endif /* !NO_CGI */ static int set_non_blocking_mode(SOCKET sock) { int flags = fcntl(sock, F_GETFL, 0); if (flags < 0) { return -1; } if (fcntl(sock, F_SETFL, (flags | O_NONBLOCK)) < 0) { return -1; } return 0; } static int set_blocking_mode(SOCKET sock) { int flags = fcntl(sock, F_GETFL, 0); if (flags < 0) { return -1; } if (fcntl(sock, F_SETFL, flags & (~(int)(O_NONBLOCK))) < 0) { return -1; } return 0; } #endif /* _WIN32 / else */ /* End of initial operating system specific define block. */ /* Get a random number (independent of C rand function) */ static uint64_t get_random(void) { static uint64_t lfsr = 0; /* Linear feedback shift register */ static uint64_t lcg = 0; /* Linear congruential generator */ uint64_t now = mg_get_current_time_ns(); if (lfsr == 0) { /* lfsr will be only 0 if has not been initialized, * so this code is called only once. */ lfsr = mg_get_current_time_ns(); lcg = mg_get_current_time_ns(); } else { /* Get the next step of both random number generators. */ lfsr = (lfsr >> 1) | ((((lfsr >> 0) ^ (lfsr >> 1) ^ (lfsr >> 3) ^ (lfsr >> 4)) & 1) << 63); lcg = lcg * 6364136223846793005LL + 1442695040888963407LL; } /* Combining two pseudo-random number generators and a high resolution * part * of the current server time will make it hard (impossible?) to guess * the * next number. */ return (lfsr ^ lcg ^ now); } static int mg_poll(struct mg_pollfd *pfd, unsigned int n, int milliseconds, volatile int *stop_server) { /* Call poll, but only for a maximum time of a few seconds. * This will allow to stop the server after some seconds, instead * of having to wait for a long socket timeout. */ int ms_now = SOCKET_TIMEOUT_QUANTUM; /* Sleep quantum in ms */ do { int result; if (*stop_server) { /* Shut down signal */ return -2; } if ((milliseconds >= 0) && (milliseconds < ms_now)) { ms_now = milliseconds; } result = poll(pfd, n, ms_now); if (result != 0) { /* Poll returned either success (1) or error (-1). * Forward both to the caller. */ return result; } /* Poll returned timeout (0). */ if (milliseconds > 0) { milliseconds -= ms_now; } } while (milliseconds != 0); /* timeout: return 0 */ return 0; } /* Write data to the IO channel - opened file descriptor, socket or SSL * descriptor. * Return value: * >=0 .. number of bytes successfully written * -1 .. timeout * -2 .. error */ static int push_inner(struct mg_context *ctx, FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int len, double timeout) { uint64_t start = 0, now = 0, timeout_ns = 0; int n, err; unsigned ms_wait = SOCKET_TIMEOUT_QUANTUM; /* Sleep quantum in ms */ #if defined(_WIN32) typedef int len_t; #else typedef size_t len_t; #endif if (timeout > 0) { now = mg_get_current_time_ns(); start = now; timeout_ns = (uint64_t)(timeout * 1.0E9); } if (ctx == NULL) { return -2; } #if defined(NO_SSL) if (ssl) { return -2; } #endif /* Try to read until it succeeds, fails, times out, or the server * shuts down. */ for (;;) { #if !defined(NO_SSL) if (ssl != NULL) { n = SSL_write(ssl, buf, len); if (n <= 0) { err = SSL_get_error(ssl, n); if ((err == SSL_ERROR_SYSCALL) && (n == -1)) { err = ERRNO; } else if ((err == SSL_ERROR_WANT_READ) || (err == SSL_ERROR_WANT_WRITE)) { n = 0; } else { DEBUG_TRACE("SSL_write() failed, error %d", err); return -2; } } else { err = 0; } } else #endif if (fp != NULL) { n = (int)fwrite(buf, 1, (size_t)len, fp); if (ferror(fp)) { n = -1; err = ERRNO; } else { err = 0; } } else { n = (int)send(sock, buf, (len_t)len, MSG_NOSIGNAL); err = (n < 0) ? ERRNO : 0; #if defined(_WIN32) if (err == WSAEWOULDBLOCK) { err = 0; n = 0; } #else if (err == EWOULDBLOCK) { err = 0; n = 0; } #endif if (n < 0) { /* shutdown of the socket at client side */ return -2; } } if (ctx->stop_flag) { return -2; } if ((n > 0) || ((n == 0) && (len == 0))) { /* some data has been read, or no data was requested */ return n; } if (n < 0) { /* socket error - check errno */ DEBUG_TRACE("send() failed, error %d", err); /* TODO (mid): error handling depending on the error code. * These codes are different between Windows and Linux. * Currently there is no problem with failing send calls, * if there is a reproducible situation, it should be * investigated in detail. */ return -2; } /* Only in case n=0 (timeout), repeat calling the write function */ /* If send failed, wait before retry */ if (fp != NULL) { /* For files, just wait a fixed time. * Maybe it helps, maybe not. */ mg_sleep(5); } else { /* For sockets, wait for the socket using poll */ struct mg_pollfd pfd[1]; int pollres; pfd[0].fd = sock; pfd[0].events = POLLOUT; pollres = mg_poll(pfd, 1, (int)(ms_wait), &(ctx->stop_flag)); if (ctx->stop_flag) { return -2; } if (pollres > 0) { continue; } } if (timeout > 0) { now = mg_get_current_time_ns(); if ((now - start) > timeout_ns) { /* Timeout */ break; } } } (void)err; /* Avoid unused warning if NO_SSL is set and DEBUG_TRACE is not used */ return -1; } static int64_t push_all(struct mg_context *ctx, FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int64_t len) { double timeout = -1.0; int64_t n, nwritten = 0; if (ctx == NULL) { return -1; } if (ctx->dd.config[REQUEST_TIMEOUT]) { timeout = atoi(ctx->dd.config[REQUEST_TIMEOUT]) / 1000.0; } while ((len > 0) && (ctx->stop_flag == 0)) { n = push_inner(ctx, fp, sock, ssl, buf + nwritten, (int)len, timeout); if (n < 0) { if (nwritten == 0) { nwritten = n; /* Propagate the error */ } break; } else if (n == 0) { break; /* No more data to write */ } else { nwritten += n; len -= n; } } return nwritten; } /* Read from IO channel - opened file descriptor, socket, or SSL descriptor. * Return value: * >=0 .. number of bytes successfully read * -1 .. timeout * -2 .. error */ static int pull_inner(FILE *fp, struct mg_connection *conn, char *buf, int len, double timeout) { int nread, err = 0; #if defined(_WIN32) typedef int len_t; #else typedef size_t len_t; #endif #if !defined(NO_SSL) int ssl_pending; #endif /* We need an additional wait loop around this, because in some cases * with TLSwe may get data from the socket but not from SSL_read. * In this case we need to repeat at least once. */ if (fp != NULL) { #if !defined(_WIN32_WCE) /* Use read() instead of fread(), because if we're reading from the * CGI pipe, fread() may block until IO buffer is filled up. We * cannot afford to block and must pass all read bytes immediately * to the client. */ nread = (int)read(fileno(fp), buf, (size_t)len); #else /* WinCE does not support CGI pipes */ nread = (int)fread(buf, 1, (size_t)len, fp); #endif err = (nread < 0) ? ERRNO : 0; if ((nread == 0) && (len > 0)) { /* Should get data, but got EOL */ return -2; } #if !defined(NO_SSL) } else if ((conn->ssl != NULL) && ((ssl_pending = SSL_pending(conn->ssl)) > 0)) { /* We already know there is no more data buffered in conn->buf * but there is more available in the SSL layer. So don't poll * conn->client.sock yet. */ if (ssl_pending > len) { ssl_pending = len; } nread = SSL_read(conn->ssl, buf, ssl_pending); if (nread <= 0) { err = SSL_get_error(conn->ssl, nread); if ((err == SSL_ERROR_SYSCALL) && (nread == -1)) { err = ERRNO; } else if ((err == SSL_ERROR_WANT_READ) || (err == SSL_ERROR_WANT_WRITE)) { nread = 0; } else { DEBUG_TRACE("SSL_read() failed, error %d", err); return -1; } } else { err = 0; } } else if (conn->ssl != NULL) { struct mg_pollfd pfd[1]; int pollres; pfd[0].fd = conn->client.sock; pfd[0].events = POLLIN; pollres = mg_poll(pfd, 1, (int)(timeout * 1000.0), &(conn->phys_ctx->stop_flag)); if (conn->phys_ctx->stop_flag) { return -2; } if (pollres > 0) { nread = SSL_read(conn->ssl, buf, len); if (nread <= 0) { err = SSL_get_error(conn->ssl, nread); if ((err == SSL_ERROR_SYSCALL) && (nread == -1)) { err = ERRNO; } else if ((err == SSL_ERROR_WANT_READ) || (err == SSL_ERROR_WANT_WRITE)) { nread = 0; } else { DEBUG_TRACE("SSL_read() failed, error %d", err); return -2; } } else { err = 0; } } else if (pollres < 0) { /* Error */ return -2; } else { /* pollres = 0 means timeout */ nread = 0; } #endif } else { struct mg_pollfd pfd[1]; int pollres; pfd[0].fd = conn->client.sock; pfd[0].events = POLLIN; pollres = mg_poll(pfd, 1, (int)(timeout * 1000.0), &(conn->phys_ctx->stop_flag)); if (conn->phys_ctx->stop_flag) { return -2; } if (pollres > 0) { nread = (int)recv(conn->client.sock, buf, (len_t)len, 0); err = (nread < 0) ? ERRNO : 0; if (nread <= 0) { /* shutdown of the socket at client side */ return -2; } } else if (pollres < 0) { /* error callint poll */ return -2; } else { /* pollres = 0 means timeout */ nread = 0; } } if (conn->phys_ctx->stop_flag) { return -2; } if ((nread > 0) || ((nread == 0) && (len == 0))) { /* some data has been read, or no data was requested */ return nread; } if (nread < 0) { /* socket error - check errno */ #if defined(_WIN32) if (err == WSAEWOULDBLOCK) { /* TODO (low): check if this is still required */ /* standard case if called from close_socket_gracefully */ return -2; } else if (err == WSAETIMEDOUT) { /* TODO (low): check if this is still required */ /* timeout is handled by the while loop */ return 0; } else if (err == WSAECONNABORTED) { /* See https://www.chilkatsoft.com/p/p_299.asp */ return -2; } else { DEBUG_TRACE("recv() failed, error %d", err); return -2; } #else /* TODO: POSIX returns either EAGAIN or EWOULDBLOCK in both cases, * if the timeout is reached and if the socket was set to non- * blocking in close_socket_gracefully, so we can not distinguish * here. We have to wait for the timeout in both cases for now. */ if ((err == EAGAIN) || (err == EWOULDBLOCK) || (err == EINTR)) { /* TODO (low): check if this is still required */ /* EAGAIN/EWOULDBLOCK: * standard case if called from close_socket_gracefully * => should return -1 */ /* or timeout occurred * => the code must stay in the while loop */ /* EINTR can be generated on a socket with a timeout set even * when SA_RESTART is effective for all relevant signals * (see signal(7)). * => stay in the while loop */ } else { DEBUG_TRACE("recv() failed, error %d", err); return -2; } #endif } /* Timeout occurred, but no data available. */ return -1; } static int pull_all(FILE *fp, struct mg_connection *conn, char *buf, int len) { int n, nread = 0; double timeout = -1.0; uint64_t start_time = 0, now = 0, timeout_ns = 0; if (conn->dom_ctx->config[REQUEST_TIMEOUT]) { timeout = atoi(conn->dom_ctx->config[REQUEST_TIMEOUT]) / 1000.0; } if (timeout >= 0.0) { start_time = mg_get_current_time_ns(); timeout_ns = (uint64_t)(timeout * 1.0E9); } while ((len > 0) && (conn->phys_ctx->stop_flag == 0)) { n = pull_inner(fp, conn, buf + nread, len, timeout); if (n == -2) { if (nread == 0) { nread = -1; /* Propagate the error */ } break; } else if (n == -1) { /* timeout */ if (timeout >= 0.0) { now = mg_get_current_time_ns(); if ((now - start_time) <= timeout_ns) { continue; } } break; } else if (n == 0) { break; /* No more data to read */ } else { conn->consumed_content += n; nread += n; len -= n; } } return nread; } static void discard_unread_request_data(struct mg_connection *conn) { char buf[MG_BUF_LEN]; size_t to_read; int nread; if (conn == NULL) { return; } to_read = sizeof(buf); if (conn->is_chunked) { /* Chunked encoding: 3=chunk read completely * completely */ while (conn->is_chunked != 3) { nread = mg_read(conn, buf, to_read); if (nread <= 0) { break; } } } else { /* Not chunked: content length is known */ while (conn->consumed_content < conn->content_len) { if (to_read > (size_t)(conn->content_len - conn->consumed_content)) { to_read = (size_t)(conn->content_len - conn->consumed_content); } nread = mg_read(conn, buf, to_read); if (nread <= 0) { break; } } } } static int mg_read_inner(struct mg_connection *conn, void *buf, size_t len) { int64_t n, buffered_len, nread; int64_t len64 = (int64_t)((len > INT_MAX) ? INT_MAX : len); /* since the return value is * int, we may not read more * bytes */ const char *body; if (conn == NULL) { return 0; } /* If Content-Length is not set for a request with body data * (e.g., a PUT or POST request), we do not know in advance * how much data should be read. */ if (conn->consumed_content == 0) { if (conn->is_chunked == 1) { conn->content_len = len64; conn->is_chunked = 2; } else if (conn->content_len == -1) { /* The body data is completed when the connection * is closed. */ conn->content_len = INT64_MAX; conn->must_close = 1; } } nread = 0; if (conn->consumed_content < conn->content_len) { /* Adjust number of bytes to read. */ int64_t left_to_read = conn->content_len - conn->consumed_content; if (left_to_read < len64) { /* Do not read more than the total content length of the * request. */ len64 = left_to_read; } /* Return buffered data */ buffered_len = (int64_t)(conn->data_len) - (int64_t)conn->request_len - conn->consumed_content; if (buffered_len > 0) { if (len64 < buffered_len) { buffered_len = len64; } body = conn->buf + conn->request_len + conn->consumed_content; memcpy(buf, body, (size_t)buffered_len); len64 -= buffered_len; conn->consumed_content += buffered_len; nread += buffered_len; buf = (char *)buf + buffered_len; } /* We have returned all buffered data. Read new data from the remote * socket. */ if ((n = pull_all(NULL, conn, (char *)buf, (int)len64)) >= 0) { nread += n; } else { nread = ((nread > 0) ? nread : n); } } return (int)nread; } static char mg_getc(struct mg_connection *conn) { char c; if (conn == NULL) { return 0; } if (mg_read_inner(conn, &c, 1) <= 0) { return (char)0; } return c; } int mg_read(struct mg_connection *conn, void *buf, size_t len) { if (len > INT_MAX) { len = INT_MAX; } if (conn == NULL) { return 0; } if (conn->is_chunked) { size_t all_read = 0; while (len > 0) { if (conn->is_chunked == 3) { /* No more data left to read */ return 0; } if (conn->chunk_remainder) { /* copy from the remainder of the last received chunk */ long read_ret; size_t read_now = ((conn->chunk_remainder > len) ? (len) : (conn->chunk_remainder)); conn->content_len += (int)read_now; read_ret = mg_read_inner(conn, (char *)buf + all_read, read_now); if (read_ret < 1) { /* read error */ return -1; } all_read += (size_t)read_ret; conn->chunk_remainder -= (size_t)read_ret; len -= (size_t)read_ret; if (conn->chunk_remainder == 0) { /* Add data bytes in the current chunk have been read, * so we are expecting \r\n now. */ char x1, x2; conn->content_len += 2; x1 = mg_getc(conn); x2 = mg_getc(conn); if ((x1 != '\r') || (x2 != '\n')) { /* Protocol violation */ return -1; } } } else { /* fetch a new chunk */ int i = 0; char lenbuf[64]; char *end = 0; unsigned long chunkSize = 0; for (i = 0; i < ((int)sizeof(lenbuf) - 1); i++) { conn->content_len++; lenbuf[i] = mg_getc(conn); if ((i > 0) && (lenbuf[i] == '\r') && (lenbuf[i - 1] != '\r')) { continue; } if ((i > 1) && (lenbuf[i] == '\n') && (lenbuf[i - 1] == '\r')) { lenbuf[i + 1] = 0; chunkSize = strtoul(lenbuf, &end, 16); if (chunkSize == 0) { /* regular end of content */ conn->is_chunked = 3; } break; } if (!isxdigit((unsigned char)lenbuf[i])) { /* illegal character for chunk length */ return -1; } } if ((end == NULL) || (*end != '\r')) { /* chunksize not set correctly */ return -1; } if (chunkSize == 0) { break; } conn->chunk_remainder = chunkSize; } } return (int)all_read; } return mg_read_inner(conn, buf, len); } int mg_write(struct mg_connection *conn, const void *buf, size_t len) { time_t now; int64_t n, total, allowed; if (conn == NULL) { return 0; } if (conn->throttle > 0) { if ((now = time(NULL)) != conn->last_throttle_time) { conn->last_throttle_time = now; conn->last_throttle_bytes = 0; } allowed = conn->throttle - conn->last_throttle_bytes; if (allowed > (int64_t)len) { allowed = (int64_t)len; } if ((total = push_all(conn->phys_ctx, NULL, conn->client.sock, conn->ssl, (const char *)buf, (int64_t)allowed)) == allowed) { buf = (const char *)buf + total; conn->last_throttle_bytes += total; while ((total < (int64_t)len) && (conn->phys_ctx->stop_flag == 0)) { allowed = (conn->throttle > ((int64_t)len - total)) ? (int64_t)len - total : conn->throttle; if ((n = push_all(conn->phys_ctx, NULL, conn->client.sock, conn->ssl, (const char *)buf, (int64_t)allowed)) != allowed) { break; } sleep(1); conn->last_throttle_bytes = allowed; conn->last_throttle_time = time(NULL); buf = (const char *)buf + n; total += n; } } } else { total = push_all(conn->phys_ctx, NULL, conn->client.sock, conn->ssl, (const char *)buf, (int64_t)len); } if (total > 0) { conn->num_bytes_sent += total; } return (int)total; } /* Send a chunk, if "Transfer-Encoding: chunked" is used */ int mg_send_chunk(struct mg_connection *conn, const char *chunk, unsigned int chunk_len) { char lenbuf[16]; size_t lenbuf_len; int ret; int t; /* First store the length information in a text buffer. */ sprintf(lenbuf, "%x\r\n", chunk_len); lenbuf_len = strlen(lenbuf); /* Then send length information, chunk and terminating \r\n. */ ret = mg_write(conn, lenbuf, lenbuf_len); if (ret != (int)lenbuf_len) { return -1; } t = ret; ret = mg_write(conn, chunk, chunk_len); if (ret != (int)chunk_len) { return -1; } t += ret; ret = mg_write(conn, "\r\n", 2); if (ret != 2) { return -1; } t += ret; return t; } #if defined(GCC_DIAGNOSTIC) /* This block forwards format strings to printf implementations, * so we need to disable the format-nonliteral warning. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif /* Alternative alloc_vprintf() for non-compliant C runtimes */ static int alloc_vprintf2(char **buf, const char *fmt, va_list ap) { va_list ap_copy; size_t size = MG_BUF_LEN / 4; int len = -1; *buf = NULL; while (len < 0) { if (*buf) { mg_free(*buf); } size *= 4; *buf = (char *)mg_malloc(size); if (!*buf) { break; } va_copy(ap_copy, ap); len = vsnprintf_impl(*buf, size - 1, fmt, ap_copy); va_end(ap_copy); (*buf)[size - 1] = 0; } return len; } /* Print message to buffer. If buffer is large enough to hold the message, * return buffer. If buffer is to small, allocate large enough buffer on * heap, * and return allocated buffer. */ static int alloc_vprintf(char **out_buf, char *prealloc_buf, size_t prealloc_size, const char *fmt, va_list ap) { va_list ap_copy; int len; /* Windows is not standard-compliant, and vsnprintf() returns -1 if * buffer is too small. Also, older versions of msvcrt.dll do not have * _vscprintf(). However, if size is 0, vsnprintf() behaves correctly. * Therefore, we make two passes: on first pass, get required message * length. * On second pass, actually print the message. */ va_copy(ap_copy, ap); len = vsnprintf_impl(NULL, 0, fmt, ap_copy); va_end(ap_copy); if (len < 0) { /* C runtime is not standard compliant, vsnprintf() returned -1. * Switch to alternative code path that uses incremental * allocations. */ va_copy(ap_copy, ap); len = alloc_vprintf2(out_buf, fmt, ap_copy); va_end(ap_copy); } else if ((size_t)(len) >= prealloc_size) { /* The pre-allocated buffer not large enough. */ /* Allocate a new buffer. */ *out_buf = (char *)mg_malloc((size_t)(len) + 1); if (!*out_buf) { /* Allocation failed. Return -1 as "out of memory" error. */ return -1; } /* Buffer allocation successful. Store the string there. */ va_copy(ap_copy, ap); IGNORE_UNUSED_RESULT( vsnprintf_impl(*out_buf, (size_t)(len) + 1, fmt, ap_copy)); va_end(ap_copy); } else { /* The pre-allocated buffer is large enough. * Use it to store the string and return the address. */ va_copy(ap_copy, ap); IGNORE_UNUSED_RESULT( vsnprintf_impl(prealloc_buf, prealloc_size, fmt, ap_copy)); va_end(ap_copy); *out_buf = prealloc_buf; } return len; } #if defined(GCC_DIAGNOSTIC) /* Enable format-nonliteral warning again. */ #pragma GCC diagnostic pop #endif static int mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap) { char mem[MG_BUF_LEN]; char *buf = NULL; int len; if ((len = alloc_vprintf(&buf, mem, sizeof(mem), fmt, ap)) > 0) { len = mg_write(conn, buf, (size_t)len); } if ((buf != mem) && (buf != NULL)) { mg_free(buf); } return len; } int mg_printf(struct mg_connection *conn, const char *fmt, ...) { va_list ap; int result; va_start(ap, fmt); result = mg_vprintf(conn, fmt, ap); va_end(ap); return result; } int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, int is_form_url_encoded) { int i, j, a, b; #define HEXTOI(x) (isdigit(x) ? (x - '0') : (x - 'W')) for (i = j = 0; (i < src_len) && (j < (dst_len - 1)); i++, j++) { if ((i < src_len - 2) && (src[i] == '%') && isxdigit((unsigned char)src[i + 1]) && isxdigit((unsigned char)src[i + 2])) { a = tolower((unsigned char)src[i + 1]); b = tolower((unsigned char)src[i + 2]); dst[j] = (char)((HEXTOI(a) << 4) | HEXTOI(b)); i += 2; } else if (is_form_url_encoded && (src[i] == '+')) { dst[j] = ' '; } else { dst[j] = src[i]; } } dst[j] = '\0'; /* Null-terminate the destination */ return (i >= src_len) ? j : -1; } int mg_get_var(const char *data, size_t data_len, const char *name, char *dst, size_t dst_len) { return mg_get_var2(data, data_len, name, dst, dst_len, 0); } int mg_get_var2(const char *data, size_t data_len, const char *name, char *dst, size_t dst_len, size_t occurrence) { const char *p, *e, *s; size_t name_len; int len; if ((dst == NULL) || (dst_len == 0)) { len = -2; } else if ((data == NULL) || (name == NULL) || (data_len == 0)) { len = -1; dst[0] = '\0'; } else { name_len = strlen(name); e = data + data_len; len = -1; dst[0] = '\0'; /* data is "var1=val1&var2=val2...". Find variable first */ for (p = data; p + name_len < e; p++) { if (((p == data) || (p[-1] == '&')) && (p[name_len] == '=') && !mg_strncasecmp(name, p, name_len) && 0 == occurrence--) { /* Point p to variable value */ p += name_len + 1; /* Point s to the end of the value */ s = (const char *)memchr(p, '&', (size_t)(e - p)); if (s == NULL) { s = e; } DEBUG_ASSERT(s >= p); if (s < p) { return -3; } /* Decode variable into destination buffer */ len = mg_url_decode(p, (int)(s - p), dst, (int)dst_len, 1); /* Redirect error code from -1 to -2 (destination buffer too * small). */ if (len == -1) { len = -2; } break; } } } return len; } /* HCP24: some changes to compare hole var_name */ int mg_get_cookie(const char *cookie_header, const char *var_name, char *dst, size_t dst_size) { const char *s, *p, *end; int name_len, len = -1; if ((dst == NULL) || (dst_size == 0)) { return -2; } dst[0] = '\0'; if ((var_name == NULL) || ((s = cookie_header) == NULL)) { return -1; } name_len = (int)strlen(var_name); end = s + strlen(s); for (; (s = mg_strcasestr(s, var_name)) != NULL; s += name_len) { if (s[name_len] == '=') { /* HCP24: now check is it a substring or a full cookie name */ if ((s == cookie_header) || (s[-1] == ' ')) { s += name_len + 1; if ((p = strchr(s, ' ')) == NULL) { p = end; } if (p[-1] == ';') { p--; } if ((*s == '"') && (p[-1] == '"') && (p > s + 1)) { s++; p--; } if ((size_t)(p - s) < dst_size) { len = (int)(p - s); mg_strlcpy(dst, s, (size_t)len + 1); } else { len = -3; } break; } } } return len; } #if defined(USE_WEBSOCKET) || defined(USE_LUA) static void base64_encode(const unsigned char *src, int src_len, char *dst) { static const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; int i, j, a, b, c; for (i = j = 0; i < src_len; i += 3) { a = src[i]; b = ((i + 1) >= src_len) ? 0 : src[i + 1]; c = ((i + 2) >= src_len) ? 0 : src[i + 2]; dst[j++] = b64[a >> 2]; dst[j++] = b64[((a & 3) << 4) | (b >> 4)]; if (i + 1 < src_len) { dst[j++] = b64[(b & 15) << 2 | (c >> 6)]; } if (i + 2 < src_len) { dst[j++] = b64[c & 63]; } } while (j % 4 != 0) { dst[j++] = '='; } dst[j++] = '\0'; } #endif #if defined(USE_LUA) static unsigned char b64reverse(char letter) { if ((letter >= 'A') && (letter <= 'Z')) { return letter - 'A'; } if ((letter >= 'a') && (letter <= 'z')) { return letter - 'a' + 26; } if ((letter >= '0') && (letter <= '9')) { return letter - '0' + 52; } if (letter == '+') { return 62; } if (letter == '/') { return 63; } if (letter == '=') { return 255; /* normal end */ } return 254; /* error */ } static int base64_decode(const unsigned char *src, int src_len, char *dst, size_t *dst_len) { int i; unsigned char a, b, c, d; *dst_len = 0; for (i = 0; i < src_len; i += 4) { a = b64reverse(src[i]); if (a >= 254) { return i; } b = b64reverse(((i + 1) >= src_len) ? 0 : src[i + 1]); if (b >= 254) { return i + 1; } c = b64reverse(((i + 2) >= src_len) ? 0 : src[i + 2]); if (c == 254) { return i + 2; } d = b64reverse(((i + 3) >= src_len) ? 0 : src[i + 3]); if (d == 254) { return i + 3; } dst[(*dst_len)++] = (a << 2) + (b >> 4); if (c != 255) { dst[(*dst_len)++] = (b << 4) + (c >> 2); if (d != 255) { dst[(*dst_len)++] = (c << 6) + d; } } } return -1; } #endif static int is_put_or_delete_method(const struct mg_connection *conn) { if (conn) { const char *s = conn->request_info.request_method; return (s != NULL) && (!strcmp(s, "PUT") || !strcmp(s, "DELETE") || !strcmp(s, "MKCOL") || !strcmp(s, "PATCH")); } return 0; } #if !defined(NO_FILES) static int extention_matches_script( struct mg_connection *conn, /* in: request (must be valid) */ const char *filename /* in: filename (must be valid) */ ) { #if !defined(NO_CGI) if (match_prefix(conn->dom_ctx->config[CGI_EXTENSIONS], strlen(conn->dom_ctx->config[CGI_EXTENSIONS]), filename) > 0) { return 1; } #endif #if defined(USE_LUA) if (match_prefix(conn->dom_ctx->config[LUA_SCRIPT_EXTENSIONS], strlen(conn->dom_ctx->config[LUA_SCRIPT_EXTENSIONS]), filename) > 0) { return 1; } #endif #if defined(USE_DUKTAPE) if (match_prefix(conn->dom_ctx->config[DUKTAPE_SCRIPT_EXTENSIONS], strlen(conn->dom_ctx->config[DUKTAPE_SCRIPT_EXTENSIONS]), filename) > 0) { return 1; } #endif /* filename and conn could be unused, if all preocessor conditions * are false (no script language supported). */ (void)filename; (void)conn; return 0; } /* For given directory path, substitute it to valid index file. * Return 1 if index file has been found, 0 if not found. * If the file is found, it's stats is returned in stp. */ static int substitute_index_file(struct mg_connection *conn, char *path, size_t path_len, struct mg_file_stat *filestat) { const char *list = conn->dom_ctx->config[INDEX_FILES]; struct vec filename_vec; size_t n = strlen(path); int found = 0; /* The 'path' given to us points to the directory. Remove all trailing * directory separator characters from the end of the path, and * then append single directory separator character. */ while ((n > 0) && (path[n - 1] == '/')) { n--; } path[n] = '/'; /* Traverse index files list. For each entry, append it to the given * path and see if the file exists. If it exists, break the loop */ while ((list = next_option(list, &filename_vec, NULL)) != NULL) { /* Ignore too long entries that may overflow path buffer */ if ((filename_vec.len + 1) > (path_len - (n + 1))) { continue; } /* Prepare full path to the index file */ mg_strlcpy(path + n + 1, filename_vec.ptr, filename_vec.len + 1); /* Does it exist? */ if (mg_stat(conn, path, filestat)) { /* Yes it does, break the loop */ found = 1; break; } } /* If no index file exists, restore directory path */ if (!found) { path[n] = '\0'; } return found; } #endif static void interpret_uri(struct mg_connection *conn, /* in/out: request (must be valid) */ char *filename, /* out: filename */ size_t filename_buf_len, /* in: size of filename buffer */ struct mg_file_stat *filestat, /* out: file status structure */ int *is_found, /* out: file found (directly) */ int *is_script_resource, /* out: handled by a script? */ int *is_websocket_request, /* out: websocket connetion? */ int *is_put_or_delete_request /* out: put/delete a file? */ ) { char const *accept_encoding; #if !defined(NO_FILES) const char *uri = conn->request_info.local_uri; const char *root = conn->dom_ctx->config[DOCUMENT_ROOT]; const char *rewrite; struct vec a, b; ptrdiff_t match_len; char gz_path[PATH_MAX]; int truncated; #if !defined(NO_CGI) || defined(USE_LUA) || defined(USE_DUKTAPE) char *tmp_str; size_t tmp_str_len, sep_pos; int allow_substitute_script_subresources; #endif #else (void)filename_buf_len; /* unused if NO_FILES is defined */ #endif /* Step 1: Set all initially unknown outputs to zero */ memset(filestat, 0, sizeof(*filestat)); *filename = 0; *is_found = 0; *is_script_resource = 0; /* Step 2: Check if the request attempts to modify the file system */ *is_put_or_delete_request = is_put_or_delete_method(conn); /* Step 3: Check if it is a websocket request, and modify the document * root if required */ #if defined(USE_WEBSOCKET) *is_websocket_request = is_websocket_protocol(conn); #if !defined(NO_FILES) if (*is_websocket_request && conn->dom_ctx->config[WEBSOCKET_ROOT]) { root = conn->dom_ctx->config[WEBSOCKET_ROOT]; } #endif /* !NO_FILES */ #else /* USE_WEBSOCKET */ *is_websocket_request = 0; #endif /* USE_WEBSOCKET */ /* Step 4: Check if gzip encoded response is allowed */ conn->accept_gzip = 0; if ((accept_encoding = mg_get_header(conn, "Accept-Encoding")) != NULL) { if (strstr(accept_encoding, "gzip") != NULL) { conn->accept_gzip = 1; } } #if !defined(NO_FILES) /* Step 5: If there is no root directory, don't look for files. */ /* Note that root == NULL is a regular use case here. This occurs, * if all requests are handled by callbacks, so the WEBSOCKET_ROOT * config is not required. */ if (root == NULL) { /* all file related outputs have already been set to 0, just return */ return; } /* Step 6: Determine the local file path from the root path and the * request uri. */ /* Using filename_buf_len - 1 because memmove() for PATH_INFO may shift * part of the path one byte on the right. */ mg_snprintf( conn, &truncated, filename, filename_buf_len - 1, "%s%s", root, uri); if (truncated) { goto interpret_cleanup; } /* Step 7: URI rewriting */ rewrite = conn->dom_ctx->config[URL_REWRITE_PATTERN]; while ((rewrite = next_option(rewrite, &a, &b)) != NULL) { if ((match_len = match_prefix(a.ptr, a.len, uri)) > 0) { mg_snprintf(conn, &truncated, filename, filename_buf_len - 1, "%.*s%s", (int)b.len, b.ptr, uri + match_len); break; } } if (truncated) { goto interpret_cleanup; } /* Step 8: Check if the file exists at the server */ /* Local file path and name, corresponding to requested URI * is now stored in "filename" variable. */ if (mg_stat(conn, filename, filestat)) { int uri_len = (int)strlen(uri); int is_uri_end_slash = (uri_len > 0) && (uri[uri_len - 1] == '/'); /* 8.1: File exists. */ *is_found = 1; /* 8.2: Check if it is a script type. */ if (extention_matches_script(conn, filename)) { /* The request addresses a CGI resource, Lua script or * server-side javascript. * The URI corresponds to the script itself (like * /path/script.cgi), and there is no additional resource * path (like /path/script.cgi/something). * Requests that modify (replace or delete) a resource, like * PUT and DELETE requests, should replace/delete the script * file. * Requests that read or write from/to a resource, like GET and * POST requests, should call the script and return the * generated response. */ *is_script_resource = (!*is_put_or_delete_request); } /* 8.3: If the request target is a directory, there could be * a substitute file (index.html, index.cgi, ...). */ if (filestat->is_directory && is_uri_end_slash) { /* Use a local copy here, since substitute_index_file will * change the content of the file status */ struct mg_file_stat tmp_filestat; memset(&tmp_filestat, 0, sizeof(tmp_filestat)); if (substitute_index_file( conn, filename, filename_buf_len, &tmp_filestat)) { /* Substitute file found. Copy stat to the output, then * check if the file is a script file */ *filestat = tmp_filestat; if (extention_matches_script(conn, filename)) { /* Substitute file is a script file */ *is_script_resource = 1; } else { /* Substitute file is a regular file */ *is_script_resource = 0; *is_found = (mg_stat(conn, filename, filestat) ? 1 : 0); } } /* If there is no substitute file, the server could return * a directory listing in a later step */ } return; } /* Step 9: Check for zipped files: */ /* If we can't find the actual file, look for the file * with the same name but a .gz extension. If we find it, * use that and set the gzipped flag in the file struct * to indicate that the response need to have the content- * encoding: gzip header. * We can only do this if the browser declares support. */ if (conn->accept_gzip) { mg_snprintf( conn, &truncated, gz_path, sizeof(gz_path), "%s.gz", filename); if (truncated) { goto interpret_cleanup; } if (mg_stat(conn, gz_path, filestat)) { if (filestat) { filestat->is_gzipped = 1; *is_found = 1; } /* Currently gz files can not be scripts. */ return; } } #if !defined(NO_CGI) || defined(USE_LUA) || defined(USE_DUKTAPE) /* Step 10: Script resources may handle sub-resources */ /* Support PATH_INFO for CGI scripts. */ tmp_str_len = strlen(filename); tmp_str = (char *)mg_malloc_ctx(tmp_str_len + PATH_MAX + 1, conn->phys_ctx); if (!tmp_str) { /* Out of memory */ goto interpret_cleanup; } memcpy(tmp_str, filename, tmp_str_len + 1); /* Check config, if index scripts may have sub-resources */ allow_substitute_script_subresources = !mg_strcasecmp(conn->dom_ctx->config[ALLOW_INDEX_SCRIPT_SUB_RES], "yes"); sep_pos = tmp_str_len; while (sep_pos > 0) { sep_pos--; if (tmp_str[sep_pos] == '/') { int is_script = 0, does_exist = 0; tmp_str[sep_pos] = 0; if (tmp_str[0]) { is_script = extention_matches_script(conn, tmp_str); does_exist = mg_stat(conn, tmp_str, filestat); } if (does_exist && is_script) { filename[sep_pos] = 0; memmove(filename + sep_pos + 2, filename + sep_pos + 1, strlen(filename + sep_pos + 1) + 1); conn->path_info = filename + sep_pos + 1; filename[sep_pos + 1] = '/'; *is_script_resource = 1; *is_found = 1; break; } if (allow_substitute_script_subresources) { if (substitute_index_file( conn, tmp_str, tmp_str_len + PATH_MAX, filestat)) { /* some intermediate directory has an index file */ if (extention_matches_script(conn, tmp_str)) { char *tmp_str2; DEBUG_TRACE("Substitute script %s serving path %s", tmp_str, filename); /* this index file is a script */ tmp_str2 = mg_strdup_ctx(filename + sep_pos + 1, conn->phys_ctx); mg_snprintf(conn, &truncated, filename, filename_buf_len, "%s//%s", tmp_str, tmp_str2); mg_free(tmp_str2); if (truncated) { mg_free(tmp_str); goto interpret_cleanup; } sep_pos = strlen(tmp_str); filename[sep_pos] = 0; conn->path_info = filename + sep_pos + 1; *is_script_resource = 1; *is_found = 1; break; } else { DEBUG_TRACE("Substitute file %s serving path %s", tmp_str, filename); /* non-script files will not have sub-resources */ filename[sep_pos] = 0; conn->path_info = 0; *is_script_resource = 0; *is_found = 0; break; } } } tmp_str[sep_pos] = '/'; } } mg_free(tmp_str); #endif /* !defined(NO_CGI) || defined(USE_LUA) || defined(USE_DUKTAPE) */ #endif /* !defined(NO_FILES) */ return; #if !defined(NO_FILES) /* Reset all outputs */ interpret_cleanup: memset(filestat, 0, sizeof(*filestat)); *filename = 0; *is_found = 0; *is_script_resource = 0; *is_websocket_request = 0; *is_put_or_delete_request = 0; #endif /* !defined(NO_FILES) */ } /* Check whether full request is buffered. Return: * -1 if request or response is malformed * 0 if request or response is not yet fully buffered * >0 actual request length, including last \r\n\r\n */ static int get_http_header_len(const char *buf, int buflen) { int i; for (i = 0; i < buflen; i++) { /* Do an unsigned comparison in some conditions below */ const unsigned char c = (unsigned char)buf[i]; if ((c < 128) && ((char)c != '\r') && ((char)c != '\n') && !isprint(c)) { /* abort scan as soon as one malformed character is found */ return -1; } if (i < buflen - 1) { if ((buf[i] == '\n') && (buf[i + 1] == '\n')) { /* Two newline, no carriage return - not standard compliant, * but * it * should be accepted */ return i + 2; } } if (i < buflen - 3) { if ((buf[i] == '\r') && (buf[i + 1] == '\n') && (buf[i + 2] == '\r') && (buf[i + 3] == '\n')) { /* Two \r\n - standard compliant */ return i + 4; } } } return 0; } #if !defined(NO_CACHING) /* Convert month to the month number. Return -1 on error, or month number */ static int get_month_index(const char *s) { size_t i; for (i = 0; i < ARRAY_SIZE(month_names); i++) { if (!strcmp(s, month_names[i])) { return (int)i; } } return -1; } /* Parse UTC date-time string, and return the corresponding time_t value. */ static time_t parse_date_string(const char *datetime) { char month_str[32] = {0}; int second, minute, hour, day, month, year; time_t result = (time_t)0; struct tm tm; if ((sscanf(datetime, "%d/%3s/%d %d:%d:%d", &day, month_str, &year, &hour, &minute, &second) == 6) || (sscanf(datetime, "%d %3s %d %d:%d:%d", &day, month_str, &year, &hour, &minute, &second) == 6) || (sscanf(datetime, "%*3s, %d %3s %d %d:%d:%d", &day, month_str, &year, &hour, &minute, &second) == 6) || (sscanf(datetime, "%d-%3s-%d %d:%d:%d", &day, month_str, &year, &hour, &minute, &second) == 6)) { month = get_month_index(month_str); if ((month >= 0) && (year >= 1970)) { memset(&tm, 0, sizeof(tm)); tm.tm_year = year - 1900; tm.tm_mon = month; tm.tm_mday = day; tm.tm_hour = hour; tm.tm_min = minute; tm.tm_sec = second; result = timegm(&tm); } } return result; } #endif /* !NO_CACHING */ /* Protect against directory disclosure attack by removing '..', * excessive '/' and '\' characters */ static void remove_double_dots_and_double_slashes(char *s) { char *p = s; while ((s[0] == '.') && (s[1] == '.')) { s++; } while (*s != '\0') { *p++ = *s++; if ((s[-1] == '/') || (s[-1] == '\\')) { /* Skip all following slashes, backslashes and double-dots */ while (s[0] != '\0') { if ((s[0] == '/') || (s[0] == '\\')) { s++; } else if ((s[0] == '.') && (s[1] == '.')) { s += 2; } else { break; } } } } *p = '\0'; } static const struct { const char *extension; size_t ext_len; const char *mime_type; } builtin_mime_types[] = { /* IANA registered MIME types * (http://www.iana.org/assignments/media-types) * application types */ {".doc", 4, "application/msword"}, {".eps", 4, "application/postscript"}, {".exe", 4, "application/octet-stream"}, {".js", 3, "application/javascript"}, {".json", 5, "application/json"}, {".pdf", 4, "application/pdf"}, {".ps", 3, "application/postscript"}, {".rtf", 4, "application/rtf"}, {".xhtml", 6, "application/xhtml+xml"}, {".xsl", 4, "application/xml"}, {".xslt", 5, "application/xml"}, /* fonts */ {".ttf", 4, "application/font-sfnt"}, {".cff", 4, "application/font-sfnt"}, {".otf", 4, "application/font-sfnt"}, {".aat", 4, "application/font-sfnt"}, {".sil", 4, "application/font-sfnt"}, {".pfr", 4, "application/font-tdpfr"}, {".woff", 5, "application/font-woff"}, /* audio */ {".mp3", 4, "audio/mpeg"}, {".oga", 4, "audio/ogg"}, {".ogg", 4, "audio/ogg"}, /* image */ {".gif", 4, "image/gif"}, {".ief", 4, "image/ief"}, {".jpeg", 5, "image/jpeg"}, {".jpg", 4, "image/jpeg"}, {".jpm", 4, "image/jpm"}, {".jpx", 4, "image/jpx"}, {".png", 4, "image/png"}, {".svg", 4, "image/svg+xml"}, {".tif", 4, "image/tiff"}, {".tiff", 5, "image/tiff"}, /* model */ {".wrl", 4, "model/vrml"}, /* text */ {".css", 4, "text/css"}, {".csv", 4, "text/csv"}, {".htm", 4, "text/html"}, {".html", 5, "text/html"}, {".sgm", 4, "text/sgml"}, {".shtm", 5, "text/html"}, {".shtml", 6, "text/html"}, {".txt", 4, "text/plain"}, {".xml", 4, "text/xml"}, /* video */ {".mov", 4, "video/quicktime"}, {".mp4", 4, "video/mp4"}, {".mpeg", 5, "video/mpeg"}, {".mpg", 4, "video/mpeg"}, {".ogv", 4, "video/ogg"}, {".qt", 3, "video/quicktime"}, /* not registered types * (http://reference.sitepoint.com/html/mime-types-full, * http://www.hansenb.pdx.edu/DMKB/dict/tutorials/mime_typ.php, ..) */ {".arj", 4, "application/x-arj-compressed"}, {".gz", 3, "application/x-gunzip"}, {".rar", 4, "application/x-arj-compressed"}, {".swf", 4, "application/x-shockwave-flash"}, {".tar", 4, "application/x-tar"}, {".tgz", 4, "application/x-tar-gz"}, {".torrent", 8, "application/x-bittorrent"}, {".ppt", 4, "application/x-mspowerpoint"}, {".xls", 4, "application/x-msexcel"}, {".zip", 4, "application/x-zip-compressed"}, {".aac", 4, "audio/aac"}, /* http://en.wikipedia.org/wiki/Advanced_Audio_Coding */ {".aif", 4, "audio/x-aif"}, {".m3u", 4, "audio/x-mpegurl"}, {".mid", 4, "audio/x-midi"}, {".ra", 3, "audio/x-pn-realaudio"}, {".ram", 4, "audio/x-pn-realaudio"}, {".wav", 4, "audio/x-wav"}, {".bmp", 4, "image/bmp"}, {".ico", 4, "image/x-icon"}, {".pct", 4, "image/x-pct"}, {".pict", 5, "image/pict"}, {".rgb", 4, "image/x-rgb"}, {".webm", 5, "video/webm"}, /* http://en.wikipedia.org/wiki/WebM */ {".asf", 4, "video/x-ms-asf"}, {".avi", 4, "video/x-msvideo"}, {".m4v", 4, "video/x-m4v"}, {NULL, 0, NULL}}; const char * mg_get_builtin_mime_type(const char *path) { const char *ext; size_t i, path_len; path_len = strlen(path); for (i = 0; builtin_mime_types[i].extension != NULL; i++) { ext = path + (path_len - builtin_mime_types[i].ext_len); if ((path_len > builtin_mime_types[i].ext_len) && (mg_strcasecmp(ext, builtin_mime_types[i].extension) == 0)) { return builtin_mime_types[i].mime_type; } } return "text/plain"; } /* Look at the "path" extension and figure what mime type it has. * Store mime type in the vector. */ static void get_mime_type(struct mg_connection *conn, const char *path, struct vec *vec) { struct vec ext_vec, mime_vec; const char *list, *ext; size_t path_len; path_len = strlen(path); if ((conn == NULL) || (vec == NULL)) { if (vec != NULL) { memset(vec, '\0', sizeof(struct vec)); } return; } /* Scan user-defined mime types first, in case user wants to * override default mime types. */ list = conn->dom_ctx->config[EXTRA_MIME_TYPES]; while ((list = next_option(list, &ext_vec, &mime_vec)) != NULL) { /* ext now points to the path suffix */ ext = path + path_len - ext_vec.len; if (mg_strncasecmp(ext, ext_vec.ptr, ext_vec.len) == 0) { *vec = mime_vec; return; } } vec->ptr = mg_get_builtin_mime_type(path); vec->len = strlen(vec->ptr); } /* Stringify binary data. Output buffer must be twice as big as input, * because each byte takes 2 bytes in string representation */ static void bin2str(char *to, const unsigned char *p, size_t len) { static const char *hex = "0123456789abcdef"; for (; len--; p++) { *to++ = hex[p[0] >> 4]; *to++ = hex[p[0] & 0x0f]; } *to = '\0'; } /* Return stringified MD5 hash for list of strings. Buffer must be 33 bytes. */ char * mg_md5(char buf[33], ...) { md5_byte_t hash[16]; const char *p; va_list ap; md5_state_t ctx; md5_init(&ctx); va_start(ap, buf); while ((p = va_arg(ap, const char *)) != NULL) { md5_append(&ctx, (const md5_byte_t *)p, strlen(p)); } va_end(ap); md5_finish(&ctx, hash); bin2str(buf, hash, sizeof(hash)); return buf; } /* Check the user's password, return 1 if OK */ static int check_password(const char *method, const char *ha1, const char *uri, const char *nonce, const char *nc, const char *cnonce, const char *qop, const char *response) { char ha2[32 + 1], expected_response[32 + 1]; /* Some of the parameters may be NULL */ if ((method == NULL) || (nonce == NULL) || (nc == NULL) || (cnonce == NULL) || (qop == NULL) || (response == NULL)) { return 0; } /* NOTE(lsm): due to a bug in MSIE, we do not compare the URI */ if (strlen(response) != 32) { return 0; } mg_md5(ha2, method, ":", uri, NULL); mg_md5(expected_response, ha1, ":", nonce, ":", nc, ":", cnonce, ":", qop, ":", ha2, NULL); return mg_strcasecmp(response, expected_response) == 0; } /* Use the global passwords file, if specified by auth_gpass option, * or search for .htpasswd in the requested directory. */ static void open_auth_file(struct mg_connection *conn, const char *path, struct mg_file *filep) { if ((conn != NULL) && (conn->dom_ctx != NULL)) { char name[PATH_MAX]; const char *p, *e, *gpass = conn->dom_ctx->config[GLOBAL_PASSWORDS_FILE]; int truncated; if (gpass != NULL) { /* Use global passwords file */ if (!mg_fopen(conn, gpass, MG_FOPEN_MODE_READ, filep)) { #if defined(DEBUG) /* Use mg_cry_internal here, since gpass has been configured. */ mg_cry_internal(conn, "fopen(%s): %s", gpass, strerror(ERRNO)); #endif } /* Important: using local struct mg_file to test path for * is_directory flag. If filep is used, mg_stat() makes it * appear as if auth file was opened. * TODO(mid): Check if this is still required after rewriting * mg_stat */ } else if (mg_stat(conn, path, &filep->stat) && filep->stat.is_directory) { mg_snprintf(conn, &truncated, name, sizeof(name), "%s/%s", path, PASSWORDS_FILE_NAME); if (truncated || !mg_fopen(conn, name, MG_FOPEN_MODE_READ, filep)) { #if defined(DEBUG) /* Don't use mg_cry_internal here, but only a trace, since this * is * a typical case. It will occur for every directory * without a password file. */ DEBUG_TRACE("fopen(%s): %s", name, strerror(ERRNO)); #endif } } else { /* Try to find .htpasswd in requested directory. */ for (p = path, e = p + strlen(p) - 1; e > p; e--) { if (e[0] == '/') { break; } } mg_snprintf(conn, &truncated, name, sizeof(name), "%.*s/%s", (int)(e - p), p, PASSWORDS_FILE_NAME); if (truncated || !mg_fopen(conn, name, MG_FOPEN_MODE_READ, filep)) { #if defined(DEBUG) /* Don't use mg_cry_internal here, but only a trace, since this * is * a typical case. It will occur for every directory * without a password file. */ DEBUG_TRACE("fopen(%s): %s", name, strerror(ERRNO)); #endif } } } } /* Parsed Authorization header */ struct ah { char *user, *uri, *cnonce, *response, *qop, *nc, *nonce; }; /* Return 1 on success. Always initializes the ah structure. */ static int parse_auth_header(struct mg_connection *conn, char *buf, size_t buf_size, struct ah *ah) { char *name, *value, *s; const char *auth_header; uint64_t nonce; if (!ah || !conn) { return 0; } (void)memset(ah, 0, sizeof(*ah)); if (((auth_header = mg_get_header(conn, "Authorization")) == NULL) || mg_strncasecmp(auth_header, "Digest ", 7) != 0) { return 0; } /* Make modifiable copy of the auth header */ (void)mg_strlcpy(buf, auth_header + 7, buf_size); s = buf; /* Parse authorization header */ for (;;) { /* Gobble initial spaces */ while (isspace((unsigned char)*s)) { s++; } name = skip_quoted(&s, "=", " ", 0); /* Value is either quote-delimited, or ends at first comma or space. */ if (s[0] == '\"') { s++; value = skip_quoted(&s, "\"", " ", '\\'); if (s[0] == ',') { s++; } } else { value = skip_quoted(&s, ", ", " ", 0); /* IE uses commas, FF uses * spaces */ } if (*name == '\0') { break; } if (!strcmp(name, "username")) { ah->user = value; } else if (!strcmp(name, "cnonce")) { ah->cnonce = value; } else if (!strcmp(name, "response")) { ah->response = value; } else if (!strcmp(name, "uri")) { ah->uri = value; } else if (!strcmp(name, "qop")) { ah->qop = value; } else if (!strcmp(name, "nc")) { ah->nc = value; } else if (!strcmp(name, "nonce")) { ah->nonce = value; } } #if !defined(NO_NONCE_CHECK) /* Read the nonce from the response. */ if (ah->nonce == NULL) { return 0; } s = NULL; nonce = strtoull(ah->nonce, &s, 10); if ((s == NULL) || (*s != 0)) { return 0; } /* Convert the nonce from the client to a number. */ nonce ^= conn->dom_ctx->auth_nonce_mask; /* The converted number corresponds to the time the nounce has been * created. This should not be earlier than the server start. */ /* Server side nonce check is valuable in all situations but one: * if the server restarts frequently, but the client should not see * that, so the server should accept nonces from previous starts. */ /* However, the reasonable default is to not accept a nonce from a * previous start, so if anyone changed the access rights between * two restarts, a new login is required. */ if (nonce < (uint64_t)conn->phys_ctx->start_time) { /* nonce is from a previous start of the server and no longer valid * (replay attack?) */ return 0; } /* Check if the nonce is too high, so it has not (yet) been used by the * server. */ if (nonce >= ((uint64_t)conn->phys_ctx->start_time + conn->dom_ctx->nonce_count)) { return 0; } #else (void)nonce; #endif /* CGI needs it as REMOTE_USER */ if (ah->user != NULL) { conn->request_info.remote_user = mg_strdup_ctx(ah->user, conn->phys_ctx); } else { return 0; } return 1; } static const char * mg_fgets(char *buf, size_t size, struct mg_file *filep, char **p) { #if defined(MG_USE_OPEN_FILE) const char *eof; size_t len; const char *memend; #else (void)p; /* parameter is unused */ #endif if (!filep) { return NULL; } #if defined(MG_USE_OPEN_FILE) if ((filep->access.membuf != NULL) && (*p != NULL)) { memend = (const char *)&filep->access.membuf[filep->stat.size]; /* Search for \n from p till the end of stream */ eof = (char *)memchr(*p, '\n', (size_t)(memend - *p)); if (eof != NULL) { eof += 1; /* Include \n */ } else { eof = memend; /* Copy remaining data */ } len = ((size_t)(eof - *p) > (size - 1)) ? (size - 1) : (size_t)(eof - *p); memcpy(buf, *p, len); buf[len] = '\0'; *p += len; return len ? eof : NULL; } else /* filep->access.fp block below */ #endif if (filep->access.fp != NULL) { return fgets(buf, (int)size, filep->access.fp); } else { return NULL; } } /* Define the initial recursion depth for procesesing htpasswd files that * include other htpasswd * (or even the same) files. It is not difficult to provide a file or files * s.t. they force civetweb * to infinitely recurse and then crash. */ #define INITIAL_DEPTH 9 #if INITIAL_DEPTH <= 0 #error Bad INITIAL_DEPTH for recursion, set to at least 1 #endif struct read_auth_file_struct { struct mg_connection *conn; struct ah ah; const char *domain; char buf[256 + 256 + 40]; const char *f_user; const char *f_domain; const char *f_ha1; }; static int read_auth_file(struct mg_file *filep, struct read_auth_file_struct *workdata, int depth) { char *p = NULL /* init if MG_USE_OPEN_FILE is not set */; int is_authorized = 0; struct mg_file fp; size_t l; if (!filep || !workdata || (0 == depth)) { return 0; } /* Loop over passwords file */ #if defined(MG_USE_OPEN_FILE) p = (char *)filep->access.membuf; #endif while (mg_fgets(workdata->buf, sizeof(workdata->buf), filep, &p) != NULL) { l = strlen(workdata->buf); while (l > 0) { if (isspace((unsigned char)workdata->buf[l - 1]) || iscntrl((unsigned char)workdata->buf[l - 1])) { l--; workdata->buf[l] = 0; } else break; } if (l < 1) { continue; } workdata->f_user = workdata->buf; if (workdata->f_user[0] == ':') { /* user names may not contain a ':' and may not be empty, * so lines starting with ':' may be used for a special purpose */ if (workdata->f_user[1] == '#') { /* :# is a comment */ continue; } else if (!strncmp(workdata->f_user + 1, "include=", 8)) { if (mg_fopen(workdata->conn, workdata->f_user + 9, MG_FOPEN_MODE_READ, &fp)) { is_authorized = read_auth_file(&fp, workdata, depth - 1); (void)mg_fclose( &fp.access); /* ignore error on read only file */ /* No need to continue processing files once we have a * match, since nothing will reset it back * to 0. */ if (is_authorized) { return is_authorized; } } else { mg_cry_internal(workdata->conn, "%s: cannot open authorization file: %s", __func__, workdata->buf); } continue; } /* everything is invalid for the moment (might change in the * future) */ mg_cry_internal(workdata->conn, "%s: syntax error in authorization file: %s", __func__, workdata->buf); continue; } workdata->f_domain = strchr(workdata->f_user, ':'); if (workdata->f_domain == NULL) { mg_cry_internal(workdata->conn, "%s: syntax error in authorization file: %s", __func__, workdata->buf); continue; } *(char *)(workdata->f_domain) = 0; (workdata->f_domain)++; workdata->f_ha1 = strchr(workdata->f_domain, ':'); if (workdata->f_ha1 == NULL) { mg_cry_internal(workdata->conn, "%s: syntax error in authorization file: %s", __func__, workdata->buf); continue; } *(char *)(workdata->f_ha1) = 0; (workdata->f_ha1)++; if (!strcmp(workdata->ah.user, workdata->f_user) && !strcmp(workdata->domain, workdata->f_domain)) { return check_password(workdata->conn->request_info.request_method, workdata->f_ha1, workdata->ah.uri, workdata->ah.nonce, workdata->ah.nc, workdata->ah.cnonce, workdata->ah.qop, workdata->ah.response); } } return is_authorized; } /* Authorize against the opened passwords file. Return 1 if authorized. */ static int authorize(struct mg_connection *conn, struct mg_file *filep, const char *realm) { struct read_auth_file_struct workdata; char buf[MG_BUF_LEN]; if (!conn || !conn->dom_ctx) { return 0; } memset(&workdata, 0, sizeof(workdata)); workdata.conn = conn; if (!parse_auth_header(conn, buf, sizeof(buf), &workdata.ah)) { return 0; } if (realm) { workdata.domain = realm; } else { workdata.domain = conn->dom_ctx->config[AUTHENTICATION_DOMAIN]; } return read_auth_file(filep, &workdata, INITIAL_DEPTH); } /* Public function to check http digest authentication header */ int mg_check_digest_access_authentication(struct mg_connection *conn, const char *realm, const char *filename) { struct mg_file file = STRUCT_FILE_INITIALIZER; int auth; if (!conn || !filename) { return -1; } if (!mg_fopen(conn, filename, MG_FOPEN_MODE_READ, &file)) { return -2; } auth = authorize(conn, &file, realm); mg_fclose(&file.access); return auth; } /* Return 1 if request is authorised, 0 otherwise. */ static int check_authorization(struct mg_connection *conn, const char *path) { char fname[PATH_MAX]; struct vec uri_vec, filename_vec; const char *list; struct mg_file file = STRUCT_FILE_INITIALIZER; int authorized = 1, truncated; if (!conn || !conn->dom_ctx) { return 0; } list = conn->dom_ctx->config[PROTECT_URI]; while ((list = next_option(list, &uri_vec, &filename_vec)) != NULL) { if (!memcmp(conn->request_info.local_uri, uri_vec.ptr, uri_vec.len)) { mg_snprintf(conn, &truncated, fname, sizeof(fname), "%.*s", (int)filename_vec.len, filename_vec.ptr); if (truncated || !mg_fopen(conn, fname, MG_FOPEN_MODE_READ, &file)) { mg_cry_internal(conn, "%s: cannot open %s: %s", __func__, fname, strerror(errno)); } break; } } if (!is_file_opened(&file.access)) { open_auth_file(conn, path, &file); } if (is_file_opened(&file.access)) { authorized = authorize(conn, &file, NULL); (void)mg_fclose(&file.access); /* ignore error on read only file */ } return authorized; } /* Internal function. Assumes conn is valid */ static void send_authorization_request(struct mg_connection *conn, const char *realm) { char date[64]; time_t curtime = time(NULL); uint64_t nonce = (uint64_t)(conn->phys_ctx->start_time); if (!realm) { realm = conn->dom_ctx->config[AUTHENTICATION_DOMAIN]; } (void)pthread_mutex_lock(&conn->phys_ctx->nonce_mutex); nonce += conn->dom_ctx->nonce_count; ++conn->dom_ctx->nonce_count; (void)pthread_mutex_unlock(&conn->phys_ctx->nonce_mutex); nonce ^= conn->dom_ctx->auth_nonce_mask; conn->status_code = 401; conn->must_close = 1; gmt_time_string(date, sizeof(date), &curtime); mg_printf(conn, "HTTP/1.1 401 Unauthorized\r\n"); send_no_cache_header(conn); send_additional_header(conn); mg_printf(conn, "Date: %s\r\n" "Connection: %s\r\n" "Content-Length: 0\r\n" "WWW-Authenticate: Digest qop=\"auth\", realm=\"%s\", " "nonce=\"%" UINT64_FMT "\"\r\n\r\n", date, suggest_connection_header(conn), realm, nonce); } /* Interface function. Parameters are provided by the user, so do * at least some basic checks. */ int mg_send_digest_access_authentication_request(struct mg_connection *conn, const char *realm) { if (conn && conn->dom_ctx) { send_authorization_request(conn, realm); return 0; } return -1; } #if !defined(NO_FILES) static int is_authorized_for_put(struct mg_connection *conn) { if (conn) { struct mg_file file = STRUCT_FILE_INITIALIZER; const char *passfile = conn->dom_ctx->config[PUT_DELETE_PASSWORDS_FILE]; int ret = 0; if (passfile != NULL && mg_fopen(conn, passfile, MG_FOPEN_MODE_READ, &file)) { ret = authorize(conn, &file, NULL); (void)mg_fclose(&file.access); /* ignore error on read only file */ } return ret; } return 0; } #endif int mg_modify_passwords_file(const char *fname, const char *domain, const char *user, const char *pass) { int found, i; char line[512], u[512] = "", d[512] = "", ha1[33], tmp[PATH_MAX + 8]; FILE *fp, *fp2; found = 0; fp = fp2 = NULL; /* Regard empty password as no password - remove user record. */ if ((pass != NULL) && (pass[0] == '\0')) { pass = NULL; } /* Other arguments must not be empty */ if ((fname == NULL) || (domain == NULL) || (user == NULL)) { return 0; } /* Using the given file format, user name and domain must not contain * ':' */ if (strchr(user, ':') != NULL) { return 0; } if (strchr(domain, ':') != NULL) { return 0; } /* Do not allow control characters like newline in user name and domain. * Do not allow excessively long names either. */ for (i = 0; ((i < 255) && (user[i] != 0)); i++) { if (iscntrl((unsigned char)user[i])) { return 0; } } if (user[i]) { return 0; } for (i = 0; ((i < 255) && (domain[i] != 0)); i++) { if (iscntrl((unsigned char)domain[i])) { return 0; } } if (domain[i]) { return 0; } /* The maximum length of the path to the password file is limited */ if ((strlen(fname) + 4) >= PATH_MAX) { return 0; } /* Create a temporary file name. Length has been checked before. */ strcpy(tmp, fname); strcat(tmp, ".tmp"); /* Create the file if does not exist */ /* Use of fopen here is OK, since fname is only ASCII */ if ((fp = fopen(fname, "a+")) != NULL) { (void)fclose(fp); } /* Open the given file and temporary file */ if ((fp = fopen(fname, "r")) == NULL) { return 0; } else if ((fp2 = fopen(tmp, "w+")) == NULL) { fclose(fp); return 0; } /* Copy the stuff to temporary file */ while (fgets(line, sizeof(line), fp) != NULL) { if (sscanf(line, "%255[^:]:%255[^:]:%*s", u, d) != 2) { continue; } u[255] = 0; d[255] = 0; if (!strcmp(u, user) && !strcmp(d, domain)) { found++; if (pass != NULL) { mg_md5(ha1, user, ":", domain, ":", pass, NULL); fprintf(fp2, "%s:%s:%s\n", user, domain, ha1); } } else { fprintf(fp2, "%s", line); } } /* If new user, just add it */ if (!found && (pass != NULL)) { mg_md5(ha1, user, ":", domain, ":", pass, NULL); fprintf(fp2, "%s:%s:%s\n", user, domain, ha1); } /* Close files */ fclose(fp); fclose(fp2); /* Put the temp file in place of real file */ IGNORE_UNUSED_RESULT(remove(fname)); IGNORE_UNUSED_RESULT(rename(tmp, fname)); return 1; } static int is_valid_port(unsigned long port) { return (port <= 0xffff); } static int mg_inet_pton(int af, const char *src, void *dst, size_t dstlen) { struct addrinfo hints, *res, *ressave; int func_ret = 0; int gai_ret; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = af; gai_ret = getaddrinfo(src, NULL, &hints, &res); if (gai_ret != 0) { /* gai_strerror could be used to convert gai_ret to a string */ /* POSIX return values: see * http://pubs.opengroup.org/onlinepubs/9699919799/functions/freeaddrinfo.html */ /* Windows return values: see * https://msdn.microsoft.com/en-us/library/windows/desktop/ms738520%28v=vs.85%29.aspx */ return 0; } ressave = res; while (res) { if (dstlen >= (size_t)res->ai_addrlen) { memcpy(dst, res->ai_addr, res->ai_addrlen); func_ret = 1; } res = res->ai_next; } freeaddrinfo(ressave); return func_ret; } static int connect_socket(struct mg_context *ctx /* may be NULL */, const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len, SOCKET *sock /* output: socket, must not be NULL */, union usa *sa /* output: socket address, must not be NULL */ ) { int ip_ver = 0; int conn_ret = -1; int ret; *sock = INVALID_SOCKET; memset(sa, 0, sizeof(*sa)); if (ebuf_len > 0) { *ebuf = 0; } if (host == NULL) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "NULL host"); return 0; } if ((port <= 0) || !is_valid_port((unsigned)port)) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "invalid port"); return 0; } #if !defined(NO_SSL) #if !defined(NO_SSL_DL) #if defined(OPENSSL_API_1_1) if (use_ssl && (TLS_client_method == NULL)) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "SSL is not initialized"); return 0; } #else if (use_ssl && (SSLv23_client_method == NULL)) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "SSL is not initialized"); return 0; } #endif /* OPENSSL_API_1_1 */ #else (void)use_ssl; #endif /* NO_SSL_DL */ #else (void)use_ssl; #endif /* !defined(NO_SSL) */ if (mg_inet_pton(AF_INET, host, &sa->sin, sizeof(sa->sin))) { sa->sin.sin_family = AF_INET; sa->sin.sin_port = htons((uint16_t)port); ip_ver = 4; #if defined(USE_IPV6) } else if (mg_inet_pton(AF_INET6, host, &sa->sin6, sizeof(sa->sin6))) { sa->sin6.sin6_family = AF_INET6; sa->sin6.sin6_port = htons((uint16_t)port); ip_ver = 6; } else if (host[0] == '[') { /* While getaddrinfo on Windows will work with [::1], * getaddrinfo on Linux only works with ::1 (without []). */ size_t l = strlen(host + 1); char *h = (l > 1) ? mg_strdup_ctx(host + 1, ctx) : NULL; if (h) { h[l - 1] = 0; if (mg_inet_pton(AF_INET6, h, &sa->sin6, sizeof(sa->sin6))) { sa->sin6.sin6_family = AF_INET6; sa->sin6.sin6_port = htons((uint16_t)port); ip_ver = 6; } mg_free(h); } #endif } if (ip_ver == 0) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "host not found"); return 0; } if (ip_ver == 4) { *sock = socket(PF_INET, SOCK_STREAM, 0); } #if defined(USE_IPV6) else if (ip_ver == 6) { *sock = socket(PF_INET6, SOCK_STREAM, 0); } #endif if (*sock == INVALID_SOCKET) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "socket(): %s", strerror(ERRNO)); return 0; } if (0 != set_non_blocking_mode(*sock)) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "Cannot set socket to non-blocking: %s", strerror(ERRNO)); closesocket(*sock); *sock = INVALID_SOCKET; return 0; } set_close_on_exec(*sock, fc(ctx)); if (ip_ver == 4) { /* connected with IPv4 */ conn_ret = connect(*sock, (struct sockaddr *)((void *)&sa->sin), sizeof(sa->sin)); } #if defined(USE_IPV6) else if (ip_ver == 6) { /* connected with IPv6 */ conn_ret = connect(*sock, (struct sockaddr *)((void *)&sa->sin6), sizeof(sa->sin6)); } #endif #if defined(_WIN32) if (conn_ret != 0) { DWORD err = WSAGetLastError(); /* could return WSAEWOULDBLOCK */ conn_ret = (int)err; #if !defined(EINPROGRESS) #define EINPROGRESS (WSAEWOULDBLOCK) /* Winsock equivalent */ #endif /* if !defined(EINPROGRESS) */ } #endif if ((conn_ret != 0) && (conn_ret != EINPROGRESS)) { /* Data for getsockopt */ int sockerr = -1; void *psockerr = &sockerr; #if defined(_WIN32) int len = (int)sizeof(sockerr); #else socklen_t len = (socklen_t)sizeof(sockerr); #endif /* Data for poll */ struct mg_pollfd pfd[1]; int pollres; int ms_wait = 10000; /* 10 second timeout */ /* For a non-blocking socket, the connect sequence is: * 1) call connect (will not block) * 2) wait until the socket is ready for writing (select or poll) * 3) check connection state with getsockopt */ pfd[0].fd = *sock; pfd[0].events = POLLOUT; pollres = mg_poll(pfd, 1, (int)(ms_wait), &(ctx->stop_flag)); if (pollres != 1) { /* Not connected */ mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "connect(%s:%d): timeout", host, port); closesocket(*sock); *sock = INVALID_SOCKET; return 0; } #if defined(_WIN32) ret = getsockopt(*sock, SOL_SOCKET, SO_ERROR, (char *)psockerr, &len); #else ret = getsockopt(*sock, SOL_SOCKET, SO_ERROR, psockerr, &len); #endif if ((ret != 0) || (sockerr != 0)) { /* Not connected */ mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "connect(%s:%d): error %s", host, port, strerror(sockerr)); closesocket(*sock); *sock = INVALID_SOCKET; return 0; } } return 1; } int mg_url_encode(const char *src, char *dst, size_t dst_len) { static const char *dont_escape = "._-$,;~()"; static const char *hex = "0123456789abcdef"; char *pos = dst; const char *end = dst + dst_len - 1; for (; ((*src != '\0') && (pos < end)); src++, pos++) { if (isalnum((unsigned char)*src) || (strchr(dont_escape, *src) != NULL)) { *pos = *src; } else if (pos + 2 < end) { pos[0] = '%'; pos[1] = hex[(unsigned char)*src >> 4]; pos[2] = hex[(unsigned char)*src & 0xf]; pos += 2; } else { break; } } *pos = '\0'; return (*src == '\0') ? (int)(pos - dst) : -1; } /* Return 0 on success, non-zero if an error occurs. */ static int print_dir_entry(struct de *de) { size_t hrefsize; char *href; char size[64], mod[64]; #if defined(REENTRANT_TIME) struct tm _tm; struct tm *tm = &_tm; #else struct tm *tm; #endif hrefsize = PATH_MAX * 3; /* worst case */ href = (char *)mg_malloc(hrefsize); if (href == NULL) { return -1; } if (de->file.is_directory) { mg_snprintf(de->conn, NULL, /* Buffer is big enough */ size, sizeof(size), "%s", "[DIRECTORY]"); } else { /* We use (signed) cast below because MSVC 6 compiler cannot * convert unsigned __int64 to double. Sigh. */ if (de->file.size < 1024) { mg_snprintf(de->conn, NULL, /* Buffer is big enough */ size, sizeof(size), "%d", (int)de->file.size); } else if (de->file.size < 0x100000) { mg_snprintf(de->conn, NULL, /* Buffer is big enough */ size, sizeof(size), "%.1fk", (double)de->file.size / 1024.0); } else if (de->file.size < 0x40000000) { mg_snprintf(de->conn, NULL, /* Buffer is big enough */ size, sizeof(size), "%.1fM", (double)de->file.size / 1048576); } else { mg_snprintf(de->conn, NULL, /* Buffer is big enough */ size, sizeof(size), "%.1fG", (double)de->file.size / 1073741824); } } /* Note: mg_snprintf will not cause a buffer overflow above. * So, string truncation checks are not required here. */ #if defined(REENTRANT_TIME) localtime_r(&de->file.last_modified, tm); #else tm = localtime(&de->file.last_modified); #endif if (tm != NULL) { strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", tm); } else { mg_strlcpy(mod, "01-Jan-1970 00:00", sizeof(mod)); mod[sizeof(mod) - 1] = '\0'; } mg_url_encode(de->file_name, href, hrefsize); mg_printf(de->conn, "<tr><td><a href=\"%s%s\">%s%s</a></td>" "<td>&nbsp;%s</td><td>&nbsp;&nbsp;%s</td></tr>\n", href, de->file.is_directory ? "/" : "", de->file_name, de->file.is_directory ? "/" : "", mod, size); mg_free(href); return 0; } /* This function is called from send_directory() and used for * sorting directory entries by size, or name, or modification time. * On windows, __cdecl specification is needed in case if project is built * with __stdcall convention. qsort always requires __cdels callback. */ static int WINCDECL compare_dir_entries(const void *p1, const void *p2) { if (p1 && p2) { const struct de *a = (const struct de *)p1, *b = (const struct de *)p2; const char *query_string = a->conn->request_info.query_string; int cmp_result = 0; if (query_string == NULL) { query_string = "na"; } if (a->file.is_directory && !b->file.is_directory) { return -1; /* Always put directories on top */ } else if (!a->file.is_directory && b->file.is_directory) { return 1; /* Always put directories on top */ } else if (*query_string == 'n') { cmp_result = strcmp(a->file_name, b->file_name); } else if (*query_string == 's') { cmp_result = (a->file.size == b->file.size) ? 0 : ((a->file.size > b->file.size) ? 1 : -1); } else if (*query_string == 'd') { cmp_result = (a->file.last_modified == b->file.last_modified) ? 0 : ((a->file.last_modified > b->file.last_modified) ? 1 : -1); } return (query_string[1] == 'd') ? -cmp_result : cmp_result; } return 0; } static int must_hide_file(struct mg_connection *conn, const char *path) { if (conn && conn->dom_ctx) { const char *pw_pattern = "**" PASSWORDS_FILE_NAME "$"; const char *pattern = conn->dom_ctx->config[HIDE_FILES]; return (match_prefix(pw_pattern, strlen(pw_pattern), path) > 0) || ((pattern != NULL) && (match_prefix(pattern, strlen(pattern), path) > 0)); } return 0; } static int scan_directory(struct mg_connection *conn, const char *dir, void *data, int (*cb)(struct de *, void *)) { char path[PATH_MAX]; struct dirent *dp; DIR *dirp; struct de de; int truncated; if ((dirp = mg_opendir(conn, dir)) == NULL) { return 0; } else { de.conn = conn; while ((dp = mg_readdir(dirp)) != NULL) { /* Do not show current dir and hidden files */ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..") || must_hide_file(conn, dp->d_name)) { continue; } mg_snprintf( conn, &truncated, path, sizeof(path), "%s/%s", dir, dp->d_name); /* If we don't memset stat structure to zero, mtime will have * garbage and strftime() will segfault later on in * print_dir_entry(). memset is required only if mg_stat() * fails. For more details, see * http://code.google.com/p/mongoose/issues/detail?id=79 */ memset(&de.file, 0, sizeof(de.file)); if (truncated) { /* If the path is not complete, skip processing. */ continue; } if (!mg_stat(conn, path, &de.file)) { mg_cry_internal(conn, "%s: mg_stat(%s) failed: %s", __func__, path, strerror(ERRNO)); } de.file_name = dp->d_name; cb(&de, data); } (void)mg_closedir(dirp); } return 1; } #if !defined(NO_FILES) static int remove_directory(struct mg_connection *conn, const char *dir) { char path[PATH_MAX]; struct dirent *dp; DIR *dirp; struct de de; int truncated; int ok = 1; if ((dirp = mg_opendir(conn, dir)) == NULL) { return 0; } else { de.conn = conn; while ((dp = mg_readdir(dirp)) != NULL) { /* Do not show current dir (but show hidden files as they will * also be removed) */ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) { continue; } mg_snprintf( conn, &truncated, path, sizeof(path), "%s/%s", dir, dp->d_name); /* If we don't memset stat structure to zero, mtime will have * garbage and strftime() will segfault later on in * print_dir_entry(). memset is required only if mg_stat() * fails. For more details, see * http://code.google.com/p/mongoose/issues/detail?id=79 */ memset(&de.file, 0, sizeof(de.file)); if (truncated) { /* Do not delete anything shorter */ ok = 0; continue; } if (!mg_stat(conn, path, &de.file)) { mg_cry_internal(conn, "%s: mg_stat(%s) failed: %s", __func__, path, strerror(ERRNO)); ok = 0; } if (de.file.is_directory) { if (remove_directory(conn, path) == 0) { ok = 0; } } else { /* This will fail file is the file is in memory */ if (mg_remove(conn, path) == 0) { ok = 0; } } } (void)mg_closedir(dirp); IGNORE_UNUSED_RESULT(rmdir(dir)); } return ok; } #endif struct dir_scan_data { struct de *entries; unsigned int num_entries; unsigned int arr_size; }; /* Behaves like realloc(), but frees original pointer on failure */ static void * realloc2(void *ptr, size_t size) { void *new_ptr = mg_realloc(ptr, size); if (new_ptr == NULL) { mg_free(ptr); } return new_ptr; } static int dir_scan_callback(struct de *de, void *data) { struct dir_scan_data *dsd = (struct dir_scan_data *)data; if ((dsd->entries == NULL) || (dsd->num_entries >= dsd->arr_size)) { dsd->arr_size *= 2; dsd->entries = (struct de *)realloc2(dsd->entries, dsd->arr_size * sizeof(dsd->entries[0])); } if (dsd->entries == NULL) { /* TODO(lsm, low): propagate an error to the caller */ dsd->num_entries = 0; } else { dsd->entries[dsd->num_entries].file_name = mg_strdup(de->file_name); dsd->entries[dsd->num_entries].file = de->file; dsd->entries[dsd->num_entries].conn = de->conn; dsd->num_entries++; } return 0; } static void handle_directory_request(struct mg_connection *conn, const char *dir) { unsigned int i; int sort_direction; struct dir_scan_data data = {NULL, 0, 128}; char date[64]; time_t curtime = time(NULL); if (!scan_directory(conn, dir, &data, dir_scan_callback)) { mg_send_http_error(conn, 500, "Error: Cannot open directory\nopendir(%s): %s", dir, strerror(ERRNO)); return; } gmt_time_string(date, sizeof(date), &curtime); if (!conn) { return; } sort_direction = ((conn->request_info.query_string != NULL) && (conn->request_info.query_string[1] == 'd')) ? 'a' : 'd'; conn->must_close = 1; mg_printf(conn, "HTTP/1.1 200 OK\r\n"); send_static_cache_header(conn); send_additional_header(conn); mg_printf(conn, "Date: %s\r\n" "Connection: close\r\n" "Content-Type: text/html; charset=utf-8\r\n\r\n", date); mg_printf(conn, "<html><head><title>Index of %s</title>" "<style>th {text-align: left;}</style></head>" "<body><h1>Index of %s</h1><pre><table cellpadding=\"0\">" "<tr><th><a href=\"?n%c\">Name</a></th>" "<th><a href=\"?d%c\">Modified</a></th>" "<th><a href=\"?s%c\">Size</a></th></tr>" "<tr><td colspan=\"3\"><hr></td></tr>", conn->request_info.local_uri, conn->request_info.local_uri, sort_direction, sort_direction, sort_direction); /* Print first entry - link to a parent directory */ mg_printf(conn, "<tr><td><a href=\"%s\">%s</a></td>" "<td>&nbsp;%s</td><td>&nbsp;&nbsp;%s</td></tr>\n", "..", "Parent directory", "-", "-"); /* Sort and print directory entries */ if (data.entries != NULL) { qsort(data.entries, (size_t)data.num_entries, sizeof(data.entries[0]), compare_dir_entries); for (i = 0; i < data.num_entries; i++) { print_dir_entry(&data.entries[i]); mg_free(data.entries[i].file_name); } mg_free(data.entries); } mg_printf(conn, "%s", "</table></body></html>"); conn->status_code = 200; } /* Send len bytes from the opened file to the client. */ static void send_file_data(struct mg_connection *conn, struct mg_file *filep, int64_t offset, int64_t len) { char buf[MG_BUF_LEN]; int to_read, num_read, num_written; int64_t size; if (!filep || !conn) { return; } /* Sanity check the offset */ size = (filep->stat.size > INT64_MAX) ? INT64_MAX : (int64_t)(filep->stat.size); offset = (offset < 0) ? 0 : ((offset > size) ? size : offset); #if defined(MG_USE_OPEN_FILE) if ((len > 0) && (filep->access.membuf != NULL) && (size > 0)) { /* file stored in memory */ if (len > size - offset) { len = size - offset; } mg_write(conn, filep->access.membuf + offset, (size_t)len); } else /* else block below */ #endif if (len > 0 && filep->access.fp != NULL) { /* file stored on disk */ #if defined(__linux__) /* sendfile is only available for Linux */ if ((conn->ssl == 0) && (conn->throttle == 0) && (!mg_strcasecmp(conn->dom_ctx->config[ALLOW_SENDFILE_CALL], "yes"))) { off_t sf_offs = (off_t)offset; ssize_t sf_sent; int sf_file = fileno(filep->access.fp); int loop_cnt = 0; do { /* 2147479552 (0x7FFFF000) is a limit found by experiment on * 64 bit Linux (2^31 minus one memory page of 4k?). */ size_t sf_tosend = (size_t)((len < 0x7FFFF000) ? len : 0x7FFFF000); sf_sent = sendfile(conn->client.sock, sf_file, &sf_offs, sf_tosend); if (sf_sent > 0) { len -= sf_sent; offset += sf_sent; } else if (loop_cnt == 0) { /* This file can not be sent using sendfile. * This might be the case for pseudo-files in the * /sys/ and /proc/ file system. * Use the regular user mode copy code instead. */ break; } else if (sf_sent == 0) { /* No error, but 0 bytes sent. May be EOF? */ return; } loop_cnt++; } while ((len > 0) && (sf_sent >= 0)); if (sf_sent > 0) { return; /* OK */ } /* sf_sent<0 means error, thus fall back to the classic way */ /* This is always the case, if sf_file is not a "normal" file, * e.g., for sending data from the output of a CGI process. */ offset = (int64_t)sf_offs; } #endif if ((offset > 0) && (fseeko(filep->access.fp, offset, SEEK_SET) != 0)) { mg_cry_internal(conn, "%s: fseeko() failed: %s", __func__, strerror(ERRNO)); mg_send_http_error( conn, 500, "%s", "Error: Unable to access file at requested position."); } else { while (len > 0) { /* Calculate how much to read from the file in the buffer */ to_read = sizeof(buf); if ((int64_t)to_read > len) { to_read = (int)len; } /* Read from file, exit the loop on error */ if ((num_read = (int)fread(buf, 1, (size_t)to_read, filep->access.fp)) <= 0) { break; } /* Send read bytes to the client, exit the loop on error */ if ((num_written = mg_write(conn, buf, (size_t)num_read)) != num_read) { break; } /* Both read and were successful, adjust counters */ len -= num_written; } } } } static int parse_range_header(const char *header, int64_t *a, int64_t *b) { return sscanf(header, "bytes=%" INT64_FMT "-%" INT64_FMT, a, b); } static void construct_etag(char *buf, size_t buf_len, const struct mg_file_stat *filestat) { if ((filestat != NULL) && (buf != NULL)) { mg_snprintf(NULL, NULL, /* All calls to construct_etag use 64 byte buffer */ buf, buf_len, "\"%lx.%" INT64_FMT "\"", (unsigned long)filestat->last_modified, filestat->size); } } static void fclose_on_exec(struct mg_file_access *filep, struct mg_connection *conn) { if (filep != NULL && filep->fp != NULL) { #if defined(_WIN32) (void)conn; /* Unused. */ #else if (fcntl(fileno(filep->fp), F_SETFD, FD_CLOEXEC) != 0) { mg_cry_internal(conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, strerror(ERRNO)); } #endif } } #if defined(USE_ZLIB) #include "mod_zlib.inl" #endif static void handle_static_file_request(struct mg_connection *conn, const char *path, struct mg_file *filep, const char *mime_type, const char *additional_headers) { char date[64], lm[64], etag[64]; char range[128]; /* large enough, so there will be no overflow */ const char *msg = "OK", *hdr; time_t curtime = time(NULL); int64_t cl, r1, r2; struct vec mime_vec; int n, truncated; char gz_path[PATH_MAX]; const char *encoding = ""; const char *cors_orig_cfg; const char *cors1, *cors2, *cors3; int is_head_request; #if defined(USE_ZLIB) /* Compression is allowed, unless there is a reason not to use compression. * If the file is already compressed, too small or a "range" request was * made, on the fly compression is not possible. */ int allow_on_the_fly_compression = 1; #endif if ((conn == NULL) || (conn->dom_ctx == NULL) || (filep == NULL)) { return; } is_head_request = !strcmp(conn->request_info.request_method, "HEAD"); if (mime_type == NULL) { get_mime_type(conn, path, &mime_vec); } else { mime_vec.ptr = mime_type; mime_vec.len = strlen(mime_type); } if (filep->stat.size > INT64_MAX) { mg_send_http_error(conn, 500, "Error: File size is too large to send\n%" INT64_FMT, filep->stat.size); return; } cl = (int64_t)filep->stat.size; conn->status_code = 200; range[0] = '\0'; #if defined(USE_ZLIB) /* if this file is in fact a pre-gzipped file, rewrite its filename * it's important to rewrite the filename after resolving * the mime type from it, to preserve the actual file's type */ if (!conn->accept_gzip) { allow_on_the_fly_compression = 0; } #endif if (filep->stat.is_gzipped) { mg_snprintf(conn, &truncated, gz_path, sizeof(gz_path), "%s.gz", path); if (truncated) { mg_send_http_error(conn, 500, "Error: Path of zipped file too long (%s)", path); return; } path = gz_path; encoding = "Content-Encoding: gzip\r\n"; #if defined(USE_ZLIB) /* File is already compressed. No "on the fly" compression. */ allow_on_the_fly_compression = 0; #endif } if (!mg_fopen(conn, path, MG_FOPEN_MODE_READ, filep)) { mg_send_http_error(conn, 500, "Error: Cannot open file\nfopen(%s): %s", path, strerror(ERRNO)); return; } fclose_on_exec(&filep->access, conn); /* If "Range" request was made: parse header, send only selected part * of the file. */ r1 = r2 = 0; hdr = mg_get_header(conn, "Range"); if ((hdr != NULL) && ((n = parse_range_header(hdr, &r1, &r2)) > 0) && (r1 >= 0) && (r2 >= 0)) { /* actually, range requests don't play well with a pre-gzipped * file (since the range is specified in the uncompressed space) */ if (filep->stat.is_gzipped) { mg_send_http_error( conn, 416, /* 416 = Range Not Satisfiable */ "%s", "Error: Range requests in gzipped files are not supported"); (void)mg_fclose( &filep->access); /* ignore error on read only file */ return; } conn->status_code = 206; cl = (n == 2) ? (((r2 > cl) ? cl : r2) - r1 + 1) : (cl - r1); mg_snprintf(conn, NULL, /* range buffer is big enough */ range, sizeof(range), "Content-Range: bytes " "%" INT64_FMT "-%" INT64_FMT "/%" INT64_FMT "\r\n", r1, r1 + cl - 1, filep->stat.size); msg = "Partial Content"; #if defined(USE_ZLIB) /* Do not compress ranges. */ allow_on_the_fly_compression = 0; #endif } /* Do not compress small files. Small files do not benefit from file * compression, but there is still some overhead. */ #if defined(USE_ZLIB) if (filep->stat.size < MG_FILE_COMPRESSION_SIZE_LIMIT) { /* File is below the size limit. */ allow_on_the_fly_compression = 0; } #endif /* Standard CORS header */ cors_orig_cfg = conn->dom_ctx->config[ACCESS_CONTROL_ALLOW_ORIGIN]; hdr = mg_get_header(conn, "Origin"); if (cors_orig_cfg && *cors_orig_cfg && hdr) { /* Cross-origin resource sharing (CORS), see * http://www.html5rocks.com/en/tutorials/cors/, * http://www.html5rocks.com/static/images/cors_server_flowchart.png * - * preflight is not supported for files. */ cors1 = "Access-Control-Allow-Origin: "; cors2 = cors_orig_cfg; cors3 = "\r\n"; } else { cors1 = cors2 = cors3 = ""; } /* Prepare Etag, Date, Last-Modified headers. Must be in UTC, * according to * http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3 */ gmt_time_string(date, sizeof(date), &curtime); gmt_time_string(lm, sizeof(lm), &filep->stat.last_modified); construct_etag(etag, sizeof(etag), &filep->stat); /* Send header */ (void)mg_printf(conn, "HTTP/1.1 %d %s\r\n" "%s%s%s" /* CORS */ "Date: %s\r\n" "Last-Modified: %s\r\n" "Etag: %s\r\n" "Content-Type: %.*s\r\n" "Connection: %s\r\n", conn->status_code, msg, cors1, cors2, cors3, date, lm, etag, (int)mime_vec.len, mime_vec.ptr, suggest_connection_header(conn)); send_static_cache_header(conn); send_additional_header(conn); #if defined(USE_ZLIB) /* On the fly compression allowed */ if (allow_on_the_fly_compression) { /* For on the fly compression, we don't know the content size in * advance, so we have to use chunked encoding */ (void)mg_printf(conn, "Content-Encoding: gzip\r\n" "Transfer-Encoding: chunked\r\n"); } else #endif { /* Without on-the-fly compression, we know the content-length * and we can use ranges (with on-the-fly compression we cannot). * So we send these response headers only in this case. */ (void)mg_printf(conn, "Content-Length: %" INT64_FMT "\r\n" "Accept-Ranges: bytes\r\n" "%s" /* range */ "%s" /* encoding */, cl, range, encoding); } /* The previous code must not add any header starting with X- to make * sure no one of the additional_headers is included twice */ if (additional_headers != NULL) { (void)mg_printf(conn, "%.*s\r\n\r\n", (int)strlen(additional_headers), additional_headers); } else { (void)mg_printf(conn, "\r\n"); } if (!is_head_request) { #if defined(USE_ZLIB) if (allow_on_the_fly_compression) { /* Compress and send */ send_compressed_data(conn, filep); } else #endif { /* Send file directly */ send_file_data(conn, filep, r1, cl); } } (void)mg_fclose(&filep->access); /* ignore error on read only file */ } int mg_send_file_body(struct mg_connection *conn, const char *path) { struct mg_file file = STRUCT_FILE_INITIALIZER; if (!mg_fopen(conn, path, MG_FOPEN_MODE_READ, &file)) { return -1; } fclose_on_exec(&file.access, conn); send_file_data(conn, &file, 0, INT64_MAX); (void)mg_fclose(&file.access); /* Ignore errors for readonly files */ return 0; /* >= 0 for OK */ } #if !defined(NO_CACHING) /* Return True if we should reply 304 Not Modified. */ static int is_not_modified(const struct mg_connection *conn, const struct mg_file_stat *filestat) { char etag[64]; const char *ims = mg_get_header(conn, "If-Modified-Since"); const char *inm = mg_get_header(conn, "If-None-Match"); construct_etag(etag, sizeof(etag), filestat); return ((inm != NULL) && !mg_strcasecmp(etag, inm)) || ((ims != NULL) && (filestat->last_modified <= parse_date_string(ims))); } static void handle_not_modified_static_file_request(struct mg_connection *conn, struct mg_file *filep) { char date[64], lm[64], etag[64]; time_t curtime = time(NULL); if ((conn == NULL) || (filep == NULL)) { return; } conn->status_code = 304; gmt_time_string(date, sizeof(date), &curtime); gmt_time_string(lm, sizeof(lm), &filep->stat.last_modified); construct_etag(etag, sizeof(etag), &filep->stat); (void)mg_printf(conn, "HTTP/1.1 %d %s\r\n" "Date: %s\r\n", conn->status_code, mg_get_response_code_text(conn, conn->status_code), date); send_static_cache_header(conn); send_additional_header(conn); (void)mg_printf(conn, "Last-Modified: %s\r\n" "Etag: %s\r\n" "Connection: %s\r\n" "\r\n", lm, etag, suggest_connection_header(conn)); } #endif void mg_send_file(struct mg_connection *conn, const char *path) { mg_send_mime_file2(conn, path, NULL, NULL); } void mg_send_mime_file(struct mg_connection *conn, const char *path, const char *mime_type) { mg_send_mime_file2(conn, path, mime_type, NULL); } void mg_send_mime_file2(struct mg_connection *conn, const char *path, const char *mime_type, const char *additional_headers) { struct mg_file file = STRUCT_FILE_INITIALIZER; if (!conn) { /* No conn */ return; } if (mg_stat(conn, path, &file.stat)) { #if !defined(NO_CACHING) if (is_not_modified(conn, &file.stat)) { /* Send 304 "Not Modified" - this must not send any body data */ handle_not_modified_static_file_request(conn, &file); } else #endif /* NO_CACHING */ if (file.stat.is_directory) { if (!mg_strcasecmp(conn->dom_ctx->config[ENABLE_DIRECTORY_LISTING], "yes")) { handle_directory_request(conn, path); } else { mg_send_http_error(conn, 403, "%s", "Error: Directory listing denied"); } } else { handle_static_file_request( conn, path, &file, mime_type, additional_headers); } } else { mg_send_http_error(conn, 404, "%s", "Error: File not found"); } } /* For a given PUT path, create all intermediate subdirectories. * Return 0 if the path itself is a directory. * Return 1 if the path leads to a file. * Return -1 for if the path is too long. * Return -2 if path can not be created. */ static int put_dir(struct mg_connection *conn, const char *path) { char buf[PATH_MAX]; const char *s, *p; struct mg_file file = STRUCT_FILE_INITIALIZER; size_t len; int res = 1; for (s = p = path + 2; (p = strchr(s, '/')) != NULL; s = ++p) { len = (size_t)(p - path); if (len >= sizeof(buf)) { /* path too long */ res = -1; break; } memcpy(buf, path, len); buf[len] = '\0'; /* Try to create intermediate directory */ DEBUG_TRACE("mkdir(%s)", buf); if (!mg_stat(conn, buf, &file.stat) && mg_mkdir(conn, buf, 0755) != 0) { /* path does not exixt and can not be created */ res = -2; break; } /* Is path itself a directory? */ if (p[1] == '\0') { res = 0; } } return res; } static void remove_bad_file(const struct mg_connection *conn, const char *path) { int r = mg_remove(conn, path); if (r != 0) { mg_cry_internal(conn, "%s: Cannot remove invalid file %s", __func__, path); } } long long mg_store_body(struct mg_connection *conn, const char *path) { char buf[MG_BUF_LEN]; long long len = 0; int ret, n; struct mg_file fi; if (conn->consumed_content != 0) { mg_cry_internal(conn, "%s: Contents already consumed", __func__); return -11; } ret = put_dir(conn, path); if (ret < 0) { /* -1 for path too long, * -2 for path can not be created. */ return ret; } if (ret != 1) { /* Return 0 means, path itself is a directory. */ return 0; } if (mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &fi) == 0) { return -12; } ret = mg_read(conn, buf, sizeof(buf)); while (ret > 0) { n = (int)fwrite(buf, 1, (size_t)ret, fi.access.fp); if (n != ret) { (void)mg_fclose( &fi.access); /* File is bad and will be removed anyway. */ remove_bad_file(conn, path); return -13; } len += ret; ret = mg_read(conn, buf, sizeof(buf)); } /* File is open for writing. If fclose fails, there was probably an * error flushing the buffer to disk, so the file on disk might be * broken. Delete it and return an error to the caller. */ if (mg_fclose(&fi.access) != 0) { remove_bad_file(conn, path); return -14; } return len; } /* Parse a buffer: * Forward the string pointer till the end of a word, then * terminate it and forward till the begin of the next word. */ static int skip_to_end_of_word_and_terminate(char **ppw, int eol) { /* Forward until a space is found - use isgraph here */ /* See http://www.cplusplus.com/reference/cctype/ */ while (isgraph((unsigned char)**ppw)) { (*ppw)++; } /* Check end of word */ if (eol) { /* must be a end of line */ if ((**ppw != '\r') && (**ppw != '\n')) { return -1; } } else { /* must be a end of a word, but not a line */ if (**ppw != ' ') { return -1; } } /* Terminate and forward to the next word */ do { **ppw = 0; (*ppw)++; } while (isspace((unsigned char)**ppw)); /* Check after term */ if (!eol) { /* if it's not the end of line, there must be a next word */ if (!isgraph((unsigned char)**ppw)) { return -1; } } /* ok */ return 1; } /* Parse HTTP headers from the given buffer, advance buf pointer * to the point where parsing stopped. * All parameters must be valid pointers (not NULL). * Return <0 on error. */ static int parse_http_headers(char **buf, struct mg_header hdr[MG_MAX_HEADERS]) { int i; int num_headers = 0; for (i = 0; i < (int)MG_MAX_HEADERS; i++) { char *dp = *buf; while ((*dp != ':') && (*dp >= 33) && (*dp <= 126)) { dp++; } if (dp == *buf) { /* End of headers reached. */ break; } if (*dp != ':') { /* This is not a valid field. */ return -1; } /* End of header key (*dp == ':') */ /* Truncate here and set the key name */ *dp = 0; hdr[i].name = *buf; do { dp++; } while (*dp == ' '); /* The rest of the line is the value */ hdr[i].value = dp; *buf = dp + strcspn(dp, "\r\n"); if (((*buf)[0] != '\r') || ((*buf)[1] != '\n')) { *buf = NULL; } num_headers = i + 1; if (*buf) { (*buf)[0] = 0; (*buf)[1] = 0; *buf += 2; } else { *buf = dp; break; } if ((*buf)[0] == '\r') { /* This is the end of the header */ break; } } return num_headers; } struct mg_http_method_info { const char *name; int request_has_body; int response_has_body; int is_safe; int is_idempotent; int is_cacheable; }; /* https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods */ static struct mg_http_method_info http_methods[] = { /* HTTP (RFC 2616) */ {"GET", 0, 1, 1, 1, 1}, {"POST", 1, 1, 0, 0, 0}, {"PUT", 1, 0, 0, 1, 0}, {"DELETE", 0, 0, 0, 1, 0}, {"HEAD", 0, 0, 1, 1, 1}, {"OPTIONS", 0, 0, 1, 1, 0}, {"CONNECT", 1, 1, 0, 0, 0}, /* TRACE method (RFC 2616) is not supported for security reasons */ /* PATCH method (RFC 5789) */ {"PATCH", 1, 0, 0, 0, 0}, /* PATCH method only allowed for CGI/Lua/LSP and callbacks. */ /* WEBDAV (RFC 2518) */ {"PROPFIND", 0, 1, 1, 1, 0}, /* http://www.webdav.org/specs/rfc4918.html, 9.1: * Some PROPFIND results MAY be cached, with care, * as there is no cache validation mechanism for * most properties. This method is both safe and * idempotent (see Section 9.1 of [RFC2616]). */ {"MKCOL", 0, 0, 0, 1, 0}, /* http://www.webdav.org/specs/rfc4918.html, 9.1: * When MKCOL is invoked without a request body, * the newly created collection SHOULD have no * members. A MKCOL request message may contain * a message body. The precise behavior of a MKCOL * request when the body is present is undefined, * ... ==> We do not support MKCOL with body data. * This method is idempotent, but not safe (see * Section 9.1 of [RFC2616]). Responses to this * method MUST NOT be cached. */ /* Unsupported WEBDAV Methods: */ /* PROPPATCH, COPY, MOVE, LOCK, UNLOCK (RFC 2518) */ /* + 11 methods from RFC 3253 */ /* ORDERPATCH (RFC 3648) */ /* ACL (RFC 3744) */ /* SEARCH (RFC 5323) */ /* + MicroSoft extensions * https://msdn.microsoft.com/en-us/library/aa142917.aspx */ /* REPORT method (RFC 3253) */ {"REPORT", 1, 1, 1, 1, 1}, /* REPORT method only allowed for CGI/Lua/LSP and callbacks. */ /* It was defined for WEBDAV in RFC 3253, Sec. 3.6 * (https://tools.ietf.org/html/rfc3253#section-3.6), but seems * to be useful for REST in case a "GET request with body" is * required. */ {NULL, 0, 0, 0, 0, 0} /* end of list */ }; static const struct mg_http_method_info * get_http_method_info(const char *method) { /* Check if the method is known to the server. The list of all known * HTTP methods can be found here at * http://www.iana.org/assignments/http-methods/http-methods.xhtml */ const struct mg_http_method_info *m = http_methods; while (m->name) { if (!strcmp(m->name, method)) { return m; } m++; } return NULL; } static int is_valid_http_method(const char *method) { return (get_http_method_info(method) != NULL); } /* Parse HTTP request, fill in mg_request_info structure. * This function modifies the buffer by NUL-terminating * HTTP request components, header names and header values. * Parameters: * buf (in/out): pointer to the HTTP header to parse and split * len (in): length of HTTP header buffer * re (out): parsed header as mg_request_info * buf and ri must be valid pointers (not NULL), len>0. * Returns <0 on error. */ static int parse_http_request(char *buf, int len, struct mg_request_info *ri) { int request_length; int init_skip = 0; /* Reset attributes. DO NOT TOUCH is_ssl, remote_addr, * remote_port */ ri->remote_user = ri->request_method = ri->request_uri = ri->http_version = NULL; ri->num_headers = 0; /* RFC says that all initial whitespaces should be ingored */ /* This included all leading \r and \n (isspace) */ /* See table: http://www.cplusplus.com/reference/cctype/ */ while ((len > 0) && isspace((unsigned char)*buf)) { buf++; len--; init_skip++; } if (len == 0) { /* Incomplete request */ return 0; } /* Control characters are not allowed, including zero */ if (iscntrl((unsigned char)*buf)) { return -1; } /* Find end of HTTP header */ request_length = get_http_header_len(buf, len); if (request_length <= 0) { return request_length; } buf[request_length - 1] = '\0'; if ((*buf == 0) || (*buf == '\r') || (*buf == '\n')) { return -1; } /* The first word has to be the HTTP method */ ri->request_method = buf; if (skip_to_end_of_word_and_terminate(&buf, 0) <= 0) { return -1; } /* Check for a valid http method */ if (!is_valid_http_method(ri->request_method)) { return -1; } /* The second word is the URI */ ri->request_uri = buf; if (skip_to_end_of_word_and_terminate(&buf, 0) <= 0) { return -1; } /* Next would be the HTTP version */ ri->http_version = buf; if (skip_to_end_of_word_and_terminate(&buf, 1) <= 0) { return -1; } /* Check for a valid HTTP version key */ if (strncmp(ri->http_version, "HTTP/", 5) != 0) { /* Invalid request */ return -1; } ri->http_version += 5; /* Parse all HTTP headers */ ri->num_headers = parse_http_headers(&buf, ri->http_headers); if (ri->num_headers < 0) { /* Error while parsing headers */ return -1; } return request_length + init_skip; } static int parse_http_response(char *buf, int len, struct mg_response_info *ri) { int response_length; int init_skip = 0; char *tmp, *tmp2; long l; /* Initialize elements. */ ri->http_version = ri->status_text = NULL; ri->num_headers = ri->status_code = 0; /* RFC says that all initial whitespaces should be ingored */ /* This included all leading \r and \n (isspace) */ /* See table: http://www.cplusplus.com/reference/cctype/ */ while ((len > 0) && isspace((unsigned char)*buf)) { buf++; len--; init_skip++; } if (len == 0) { /* Incomplete request */ return 0; } /* Control characters are not allowed, including zero */ if (iscntrl((unsigned char)*buf)) { return -1; } /* Find end of HTTP header */ response_length = get_http_header_len(buf, len); if (response_length <= 0) { return response_length; } buf[response_length - 1] = '\0'; if ((*buf == 0) || (*buf == '\r') || (*buf == '\n')) { return -1; } /* The first word is the HTTP version */ /* Check for a valid HTTP version key */ if (strncmp(buf, "HTTP/", 5) != 0) { /* Invalid request */ return -1; } buf += 5; if (!isgraph((unsigned char)buf[0])) { /* Invalid request */ return -1; } ri->http_version = buf; if (skip_to_end_of_word_and_terminate(&buf, 0) <= 0) { return -1; } /* The second word is the status as a number */ tmp = buf; if (skip_to_end_of_word_and_terminate(&buf, 0) <= 0) { return -1; } l = strtol(tmp, &tmp2, 10); if ((l < 100) || (l >= 1000) || ((tmp2 - tmp) != 3) || (*tmp2 != 0)) { /* Everything else but a 3 digit code is invalid */ return -1; } ri->status_code = (int)l; /* The rest of the line is the status text */ ri->status_text = buf; /* Find end of status text */ /* isgraph or isspace = isprint */ while (isprint((unsigned char)*buf)) { buf++; } if ((*buf != '\r') && (*buf != '\n')) { return -1; } /* Terminate string and forward buf to next line */ do { *buf = 0; buf++; } while (isspace((unsigned char)*buf)); /* Parse all HTTP headers */ ri->num_headers = parse_http_headers(&buf, ri->http_headers); if (ri->num_headers < 0) { /* Error while parsing headers */ return -1; } return response_length + init_skip; } /* Keep reading the input (either opened file descriptor fd, or socket sock, * or SSL descriptor ssl) into buffer buf, until \r\n\r\n appears in the * buffer (which marks the end of HTTP request). Buffer buf may already * have some data. The length of the data is stored in nread. * Upon every read operation, increase nread by the number of bytes read. */ static int read_message(FILE *fp, struct mg_connection *conn, char *buf, int bufsiz, int *nread) { int request_len, n = 0; struct timespec last_action_time; double request_timeout; if (!conn) { return 0; } memset(&last_action_time, 0, sizeof(last_action_time)); if (conn->dom_ctx->config[REQUEST_TIMEOUT]) { /* value of request_timeout is in seconds, config in milliseconds */ request_timeout = atof(conn->dom_ctx->config[REQUEST_TIMEOUT]) / 1000.0; } else { request_timeout = -1.0; } if (conn->handled_requests > 0) { if (conn->dom_ctx->config[KEEP_ALIVE_TIMEOUT]) { request_timeout = atof(conn->dom_ctx->config[KEEP_ALIVE_TIMEOUT]) / 1000.0; } } request_len = get_http_header_len(buf, *nread); /* first time reading from this connection */ clock_gettime(CLOCK_MONOTONIC, &last_action_time); while (request_len == 0) { /* Full request not yet received */ if (conn->phys_ctx->stop_flag != 0) { /* Server is to be stopped. */ return -1; } if (*nread >= bufsiz) { /* Request too long */ return -2; } n = pull_inner( fp, conn, buf + *nread, bufsiz - *nread, request_timeout); if (n == -2) { /* Receive error */ return -1; } if (n > 0) { *nread += n; request_len = get_http_header_len(buf, *nread); } else { request_len = 0; } if ((request_len == 0) && (request_timeout >= 0)) { if (mg_difftimespec(&last_action_time, &(conn->req_time)) > request_timeout) { /* Timeout */ return -1; } clock_gettime(CLOCK_MONOTONIC, &last_action_time); } } return request_len; } #if !defined(NO_CGI) || !defined(NO_FILES) static int forward_body_data(struct mg_connection *conn, FILE *fp, SOCKET sock, SSL *ssl) { const char *expect, *body; char buf[MG_BUF_LEN]; int to_read, nread, success = 0; int64_t buffered_len; double timeout = -1.0; if (!conn) { return 0; } if (conn->dom_ctx->config[REQUEST_TIMEOUT]) { timeout = atoi(conn->dom_ctx->config[REQUEST_TIMEOUT]) / 1000.0; } expect = mg_get_header(conn, "Expect"); DEBUG_ASSERT(fp != NULL); if (!fp) { mg_send_http_error(conn, 500, "%s", "Error: NULL File"); return 0; } if ((conn->content_len == -1) && (!conn->is_chunked)) { /* Content length is not specified by the client. */ mg_send_http_error(conn, 411, "%s", "Error: Client did not specify content length"); } else if ((expect != NULL) && (mg_strcasecmp(expect, "100-continue") != 0)) { /* Client sent an "Expect: xyz" header and xyz is not 100-continue. */ mg_send_http_error(conn, 417, "Error: Can not fulfill expectation %s", expect); } else { if (expect != NULL) { (void)mg_printf(conn, "%s", "HTTP/1.1 100 Continue\r\n\r\n"); conn->status_code = 100; } else { conn->status_code = 200; } buffered_len = (int64_t)(conn->data_len) - (int64_t)conn->request_len - conn->consumed_content; DEBUG_ASSERT(buffered_len >= 0); DEBUG_ASSERT(conn->consumed_content == 0); if ((buffered_len < 0) || (conn->consumed_content != 0)) { mg_send_http_error(conn, 500, "%s", "Error: Size mismatch"); return 0; } if (buffered_len > 0) { if ((int64_t)buffered_len > conn->content_len) { buffered_len = (int)conn->content_len; } body = conn->buf + conn->request_len + conn->consumed_content; push_all( conn->phys_ctx, fp, sock, ssl, body, (int64_t)buffered_len); conn->consumed_content += buffered_len; } nread = 0; while (conn->consumed_content < conn->content_len) { to_read = sizeof(buf); if ((int64_t)to_read > conn->content_len - conn->consumed_content) { to_read = (int)(conn->content_len - conn->consumed_content); } nread = pull_inner(NULL, conn, buf, to_read, timeout); if (nread == -2) { /* error */ break; } if (nread > 0) { if (push_all(conn->phys_ctx, fp, sock, ssl, buf, nread) != nread) { break; } } conn->consumed_content += nread; } if (conn->consumed_content == conn->content_len) { success = (nread >= 0); } /* Each error code path in this function must send an error */ if (!success) { /* NOTE: Maybe some data has already been sent. */ /* TODO (low): If some data has been sent, a correct error * reply can no longer be sent, so just close the connection */ mg_send_http_error(conn, 500, "%s", ""); } } return success; } #endif #if defined(USE_TIMERS) #define TIMER_API static #include "timer.inl" #endif /* USE_TIMERS */ #if !defined(NO_CGI) /* This structure helps to create an environment for the spawned CGI * program. * Environment is an array of "VARIABLE=VALUE\0" ASCIIZ strings, * last element must be NULL. * However, on Windows there is a requirement that all these * VARIABLE=VALUE\0 * strings must reside in a contiguous buffer. The end of the buffer is * marked by two '\0' characters. * We satisfy both worlds: we create an envp array (which is vars), all * entries are actually pointers inside buf. */ struct cgi_environment { struct mg_connection *conn; /* Data block */ char *buf; /* Environment buffer */ size_t buflen; /* Space available in buf */ size_t bufused; /* Space taken in buf */ /* Index block */ char **var; /* char **envp */ size_t varlen; /* Number of variables available in var */ size_t varused; /* Number of variables stored in var */ }; static void addenv(struct cgi_environment *env, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(2, 3); /* Append VARIABLE=VALUE\0 string to the buffer, and add a respective * pointer into the vars array. Assumes env != NULL and fmt != NULL. */ static void addenv(struct cgi_environment *env, const char *fmt, ...) { size_t n, space; int truncated = 0; char *added; va_list ap; /* Calculate how much space is left in the buffer */ space = (env->buflen - env->bufused); /* Calculate an estimate for the required space */ n = strlen(fmt) + 2 + 128; do { if (space <= n) { /* Allocate new buffer */ n = env->buflen + CGI_ENVIRONMENT_SIZE; added = (char *)mg_realloc_ctx(env->buf, n, env->conn->phys_ctx); if (!added) { /* Out of memory */ mg_cry_internal( env->conn, "%s: Cannot allocate memory for CGI variable [%s]", __func__, fmt); return; } env->buf = added; env->buflen = n; space = (env->buflen - env->bufused); } /* Make a pointer to the free space int the buffer */ added = env->buf + env->bufused; /* Copy VARIABLE=VALUE\0 string into the free space */ va_start(ap, fmt); mg_vsnprintf(env->conn, &truncated, added, (size_t)space, fmt, ap); va_end(ap); /* Do not add truncated strings to the environment */ if (truncated) { /* Reallocate the buffer */ space = 0; n = 1; } } while (truncated); /* Calculate number of bytes added to the environment */ n = strlen(added) + 1; env->bufused += n; /* Now update the variable index */ space = (env->varlen - env->varused); if (space < 2) { mg_cry_internal(env->conn, "%s: Cannot register CGI variable [%s]", __func__, fmt); return; } /* Append a pointer to the added string into the envp array */ env->var[env->varused] = added; env->varused++; } /* Return 0 on success, non-zero if an error occurs. */ static int prepare_cgi_environment(struct mg_connection *conn, const char *prog, struct cgi_environment *env) { const char *s; struct vec var_vec; char *p, src_addr[IP_ADDR_STR_LEN], http_var_name[128]; int i, truncated, uri_len; if ((conn == NULL) || (prog == NULL) || (env == NULL)) { return -1; } env->conn = conn; env->buflen = CGI_ENVIRONMENT_SIZE; env->bufused = 0; env->buf = (char *)mg_malloc_ctx(env->buflen, conn->phys_ctx); if (env->buf == NULL) { mg_cry_internal(conn, "%s: Not enough memory for environmental buffer", __func__); return -1; } env->varlen = MAX_CGI_ENVIR_VARS; env->varused = 0; env->var = (char **)mg_malloc_ctx(env->buflen * sizeof(char *), conn->phys_ctx); if (env->var == NULL) { mg_cry_internal(conn, "%s: Not enough memory for environmental variables", __func__); mg_free(env->buf); return -1; } addenv(env, "SERVER_NAME=%s", conn->dom_ctx->config[AUTHENTICATION_DOMAIN]); addenv(env, "SERVER_ROOT=%s", conn->dom_ctx->config[DOCUMENT_ROOT]); addenv(env, "DOCUMENT_ROOT=%s", conn->dom_ctx->config[DOCUMENT_ROOT]); addenv(env, "SERVER_SOFTWARE=CivetWeb/%s", mg_version()); /* Prepare the environment block */ addenv(env, "%s", "GATEWAY_INTERFACE=CGI/1.1"); addenv(env, "%s", "SERVER_PROTOCOL=HTTP/1.1"); addenv(env, "%s", "REDIRECT_STATUS=200"); /* For PHP */ #if defined(USE_IPV6) if (conn->client.lsa.sa.sa_family == AF_INET6) { addenv(env, "SERVER_PORT=%d", ntohs(conn->client.lsa.sin6.sin6_port)); } else #endif { addenv(env, "SERVER_PORT=%d", ntohs(conn->client.lsa.sin.sin_port)); } sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa); addenv(env, "REMOTE_ADDR=%s", src_addr); addenv(env, "REQUEST_METHOD=%s", conn->request_info.request_method); addenv(env, "REMOTE_PORT=%d", conn->request_info.remote_port); addenv(env, "REQUEST_URI=%s", conn->request_info.request_uri); addenv(env, "LOCAL_URI=%s", conn->request_info.local_uri); /* SCRIPT_NAME */ uri_len = (int)strlen(conn->request_info.local_uri); if (conn->path_info == NULL) { if (conn->request_info.local_uri[uri_len - 1] != '/') { /* URI: /path_to_script/script.cgi */ addenv(env, "SCRIPT_NAME=%s", conn->request_info.local_uri); } else { /* URI: /path_to_script/ ... using index.cgi */ const char *index_file = strrchr(prog, '/'); if (index_file) { addenv(env, "SCRIPT_NAME=%s%s", conn->request_info.local_uri, index_file + 1); } } } else { /* URI: /path_to_script/script.cgi/path_info */ addenv(env, "SCRIPT_NAME=%.*s", uri_len - (int)strlen(conn->path_info), conn->request_info.local_uri); } addenv(env, "SCRIPT_FILENAME=%s", prog); if (conn->path_info == NULL) { addenv(env, "PATH_TRANSLATED=%s", conn->dom_ctx->config[DOCUMENT_ROOT]); } else { addenv(env, "PATH_TRANSLATED=%s%s", conn->dom_ctx->config[DOCUMENT_ROOT], conn->path_info); } addenv(env, "HTTPS=%s", (conn->ssl == NULL) ? "off" : "on"); if ((s = mg_get_header(conn, "Content-Type")) != NULL) { addenv(env, "CONTENT_TYPE=%s", s); } if (conn->request_info.query_string != NULL) { addenv(env, "QUERY_STRING=%s", conn->request_info.query_string); } if ((s = mg_get_header(conn, "Content-Length")) != NULL) { addenv(env, "CONTENT_LENGTH=%s", s); } if ((s = getenv("PATH")) != NULL) { addenv(env, "PATH=%s", s); } if (conn->path_info != NULL) { addenv(env, "PATH_INFO=%s", conn->path_info); } if (conn->status_code > 0) { /* CGI error handler should show the status code */ addenv(env, "STATUS=%d", conn->status_code); } #if defined(_WIN32) if ((s = getenv("COMSPEC")) != NULL) { addenv(env, "COMSPEC=%s", s); } if ((s = getenv("SYSTEMROOT")) != NULL) { addenv(env, "SYSTEMROOT=%s", s); } if ((s = getenv("SystemDrive")) != NULL) { addenv(env, "SystemDrive=%s", s); } if ((s = getenv("ProgramFiles")) != NULL) { addenv(env, "ProgramFiles=%s", s); } if ((s = getenv("ProgramFiles(x86)")) != NULL) { addenv(env, "ProgramFiles(x86)=%s", s); } #else if ((s = getenv("LD_LIBRARY_PATH")) != NULL) { addenv(env, "LD_LIBRARY_PATH=%s", s); } #endif /* _WIN32 */ if ((s = getenv("PERLLIB")) != NULL) { addenv(env, "PERLLIB=%s", s); } if (conn->request_info.remote_user != NULL) { addenv(env, "REMOTE_USER=%s", conn->request_info.remote_user); addenv(env, "%s", "AUTH_TYPE=Digest"); } /* Add all headers as HTTP_* variables */ for (i = 0; i < conn->request_info.num_headers; i++) { (void)mg_snprintf(conn, &truncated, http_var_name, sizeof(http_var_name), "HTTP_%s", conn->request_info.http_headers[i].name); if (truncated) { mg_cry_internal(conn, "%s: HTTP header variable too long [%s]", __func__, conn->request_info.http_headers[i].name); continue; } /* Convert variable name into uppercase, and change - to _ */ for (p = http_var_name; *p != '\0'; p++) { if (*p == '-') { *p = '_'; } *p = (char)toupper((unsigned char)*p); } addenv(env, "%s=%s", http_var_name, conn->request_info.http_headers[i].value); } /* Add user-specified variables */ s = conn->dom_ctx->config[CGI_ENVIRONMENT]; while ((s = next_option(s, &var_vec, NULL)) != NULL) { addenv(env, "%.*s", (int)var_vec.len, var_vec.ptr); } env->var[env->varused] = NULL; env->buf[env->bufused] = '\0'; return 0; } /* Data for CGI process control: PID and number of references */ struct process_control_data { pid_t pid; int references; }; static int abort_process(void *data) { /* Waitpid checks for child status and won't work for a pid that does not * identify a child of the current process. Thus, if the pid is reused, * we will not affect a different process. */ struct process_control_data *proc = (struct process_control_data *)data; int status = 0; int refs; pid_t ret_pid; ret_pid = waitpid(proc->pid, &status, WNOHANG); if ((ret_pid != (pid_t)-1) && (status == 0)) { /* Stop child process */ DEBUG_TRACE("CGI timer: Stop child process %p\n", proc->pid); kill(proc->pid, SIGABRT); /* Wait until process is terminated (don't leave zombies) */ while (waitpid(proc->pid, &status, 0) != (pid_t)-1) /* nop */ ; } else { DEBUG_TRACE("CGI timer: Child process %p already stopped\n", proc->pid); } /* Dec reference counter */ refs = mg_atomic_dec(&proc->references); if (refs == 0) { /* no more references - free data */ mg_free(data); } return 0; } static void handle_cgi_request(struct mg_connection *conn, const char *prog) { char *buf; size_t buflen; int headers_len, data_len, i, truncated; int fdin[2] = {-1, -1}, fdout[2] = {-1, -1}, fderr[2] = {-1, -1}; const char *status, *status_text, *connection_state; char *pbuf, dir[PATH_MAX], *p; struct mg_request_info ri; struct cgi_environment blk; FILE *in = NULL, *out = NULL, *err = NULL; struct mg_file fout = STRUCT_FILE_INITIALIZER; pid_t pid = (pid_t)-1; struct process_control_data *proc = NULL; #if defined(USE_TIMERS) double cgi_timeout = -1.0; if (conn->dom_ctx->config[CGI_TIMEOUT]) { /* Get timeout in seconds */ cgi_timeout = atof(conn->dom_ctx->config[CGI_TIMEOUT]) * 0.001; } #endif if (conn == NULL) { return; } buf = NULL; buflen = conn->phys_ctx->max_request_size; i = prepare_cgi_environment(conn, prog, &blk); if (i != 0) { blk.buf = NULL; blk.var = NULL; goto done; } /* CGI must be executed in its own directory. 'dir' must point to the * directory containing executable program, 'p' must point to the * executable program name relative to 'dir'. */ (void)mg_snprintf(conn, &truncated, dir, sizeof(dir), "%s", prog); if (truncated) { mg_cry_internal(conn, "Error: CGI program \"%s\": Path too long", prog); mg_send_http_error(conn, 500, "Error: %s", "CGI path too long"); goto done; } if ((p = strrchr(dir, '/')) != NULL) { *p++ = '\0'; } else { dir[0] = '.'; dir[1] = '\0'; p = (char *)prog; } if ((pipe(fdin) != 0) || (pipe(fdout) != 0) || (pipe(fderr) != 0)) { status = strerror(ERRNO); mg_cry_internal( conn, "Error: CGI program \"%s\": Can not create CGI pipes: %s", prog, status); mg_send_http_error(conn, 500, "Error: Cannot create CGI pipe: %s", status); goto done; } proc = (struct process_control_data *) mg_malloc_ctx(sizeof(struct process_control_data), conn->phys_ctx); if (proc == NULL) { mg_cry_internal(conn, "Error: CGI program \"%s\": Out or memory", prog); mg_send_http_error(conn, 500, "Error: Out of memory [%s]", prog); goto done; } DEBUG_TRACE("CGI: spawn %s %s\n", dir, p); pid = spawn_process(conn, p, blk.buf, blk.var, fdin, fdout, fderr, dir); if (pid == (pid_t)-1) { status = strerror(ERRNO); mg_cry_internal( conn, "Error: CGI program \"%s\": Can not spawn CGI process: %s", prog, status); mg_send_http_error(conn, 500, "Error: Cannot spawn CGI process [%s]: %s", prog, status); mg_free(proc); proc = NULL; goto done; } /* Store data in shared process_control_data */ proc->pid = pid; proc->references = 1; #if defined(USE_TIMERS) if (cgi_timeout > 0.0) { proc->references = 2; // Start a timer for CGI timer_add(conn->phys_ctx, cgi_timeout /* in seconds */, 0.0, 1, abort_process, (void *)proc); } #endif /* Make sure child closes all pipe descriptors. It must dup them to 0,1 */ set_close_on_exec((SOCKET)fdin[0], conn); /* stdin read */ set_close_on_exec((SOCKET)fdin[1], conn); /* stdin write */ set_close_on_exec((SOCKET)fdout[0], conn); /* stdout read */ set_close_on_exec((SOCKET)fdout[1], conn); /* stdout write */ set_close_on_exec((SOCKET)fderr[0], conn); /* stderr read */ set_close_on_exec((SOCKET)fderr[1], conn); /* stderr write */ /* Parent closes only one side of the pipes. * If we don't mark them as closed, close() attempt before * return from this function throws an exception on Windows. * Windows does not like when closed descriptor is closed again. */ (void)close(fdin[0]); (void)close(fdout[1]); (void)close(fderr[1]); fdin[0] = fdout[1] = fderr[1] = -1; if ((in = fdopen(fdin[1], "wb")) == NULL) { status = strerror(ERRNO); mg_cry_internal(conn, "Error: CGI program \"%s\": Can not open stdin: %s", prog, status); mg_send_http_error(conn, 500, "Error: CGI can not open fdin\nfopen: %s", status); goto done; } if ((out = fdopen(fdout[0], "rb")) == NULL) { status = strerror(ERRNO); mg_cry_internal(conn, "Error: CGI program \"%s\": Can not open stdout: %s", prog, status); mg_send_http_error(conn, 500, "Error: CGI can not open fdout\nfopen: %s", status); goto done; } if ((err = fdopen(fderr[0], "rb")) == NULL) { status = strerror(ERRNO); mg_cry_internal(conn, "Error: CGI program \"%s\": Can not open stderr: %s", prog, status); mg_send_http_error(conn, 500, "Error: CGI can not open fderr\nfopen: %s", status); goto done; } setbuf(in, NULL); setbuf(out, NULL); setbuf(err, NULL); fout.access.fp = out; if ((conn->request_info.content_length != 0) || (conn->is_chunked)) { DEBUG_TRACE("CGI: send body data (%lli)\n", (signed long long)conn->request_info.content_length); /* This is a POST/PUT request, or another request with body data. */ if (!forward_body_data(conn, in, INVALID_SOCKET, NULL)) { /* Error sending the body data */ mg_cry_internal( conn, "Error: CGI program \"%s\": Forward body data failed", prog); goto done; } } /* Close so child gets an EOF. */ fclose(in); in = NULL; fdin[1] = -1; /* Now read CGI reply into a buffer. We need to set correct * status code, thus we need to see all HTTP headers first. * Do not send anything back to client, until we buffer in all * HTTP headers. */ data_len = 0; buf = (char *)mg_malloc_ctx(buflen, conn->phys_ctx); if (buf == NULL) { mg_send_http_error(conn, 500, "Error: Not enough memory for CGI buffer (%u bytes)", (unsigned int)buflen); mg_cry_internal( conn, "Error: CGI program \"%s\": Not enough memory for buffer (%u " "bytes)", prog, (unsigned int)buflen); goto done; } DEBUG_TRACE("CGI: %s", "wait for response"); headers_len = read_message(out, conn, buf, (int)buflen, &data_len); DEBUG_TRACE("CGI: response: %li", (signed long)headers_len); if (headers_len <= 0) { /* Could not parse the CGI response. Check if some error message on * stderr. */ i = pull_all(err, conn, buf, (int)buflen); if (i > 0) { /* CGI program explicitly sent an error */ /* Write the error message to the internal log */ mg_cry_internal(conn, "Error: CGI program \"%s\" sent error " "message: [%.*s]", prog, i, buf); /* Don't send the error message back to the client */ mg_send_http_error(conn, 500, "Error: CGI program \"%s\" failed.", prog); } else { /* CGI program did not explicitly send an error, but a broken * respon header */ mg_cry_internal(conn, "Error: CGI program sent malformed or too big " "(>%u bytes) HTTP headers: [%.*s]", (unsigned)buflen, data_len, buf); mg_send_http_error(conn, 500, "Error: CGI program sent malformed or too big " "(>%u bytes) HTTP headers: [%.*s]", (unsigned)buflen, data_len, buf); } /* in both cases, abort processing CGI */ goto done; } pbuf = buf; buf[headers_len - 1] = '\0'; ri.num_headers = parse_http_headers(&pbuf, ri.http_headers); /* Make up and send the status line */ status_text = "OK"; if ((status = get_header(ri.http_headers, ri.num_headers, "Status")) != NULL) { conn->status_code = atoi(status); status_text = status; while (isdigit((unsigned char)*status_text) || *status_text == ' ') { status_text++; } } else if (get_header(ri.http_headers, ri.num_headers, "Location") != NULL) { conn->status_code = 307; } else { conn->status_code = 200; } connection_state = get_header(ri.http_headers, ri.num_headers, "Connection"); if (!header_has_option(connection_state, "keep-alive")) { conn->must_close = 1; } DEBUG_TRACE("CGI: response %u %s", conn->status_code, status_text); (void)mg_printf(conn, "HTTP/1.1 %d %s\r\n", conn->status_code, status_text); /* Send headers */ for (i = 0; i < ri.num_headers; i++) { mg_printf(conn, "%s: %s\r\n", ri.http_headers[i].name, ri.http_headers[i].value); } mg_write(conn, "\r\n", 2); /* Send chunk of data that may have been read after the headers */ mg_write(conn, buf + headers_len, (size_t)(data_len - headers_len)); /* Read the rest of CGI output and send to the client */ DEBUG_TRACE("CGI: %s", "forward all data"); send_file_data(conn, &fout, 0, INT64_MAX); DEBUG_TRACE("CGI: %s", "all data sent"); done: mg_free(blk.var); mg_free(blk.buf); if (pid != (pid_t)-1) { abort_process((void *)proc); } if (fdin[0] != -1) { close(fdin[0]); } if (fdout[1] != -1) { close(fdout[1]); } if (in != NULL) { fclose(in); } else if (fdin[1] != -1) { close(fdin[1]); } if (out != NULL) { fclose(out); } else if (fdout[0] != -1) { close(fdout[0]); } if (err != NULL) { fclose(err); } else if (fderr[0] != -1) { close(fderr[0]); } if (buf != NULL) { mg_free(buf); } } #endif /* !NO_CGI */ #if !defined(NO_FILES) static void mkcol(struct mg_connection *conn, const char *path) { int rc, body_len; struct de de; char date[64]; time_t curtime = time(NULL); if (conn == NULL) { return; } /* TODO (mid): Check the mg_send_http_error situations in this function */ memset(&de.file, 0, sizeof(de.file)); if (!mg_stat(conn, path, &de.file)) { mg_cry_internal(conn, "%s: mg_stat(%s) failed: %s", __func__, path, strerror(ERRNO)); } if (de.file.last_modified) { /* TODO (mid): This check does not seem to make any sense ! */ /* TODO (mid): Add a webdav unit test first, before changing * anything here. */ mg_send_http_error( conn, 405, "Error: mkcol(%s): %s", path, strerror(ERRNO)); return; } body_len = conn->data_len - conn->request_len; if (body_len > 0) { mg_send_http_error( conn, 415, "Error: mkcol(%s): %s", path, strerror(ERRNO)); return; } rc = mg_mkdir(conn, path, 0755); if (rc == 0) { conn->status_code = 201; gmt_time_string(date, sizeof(date), &curtime); mg_printf(conn, "HTTP/1.1 %d Created\r\n" "Date: %s\r\n", conn->status_code, date); send_static_cache_header(conn); send_additional_header(conn); mg_printf(conn, "Content-Length: 0\r\n" "Connection: %s\r\n\r\n", suggest_connection_header(conn)); } else { if (errno == EEXIST) { mg_send_http_error( conn, 405, "Error: mkcol(%s): %s", path, strerror(ERRNO)); } else if (errno == EACCES) { mg_send_http_error( conn, 403, "Error: mkcol(%s): %s", path, strerror(ERRNO)); } else if (errno == ENOENT) { mg_send_http_error( conn, 409, "Error: mkcol(%s): %s", path, strerror(ERRNO)); } else { mg_send_http_error( conn, 500, "fopen(%s): %s", path, strerror(ERRNO)); } } } static void put_file(struct mg_connection *conn, const char *path) { struct mg_file file = STRUCT_FILE_INITIALIZER; const char *range; int64_t r1, r2; int rc; char date[64]; time_t curtime = time(NULL); if (conn == NULL) { return; } if (mg_stat(conn, path, &file.stat)) { /* File already exists */ conn->status_code = 200; if (file.stat.is_directory) { /* This is an already existing directory, * so there is nothing to do for the server. */ rc = 0; } else { /* File exists and is not a directory. */ /* Can it be replaced? */ #if defined(MG_USE_OPEN_FILE) if (file.access.membuf != NULL) { /* This is an "in-memory" file, that can not be replaced */ mg_send_http_error(conn, 405, "Error: Put not possible\nReplacing %s " "is not supported", path); return; } #endif /* Check if the server may write this file */ if (access(path, W_OK) == 0) { /* Access granted */ conn->status_code = 200; rc = 1; } else { mg_send_http_error( conn, 403, "Error: Put not possible\nReplacing %s is not allowed", path); return; } } } else { /* File should be created */ conn->status_code = 201; rc = put_dir(conn, path); } if (rc == 0) { /* put_dir returns 0 if path is a directory */ gmt_time_string(date, sizeof(date), &curtime); mg_printf(conn, "HTTP/1.1 %d %s\r\n", conn->status_code, mg_get_response_code_text(NULL, conn->status_code)); send_no_cache_header(conn); send_additional_header(conn); mg_printf(conn, "Date: %s\r\n" "Content-Length: 0\r\n" "Connection: %s\r\n\r\n", date, suggest_connection_header(conn)); /* Request to create a directory has been fulfilled successfully. * No need to put a file. */ return; } if (rc == -1) { /* put_dir returns -1 if the path is too long */ mg_send_http_error(conn, 414, "Error: Path too long\nput_dir(%s): %s", path, strerror(ERRNO)); return; } if (rc == -2) { /* put_dir returns -2 if the directory can not be created */ mg_send_http_error(conn, 500, "Error: Can not create directory\nput_dir(%s): %s", path, strerror(ERRNO)); return; } /* A file should be created or overwritten. */ /* Currently CivetWeb does not nead read+write access. */ if (!mg_fopen(conn, path, MG_FOPEN_MODE_WRITE, &file) || file.access.fp == NULL) { (void)mg_fclose(&file.access); mg_send_http_error(conn, 500, "Error: Can not create file\nfopen(%s): %s", path, strerror(ERRNO)); return; } fclose_on_exec(&file.access, conn); range = mg_get_header(conn, "Content-Range"); r1 = r2 = 0; if ((range != NULL) && parse_range_header(range, &r1, &r2) > 0) { conn->status_code = 206; /* Partial content */ fseeko(file.access.fp, r1, SEEK_SET); } if (!forward_body_data(conn, file.access.fp, INVALID_SOCKET, NULL)) { /* forward_body_data failed. * The error code has already been sent to the client, * and conn->status_code is already set. */ (void)mg_fclose(&file.access); return; } if (mg_fclose(&file.access) != 0) { /* fclose failed. This might have different reasons, but a likely * one is "no space on disk", http 507. */ conn->status_code = 507; } gmt_time_string(date, sizeof(date), &curtime); mg_printf(conn, "HTTP/1.1 %d %s\r\n", conn->status_code, mg_get_response_code_text(NULL, conn->status_code)); send_no_cache_header(conn); send_additional_header(conn); mg_printf(conn, "Date: %s\r\n" "Content-Length: 0\r\n" "Connection: %s\r\n\r\n", date, suggest_connection_header(conn)); } static void delete_file(struct mg_connection *conn, const char *path) { struct de de; memset(&de.file, 0, sizeof(de.file)); if (!mg_stat(conn, path, &de.file)) { /* mg_stat returns 0 if the file does not exist */ mg_send_http_error(conn, 404, "Error: Cannot delete file\nFile %s not found", path); return; } #if 0 /* Ignore if a file in memory is inside a folder */ if (de.access.membuf != NULL) { /* the file is cached in memory */ mg_send_http_error( conn, 405, "Error: Delete not possible\nDeleting %s is not supported", path); return; } #endif if (de.file.is_directory) { if (remove_directory(conn, path)) { /* Delete is successful: Return 204 without content. */ mg_send_http_error(conn, 204, "%s", ""); } else { /* Delete is not successful: Return 500 (Server error). */ mg_send_http_error(conn, 500, "Error: Could not delete %s", path); } return; } /* This is an existing file (not a directory). * Check if write permission is granted. */ if (access(path, W_OK) != 0) { /* File is read only */ mg_send_http_error( conn, 403, "Error: Delete not possible\nDeleting %s is not allowed", path); return; } /* Try to delete it. */ if (mg_remove(conn, path) == 0) { /* Delete was successful: Return 204 without content. */ mg_send_http_error(conn, 204, "%s", ""); } else { /* Delete not successful (file locked). */ mg_send_http_error(conn, 423, "Error: Cannot delete file\nremove(%s): %s", path, strerror(ERRNO)); } } #endif /* !NO_FILES */ static void send_ssi_file(struct mg_connection *, const char *, struct mg_file *, int); static void do_ssi_include(struct mg_connection *conn, const char *ssi, char *tag, int include_level) { char file_name[MG_BUF_LEN], path[512], *p; struct mg_file file = STRUCT_FILE_INITIALIZER; size_t len; int truncated = 0; if (conn == NULL) { return; } /* sscanf() is safe here, since send_ssi_file() also uses buffer * of size MG_BUF_LEN to get the tag. So strlen(tag) is * always < MG_BUF_LEN. */ if (sscanf(tag, " virtual=\"%511[^\"]\"", file_name) == 1) { /* File name is relative to the webserver root */ file_name[511] = 0; (void)mg_snprintf(conn, &truncated, path, sizeof(path), "%s/%s", conn->dom_ctx->config[DOCUMENT_ROOT], file_name); } else if (sscanf(tag, " abspath=\"%511[^\"]\"", file_name) == 1) { /* File name is relative to the webserver working directory * or it is absolute system path */ file_name[511] = 0; (void) mg_snprintf(conn, &truncated, path, sizeof(path), "%s", file_name); } else if ((sscanf(tag, " file=\"%511[^\"]\"", file_name) == 1) || (sscanf(tag, " \"%511[^\"]\"", file_name) == 1)) { /* File name is relative to the currect document */ file_name[511] = 0; (void)mg_snprintf(conn, &truncated, path, sizeof(path), "%s", ssi); if (!truncated) { if ((p = strrchr(path, '/')) != NULL) { p[1] = '\0'; } len = strlen(path); (void)mg_snprintf(conn, &truncated, path + len, sizeof(path) - len, "%s", file_name); } } else { mg_cry_internal(conn, "Bad SSI #include: [%s]", tag); return; } if (truncated) { mg_cry_internal(conn, "SSI #include path length overflow: [%s]", tag); return; } if (!mg_fopen(conn, path, MG_FOPEN_MODE_READ, &file)) { mg_cry_internal(conn, "Cannot open SSI #include: [%s]: fopen(%s): %s", tag, path, strerror(ERRNO)); } else { fclose_on_exec(&file.access, conn); if (match_prefix(conn->dom_ctx->config[SSI_EXTENSIONS], strlen(conn->dom_ctx->config[SSI_EXTENSIONS]), path) > 0) { send_ssi_file(conn, path, &file, include_level + 1); } else { send_file_data(conn, &file, 0, INT64_MAX); } (void)mg_fclose(&file.access); /* Ignore errors for readonly files */ } } #if !defined(NO_POPEN) static void do_ssi_exec(struct mg_connection *conn, char *tag) { char cmd[1024] = ""; struct mg_file file = STRUCT_FILE_INITIALIZER; if (sscanf(tag, " \"%1023[^\"]\"", cmd) != 1) { mg_cry_internal(conn, "Bad SSI #exec: [%s]", tag); } else { cmd[1023] = 0; if ((file.access.fp = popen(cmd, "r")) == NULL) { mg_cry_internal(conn, "Cannot SSI #exec: [%s]: %s", cmd, strerror(ERRNO)); } else { send_file_data(conn, &file, 0, INT64_MAX); pclose(file.access.fp); } } } #endif /* !NO_POPEN */ static int mg_fgetc(struct mg_file *filep, int offset) { (void)offset; /* unused in case MG_USE_OPEN_FILE is set */ if (filep == NULL) { return EOF; } #if defined(MG_USE_OPEN_FILE) if ((filep->access.membuf != NULL) && (offset >= 0) && (((unsigned int)(offset)) < filep->stat.size)) { return ((const unsigned char *)filep->access.membuf)[offset]; } else /* else block below */ #endif if (filep->access.fp != NULL) { return fgetc(filep->access.fp); } else { return EOF; } } static void send_ssi_file(struct mg_connection *conn, const char *path, struct mg_file *filep, int include_level) { char buf[MG_BUF_LEN]; int ch, offset, len, in_tag, in_ssi_tag; if (include_level > 10) { mg_cry_internal(conn, "SSI #include level is too deep (%s)", path); return; } in_tag = in_ssi_tag = len = offset = 0; /* Read file, byte by byte, and look for SSI include tags */ while ((ch = mg_fgetc(filep, offset++)) != EOF) { if (in_tag) { /* We are in a tag, either SSI tag or html tag */ if (ch == '>') { /* Tag is closing */ buf[len++] = '>'; if (in_ssi_tag) { /* Handle SSI tag */ buf[len] = 0; if ((len > 12) && !memcmp(buf + 5, "include", 7)) { do_ssi_include(conn, path, buf + 12, include_level + 1); #if !defined(NO_POPEN) } else if ((len > 9) && !memcmp(buf + 5, "exec", 4)) { do_ssi_exec(conn, buf + 9); #endif /* !NO_POPEN */ } else { mg_cry_internal(conn, "%s: unknown SSI " "command: \"%s\"", path, buf); } len = 0; in_ssi_tag = in_tag = 0; } else { /* Not an SSI tag */ /* Flush buffer */ (void)mg_write(conn, buf, (size_t)len); len = 0; in_tag = 0; } } else { /* Tag is still open */ buf[len++] = (char)(ch & 0xff); if ((len == 5) && !memcmp(buf, "<!--#", 5)) { /* All SSI tags start with <!--# */ in_ssi_tag = 1; } if ((len + 2) > (int)sizeof(buf)) { /* Tag to long for buffer */ mg_cry_internal(conn, "%s: tag is too large", path); return; } } } else { /* We are not in a tag yet. */ if (ch == '<') { /* Tag is opening */ in_tag = 1; if (len > 0) { /* Flush current buffer. * Buffer is filled with "len" bytes. */ (void)mg_write(conn, buf, (size_t)len); } /* Store the < */ len = 1; buf[0] = '<'; } else { /* No Tag */ /* Add data to buffer */ buf[len++] = (char)(ch & 0xff); /* Flush if buffer is full */ if (len == (int)sizeof(buf)) { mg_write(conn, buf, (size_t)len); len = 0; } } } } /* Send the rest of buffered data */ if (len > 0) { mg_write(conn, buf, (size_t)len); } } static void handle_ssi_file_request(struct mg_connection *conn, const char *path, struct mg_file *filep) { char date[64]; time_t curtime = time(NULL); const char *cors_orig_cfg; const char *cors1, *cors2, *cors3; if ((conn == NULL) || (path == NULL) || (filep == NULL)) { return; } cors_orig_cfg = conn->dom_ctx->config[ACCESS_CONTROL_ALLOW_ORIGIN]; if (cors_orig_cfg && *cors_orig_cfg && mg_get_header(conn, "Origin")) { /* Cross-origin resource sharing (CORS). */ cors1 = "Access-Control-Allow-Origin: "; cors2 = cors_orig_cfg; cors3 = "\r\n"; } else { cors1 = cors2 = cors3 = ""; } if (!mg_fopen(conn, path, MG_FOPEN_MODE_READ, filep)) { /* File exists (precondition for calling this function), * but can not be opened by the server. */ mg_send_http_error(conn, 500, "Error: Cannot read file\nfopen(%s): %s", path, strerror(ERRNO)); } else { conn->must_close = 1; gmt_time_string(date, sizeof(date), &curtime); fclose_on_exec(&filep->access, conn); mg_printf(conn, "HTTP/1.1 200 OK\r\n"); send_no_cache_header(conn); send_additional_header(conn); mg_printf(conn, "%s%s%s" "Date: %s\r\n" "Content-Type: text/html\r\n" "Connection: %s\r\n\r\n", cors1, cors2, cors3, date, suggest_connection_header(conn)); send_ssi_file(conn, path, filep, 0); (void)mg_fclose(&filep->access); /* Ignore errors for readonly files */ } } #if !defined(NO_FILES) static void send_options(struct mg_connection *conn) { char date[64]; time_t curtime = time(NULL); if (!conn) { return; } conn->status_code = 200; conn->must_close = 1; gmt_time_string(date, sizeof(date), &curtime); /* We do not set a "Cache-Control" header here, but leave the default. * Since browsers do not send an OPTIONS request, we can not test the * effect anyway. */ mg_printf(conn, "HTTP/1.1 200 OK\r\n" "Date: %s\r\n" "Connection: %s\r\n" "Allow: GET, POST, HEAD, CONNECT, PUT, DELETE, OPTIONS, " "PROPFIND, MKCOL\r\n" "DAV: 1\r\n", date, suggest_connection_header(conn)); send_additional_header(conn); mg_printf(conn, "\r\n"); } /* Writes PROPFIND properties for a collection element */ static void print_props(struct mg_connection *conn, const char *uri, struct mg_file_stat *filep) { char mtime[64]; if ((conn == NULL) || (uri == NULL) || (filep == NULL)) { return; } gmt_time_string(mtime, sizeof(mtime), &filep->last_modified); mg_printf(conn, "<d:response>" "<d:href>%s</d:href>" "<d:propstat>" "<d:prop>" "<d:resourcetype>%s</d:resourcetype>" "<d:getcontentlength>%" INT64_FMT "</d:getcontentlength>" "<d:getlastmodified>%s</d:getlastmodified>" "</d:prop>" "<d:status>HTTP/1.1 200 OK</d:status>" "</d:propstat>" "</d:response>\n", uri, filep->is_directory ? "<d:collection/>" : "", filep->size, mtime); } static int print_dav_dir_entry(struct de *de, void *data) { char href[PATH_MAX]; int truncated; struct mg_connection *conn = (struct mg_connection *)data; if (!de || !conn) { return -1; } mg_snprintf(conn, &truncated, href, sizeof(href), "%s%s", conn->request_info.local_uri, de->file_name); if (!truncated) { size_t href_encoded_size; char *href_encoded; href_encoded_size = PATH_MAX * 3; /* worst case */ href_encoded = (char *)mg_malloc(href_encoded_size); if (href_encoded == NULL) { return -1; } mg_url_encode(href, href_encoded, href_encoded_size); print_props(conn, href_encoded, &de->file); mg_free(href_encoded); } return 0; } static void handle_propfind(struct mg_connection *conn, const char *path, struct mg_file_stat *filep) { const char *depth = mg_get_header(conn, "Depth"); char date[64]; time_t curtime = time(NULL); gmt_time_string(date, sizeof(date), &curtime); if (!conn || !path || !filep || !conn->dom_ctx) { return; } conn->must_close = 1; conn->status_code = 207; mg_printf(conn, "HTTP/1.1 207 Multi-Status\r\n" "Date: %s\r\n", date); send_static_cache_header(conn); send_additional_header(conn); mg_printf(conn, "Connection: %s\r\n" "Content-Type: text/xml; charset=utf-8\r\n\r\n", suggest_connection_header(conn)); mg_printf(conn, "<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<d:multistatus xmlns:d='DAV:'>\n"); /* Print properties for the requested resource itself */ print_props(conn, conn->request_info.local_uri, filep); /* If it is a directory, print directory entries too if Depth is not 0 */ if (filep->is_directory && !mg_strcasecmp(conn->dom_ctx->config[ENABLE_DIRECTORY_LISTING], "yes") && ((depth == NULL) || (strcmp(depth, "0") != 0))) { scan_directory(conn, path, conn, &print_dav_dir_entry); } mg_printf(conn, "%s\n", "</d:multistatus>"); } #endif void mg_lock_connection(struct mg_connection *conn) { if (conn) { (void)pthread_mutex_lock(&conn->mutex); } } void mg_unlock_connection(struct mg_connection *conn) { if (conn) { (void)pthread_mutex_unlock(&conn->mutex); } } void mg_lock_context(struct mg_context *ctx) { if (ctx) { (void)pthread_mutex_lock(&ctx->nonce_mutex); } } void mg_unlock_context(struct mg_context *ctx) { if (ctx) { (void)pthread_mutex_unlock(&ctx->nonce_mutex); } } #if defined(USE_LUA) #include "mod_lua.inl" #endif /* USE_LUA */ #if defined(USE_DUKTAPE) #include "mod_duktape.inl" #endif /* USE_DUKTAPE */ #if defined(USE_WEBSOCKET) #if !defined(NO_SSL_DL) #define SHA_API static #include "sha1.inl" #endif static int send_websocket_handshake(struct mg_connection *conn, const char *websock_key) { static const char *magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; char buf[100], sha[20], b64_sha[sizeof(sha) * 2]; SHA_CTX sha_ctx; int truncated; /* Calculate Sec-WebSocket-Accept reply from Sec-WebSocket-Key. */ mg_snprintf(conn, &truncated, buf, sizeof(buf), "%s%s", websock_key, magic); if (truncated) { conn->must_close = 1; return 0; } DEBUG_TRACE("%s", "Send websocket handshake"); SHA1_Init(&sha_ctx); SHA1_Update(&sha_ctx, (unsigned char *)buf, (uint32_t)strlen(buf)); SHA1_Final((unsigned char *)sha, &sha_ctx); base64_encode((unsigned char *)sha, sizeof(sha), b64_sha); mg_printf(conn, "HTTP/1.1 101 Switching Protocols\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Accept: %s\r\n", b64_sha); if (conn->request_info.acceptedWebSocketSubprotocol) { mg_printf(conn, "Sec-WebSocket-Protocol: %s\r\n\r\n", conn->request_info.acceptedWebSocketSubprotocol); } else { mg_printf(conn, "%s", "\r\n"); } return 1; } #if !defined(MG_MAX_UNANSWERED_PING) /* Configuration of the maximum number of websocket PINGs that might * stay unanswered before the connection is considered broken. * Note: The name of this define may still change (until it is * defined as a compile parameter in a documentation). */ #define MG_MAX_UNANSWERED_PING (5) #endif static void read_websocket(struct mg_connection *conn, mg_websocket_data_handler ws_data_handler, void *callback_data) { /* Pointer to the beginning of the portion of the incoming websocket * message queue. * The original websocket upgrade request is never removed, so the queue * begins after it. */ unsigned char *buf = (unsigned char *)conn->buf + conn->request_len; int n, error, exit_by_callback; int ret; /* body_len is the length of the entire queue in bytes * len is the length of the current message * data_len is the length of the current message's data payload * header_len is the length of the current message's header */ size_t i, len, mask_len = 0, header_len, body_len; uint64_t data_len = 0; /* "The masking key is a 32-bit value chosen at random by the client." * http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17#section-5 */ unsigned char mask[4]; /* data points to the place where the message is stored when passed to * the websocket_data callback. This is either mem on the stack, or a * dynamically allocated buffer if it is too large. */ unsigned char mem[4096]; unsigned char mop; /* mask flag and opcode */ /* Variables used for connection monitoring */ double timeout = -1.0; int enable_ping_pong = 0; int ping_count = 0; if (conn->dom_ctx->config[ENABLE_WEBSOCKET_PING_PONG]) { enable_ping_pong = !mg_strcasecmp(conn->dom_ctx->config[ENABLE_WEBSOCKET_PING_PONG], "yes"); } if (conn->dom_ctx->config[WEBSOCKET_TIMEOUT]) { timeout = atoi(conn->dom_ctx->config[WEBSOCKET_TIMEOUT]) / 1000.0; } if ((timeout <= 0.0) && (conn->dom_ctx->config[REQUEST_TIMEOUT])) { timeout = atoi(conn->dom_ctx->config[REQUEST_TIMEOUT]) / 1000.0; } /* Enter data processing loop */ DEBUG_TRACE("Websocket connection %s:%u start data processing loop", conn->request_info.remote_addr, conn->request_info.remote_port); conn->in_websocket_handling = 1; mg_set_thread_name("wsock"); /* Loop continuously, reading messages from the socket, invoking the * callback, and waiting repeatedly until an error occurs. */ while (!conn->phys_ctx->stop_flag && !conn->must_close) { header_len = 0; DEBUG_ASSERT(conn->data_len >= conn->request_len); if ((body_len = (size_t)(conn->data_len - conn->request_len)) >= 2) { len = buf[1] & 127; mask_len = (buf[1] & 128) ? 4 : 0; if ((len < 126) && (body_len >= mask_len)) { /* inline 7-bit length field */ data_len = len; header_len = 2 + mask_len; } else if ((len == 126) && (body_len >= (4 + mask_len))) { /* 16-bit length field */ header_len = 4 + mask_len; data_len = ((((size_t)buf[2]) << 8) + buf[3]); } else if (body_len >= (10 + mask_len)) { /* 64-bit length field */ uint32_t l1, l2; memcpy(&l1, &buf[2], 4); /* Use memcpy for alignment */ memcpy(&l2, &buf[6], 4); header_len = 10 + mask_len; data_len = (((uint64_t)ntohl(l1)) << 32) + ntohl(l2); if (data_len > (uint64_t)0x7FFF0000ul) { /* no can do */ mg_cry_internal( conn, "%s", "websocket out of memory; closing connection"); break; } } } if ((header_len > 0) && (body_len >= header_len)) { /* Allocate space to hold websocket payload */ unsigned char *data = mem; if ((size_t)data_len > (size_t)sizeof(mem)) { data = (unsigned char *)mg_malloc_ctx((size_t)data_len, conn->phys_ctx); if (data == NULL) { /* Allocation failed, exit the loop and then close the * connection */ mg_cry_internal( conn, "%s", "websocket out of memory; closing connection"); break; } } /* Copy the mask before we shift the queue and destroy it */ if (mask_len > 0) { memcpy(mask, buf + header_len - mask_len, sizeof(mask)); } else { memset(mask, 0, sizeof(mask)); } /* Read frame payload from the first message in the queue into * data and advance the queue by moving the memory in place. */ DEBUG_ASSERT(body_len >= header_len); if (data_len + (uint64_t)header_len > (uint64_t)body_len) { mop = buf[0]; /* current mask and opcode */ /* Overflow case */ len = body_len - header_len; memcpy(data, buf + header_len, len); error = 0; while ((uint64_t)len < data_len) { n = pull_inner(NULL, conn, (char *)(data + len), (int)(data_len - len), timeout); if (n <= -2) { error = 1; break; } else if (n > 0) { len += (size_t)n; } else { /* Timeout: should retry */ /* TODO: retry condition */ } } if (error) { mg_cry_internal( conn, "%s", "Websocket pull failed; closing connection"); if (data != mem) { mg_free(data); } break; } conn->data_len = conn->request_len; } else { mop = buf[0]; /* current mask and opcode, overwritten by * memmove() */ /* Length of the message being read at the front of the * queue. Cast to 31 bit is OK, since we limited * data_len before. */ len = (size_t)data_len + header_len; /* Copy the data payload into the data pointer for the * callback. Cast to 31 bit is OK, since we * limited data_len */ memcpy(data, buf + header_len, (size_t)data_len); /* Move the queue forward len bytes */ memmove(buf, buf + len, body_len - len); /* Mark the queue as advanced */ conn->data_len -= (int)len; } /* Apply mask if necessary */ if (mask_len > 0) { for (i = 0; i < (size_t)data_len; i++) { data[i] ^= mask[i & 3]; } } exit_by_callback = 0; if (enable_ping_pong && ((mop & 0xF) == MG_WEBSOCKET_OPCODE_PONG)) { /* filter PONG messages */ DEBUG_TRACE("PONG from %s:%u", conn->request_info.remote_addr, conn->request_info.remote_port); /* No unanwered PINGs left */ ping_count = 0; } else if (enable_ping_pong && ((mop & 0xF) == MG_WEBSOCKET_OPCODE_PING)) { /* reply PING messages */ DEBUG_TRACE("Reply PING from %s:%u", conn->request_info.remote_addr, conn->request_info.remote_port); ret = mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_PONG, (char *)data, (size_t)data_len); if (ret <= 0) { /* Error: send failed */ DEBUG_TRACE("Reply PONG failed (%i)", ret); break; } } else { /* Exit the loop if callback signals to exit (server side), * or "connection close" opcode received (client side). */ if ((ws_data_handler != NULL) && !ws_data_handler(conn, mop, (char *)data, (size_t)data_len, callback_data)) { exit_by_callback = 1; } } /* It a buffer has been allocated, free it again */ if (data != mem) { mg_free(data); } if (exit_by_callback) { DEBUG_TRACE("Callback requests to close connection from %s:%u", conn->request_info.remote_addr, conn->request_info.remote_port); break; } if ((mop & 0xf) == MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE) { /* Opcode == 8, connection close */ DEBUG_TRACE("Message requests to close connection from %s:%u", conn->request_info.remote_addr, conn->request_info.remote_port); break; } /* Not breaking the loop, process next websocket frame. */ } else { /* Read from the socket into the next available location in the * message queue. */ n = pull_inner(NULL, conn, conn->buf + conn->data_len, conn->buf_size - conn->data_len, timeout); if (n <= -2) { /* Error, no bytes read */ DEBUG_TRACE("PULL from %s:%u failed", conn->request_info.remote_addr, conn->request_info.remote_port); break; } if (n > 0) { conn->data_len += n; /* Reset open PING count */ ping_count = 0; } else { if (!conn->phys_ctx->stop_flag && !conn->must_close) { if (ping_count > MG_MAX_UNANSWERED_PING) { /* Stop sending PING */ DEBUG_TRACE("Too many (%i) unanswered ping from %s:%u " "- closing connection", ping_count, conn->request_info.remote_addr, conn->request_info.remote_port); break; } if (enable_ping_pong) { /* Send Websocket PING message */ DEBUG_TRACE("PING to %s:%u", conn->request_info.remote_addr, conn->request_info.remote_port); ret = mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_PING, NULL, 0); if (ret <= 0) { /* Error: send failed */ DEBUG_TRACE("Send PING failed (%i)", ret); break; } ping_count++; } } /* Timeout: should retry */ /* TODO: get timeout def */ } } } /* Leave data processing loop */ mg_set_thread_name("worker"); conn->in_websocket_handling = 0; DEBUG_TRACE("Websocket connection %s:%u left data processing loop", conn->request_info.remote_addr, conn->request_info.remote_port); } static int mg_websocket_write_exec(struct mg_connection *conn, int opcode, const char *data, size_t dataLen, uint32_t masking_key) { unsigned char header[14]; size_t headerLen; int retval; #if defined(GCC_DIAGNOSTIC) /* Disable spurious conversion warning for GCC */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif header[0] = 0x80u | (unsigned char)((unsigned)opcode & 0xf); #if defined(GCC_DIAGNOSTIC) #pragma GCC diagnostic pop #endif /* Frame format: http://tools.ietf.org/html/rfc6455#section-5.2 */ if (dataLen < 126) { /* inline 7-bit length field */ header[1] = (unsigned char)dataLen; headerLen = 2; } else if (dataLen <= 0xFFFF) { /* 16-bit length field */ uint16_t len = htons((uint16_t)dataLen); header[1] = 126; memcpy(header + 2, &len, 2); headerLen = 4; } else { /* 64-bit length field */ uint32_t len1 = htonl((uint32_t)((uint64_t)dataLen >> 32)); uint32_t len2 = htonl((uint32_t)(dataLen & 0xFFFFFFFFu)); header[1] = 127; memcpy(header + 2, &len1, 4); memcpy(header + 6, &len2, 4); headerLen = 10; } if (masking_key) { /* add mask */ header[1] |= 0x80; memcpy(header + headerLen, &masking_key, 4); headerLen += 4; } /* Note that POSIX/Winsock's send() is threadsafe * http://stackoverflow.com/questions/1981372/are-parallel-calls-to-send-recv-on-the-same-socket-valid * but mongoose's mg_printf/mg_write is not (because of the loop in * push(), although that is only a problem if the packet is large or * outgoing buffer is full). */ /* TODO: Check if this lock should be moved to user land. * Currently the server sets this lock for websockets, but * not for any other connection. It must be set for every * conn read/written by more than one thread, no matter if * it is a websocket or regular connection. */ (void)mg_lock_connection(conn); retval = mg_write(conn, header, headerLen); if (retval != (int)headerLen) { /* Did not send complete header */ retval = -1; } else { if (dataLen > 0) { retval = mg_write(conn, data, dataLen); } /* if dataLen == 0, the header length (2) is returned */ } /* TODO: Remove this unlock as well, when lock is removed. */ mg_unlock_connection(conn); return retval; } int mg_websocket_write(struct mg_connection *conn, int opcode, const char *data, size_t dataLen) { return mg_websocket_write_exec(conn, opcode, data, dataLen, 0); } static void mask_data(const char *in, size_t in_len, uint32_t masking_key, char *out) { size_t i = 0; i = 0; if ((in_len > 3) && ((ptrdiff_t)in % 4) == 0) { /* Convert in 32 bit words, if data is 4 byte aligned */ while (i < (in_len - 3)) { *(uint32_t *)(void *)(out + i) = *(uint32_t *)(void *)(in + i) ^ masking_key; i += 4; } } if (i != in_len) { /* convert 1-3 remaining bytes if ((dataLen % 4) != 0)*/ while (i < in_len) { *(uint8_t *)(void *)(out + i) = *(uint8_t *)(void *)(in + i) ^ *(((uint8_t *)&masking_key) + (i % 4)); i++; } } } int mg_websocket_client_write(struct mg_connection *conn, int opcode, const char *data, size_t dataLen) { int retval = -1; char *masked_data = (char *)mg_malloc_ctx(((dataLen + 7) / 4) * 4, conn->phys_ctx); uint32_t masking_key = 0; if (masked_data == NULL) { /* Return -1 in an error case */ mg_cry_internal(conn, "%s", "Cannot allocate buffer for masked websocket response: " "Out of memory"); return -1; } do { /* Get a masking key - but not 0 */ masking_key = (uint32_t)get_random(); } while (masking_key == 0); mask_data(data, dataLen, masking_key, masked_data); retval = mg_websocket_write_exec( conn, opcode, masked_data, dataLen, masking_key); mg_free(masked_data); return retval; } static void handle_websocket_request(struct mg_connection *conn, const char *path, int is_callback_resource, struct mg_websocket_subprotocols *subprotocols, mg_websocket_connect_handler ws_connect_handler, mg_websocket_ready_handler ws_ready_handler, mg_websocket_data_handler ws_data_handler, mg_websocket_close_handler ws_close_handler, void *cbData) { const char *websock_key = mg_get_header(conn, "Sec-WebSocket-Key"); const char *version = mg_get_header(conn, "Sec-WebSocket-Version"); ptrdiff_t lua_websock = 0; #if !defined(USE_LUA) (void)path; #endif /* Step 1: Check websocket protocol version. */ /* Step 1.1: Check Sec-WebSocket-Key. */ if (!websock_key) { /* The RFC standard version (https://tools.ietf.org/html/rfc6455) * requires a Sec-WebSocket-Key header. */ /* It could be the hixie draft version * (http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76). */ const char *key1 = mg_get_header(conn, "Sec-WebSocket-Key1"); const char *key2 = mg_get_header(conn, "Sec-WebSocket-Key2"); char key3[8]; if ((key1 != NULL) && (key2 != NULL)) { /* This version uses 8 byte body data in a GET request */ conn->content_len = 8; if (8 == mg_read(conn, key3, 8)) { /* This is the hixie version */ mg_send_http_error(conn, 426, "%s", "Protocol upgrade to RFC 6455 required"); return; } } /* This is an unknown version */ mg_send_http_error(conn, 400, "%s", "Malformed websocket request"); return; } /* Step 1.2: Check websocket protocol version. */ /* The RFC version (https://tools.ietf.org/html/rfc6455) is 13. */ if ((version == NULL) || (strcmp(version, "13") != 0)) { /* Reject wrong versions */ mg_send_http_error(conn, 426, "%s", "Protocol upgrade required"); return; } /* Step 1.3: Could check for "Host", but we do not really nead this * value for anything, so just ignore it. */ /* Step 2: If a callback is responsible, call it. */ if (is_callback_resource) { /* Step 2.1 check and select subprotocol */ const char *protocols[64]; // max 64 headers int nbSubprotocolHeader = get_req_headers(&conn->request_info, "Sec-WebSocket-Protocol", protocols, 64); if ((nbSubprotocolHeader > 0) && subprotocols) { int cnt = 0; int idx; unsigned long len; const char *sep, *curSubProtocol, *acceptedWebSocketSubprotocol = NULL; /* look for matching subprotocol */ do { const char *protocol = protocols[cnt]; do { sep = strchr(protocol, ','); curSubProtocol = protocol; len = sep ? (unsigned long)(sep - protocol) : (unsigned long)strlen(protocol); while (sep && isspace((unsigned char)*++sep)) ; // ignore leading whitespaces protocol = sep; for (idx = 0; idx < subprotocols->nb_subprotocols; idx++) { if ((strlen(subprotocols->subprotocols[idx]) == len) && (strncmp(curSubProtocol, subprotocols->subprotocols[idx], len) == 0)) { acceptedWebSocketSubprotocol = subprotocols->subprotocols[idx]; break; } } } while (sep && !acceptedWebSocketSubprotocol); } while (++cnt < nbSubprotocolHeader && !acceptedWebSocketSubprotocol); conn->request_info.acceptedWebSocketSubprotocol = acceptedWebSocketSubprotocol; } else if (nbSubprotocolHeader > 0) { /* keep legacy behavior */ const char *protocol = protocols[0]; /* The protocol is a comma separated list of names. */ /* The server must only return one value from this list. */ /* First check if it is a list or just a single value. */ const char *sep = strrchr(protocol, ','); if (sep == NULL) { /* Just a single protocol -> accept it. */ conn->request_info.acceptedWebSocketSubprotocol = protocol; } else { /* Multiple protocols -> accept the last one. */ /* This is just a quick fix if the client offers multiple * protocols. The handler should have a list of accepted * protocols on his own * and use it to select one protocol among those the client * has * offered. */ while (isspace((unsigned char)*++sep)) { ; /* ignore leading whitespaces */ } conn->request_info.acceptedWebSocketSubprotocol = sep; } } if ((ws_connect_handler != NULL) && (ws_connect_handler(conn, cbData) != 0)) { /* C callback has returned non-zero, do not proceed with * handshake. */ /* Note that C callbacks are no longer called when Lua is * responsible, so C can no longer filter callbacks for Lua. */ return; } } #if defined(USE_LUA) /* Step 3: No callback. Check if Lua is responsible. */ else { /* Step 3.1: Check if Lua is responsible. */ if (conn->dom_ctx->config[LUA_WEBSOCKET_EXTENSIONS]) { lua_websock = match_prefix( conn->dom_ctx->config[LUA_WEBSOCKET_EXTENSIONS], strlen(conn->dom_ctx->config[LUA_WEBSOCKET_EXTENSIONS]), path); } if (lua_websock) { /* Step 3.2: Lua is responsible: call it. */ conn->lua_websocket_state = lua_websocket_new(path, conn); if (!conn->lua_websocket_state) { /* Lua rejected the new client */ return; } } } #endif /* Step 4: Check if there is a responsible websocket handler. */ if (!is_callback_resource && !lua_websock) { /* There is no callback, and Lua is not responsible either. */ /* Reply with a 404 Not Found. We are still at a standard * HTTP request here, before the websocket handshake, so * we can still send standard HTTP error replies. */ mg_send_http_error(conn, 404, "%s", "Not found"); return; } /* Step 5: The websocket connection has been accepted */ if (!send_websocket_handshake(conn, websock_key)) { mg_send_http_error(conn, 500, "%s", "Websocket handshake failed"); return; } /* Step 6: Call the ready handler */ if (is_callback_resource) { if (ws_ready_handler != NULL) { ws_ready_handler(conn, cbData); } #if defined(USE_LUA) } else if (lua_websock) { if (!lua_websocket_ready(conn, conn->lua_websocket_state)) { /* the ready handler returned false */ return; } #endif } /* Step 7: Enter the read loop */ if (is_callback_resource) { read_websocket(conn, ws_data_handler, cbData); #if defined(USE_LUA) } else if (lua_websock) { read_websocket(conn, lua_websocket_data, conn->lua_websocket_state); #endif } /* Step 8: Call the close handler */ if (ws_close_handler) { ws_close_handler(conn, cbData); } } static int is_websocket_protocol(const struct mg_connection *conn) { const char *upgrade, *connection; /* A websocket protocoll has the following HTTP headers: * * Connection: Upgrade * Upgrade: Websocket */ upgrade = mg_get_header(conn, "Upgrade"); if (upgrade == NULL) { return 0; /* fail early, don't waste time checking other header * fields */ } if (!mg_strcasestr(upgrade, "websocket")) { return 0; } connection = mg_get_header(conn, "Connection"); if (connection == NULL) { return 0; } if (!mg_strcasestr(connection, "upgrade")) { return 0; } /* The headers "Host", "Sec-WebSocket-Key", "Sec-WebSocket-Protocol" and * "Sec-WebSocket-Version" are also required. * Don't check them here, since even an unsupported websocket protocol * request still IS a websocket request (in contrast to a standard HTTP * request). It will fail later in handle_websocket_request. */ return 1; } #endif /* !USE_WEBSOCKET */ static int isbyte(int n) { return (n >= 0) && (n <= 255); } static int parse_net(const char *spec, uint32_t *net, uint32_t *mask) { int n, a, b, c, d, slash = 32, len = 0; if (((sscanf(spec, "%d.%d.%d.%d/%d%n", &a, &b, &c, &d, &slash, &n) == 5) || (sscanf(spec, "%d.%d.%d.%d%n", &a, &b, &c, &d, &n) == 4)) && isbyte(a) && isbyte(b) && isbyte(c) && isbyte(d) && (slash >= 0) && (slash < 33)) { len = n; *net = ((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d; *mask = slash ? (0xffffffffU << (32 - slash)) : 0; } return len; } static int set_throttle(const char *spec, uint32_t remote_ip, const char *uri) { int throttle = 0; struct vec vec, val; uint32_t net, mask; char mult; double v; while ((spec = next_option(spec, &vec, &val)) != NULL) { mult = ','; if ((val.ptr == NULL) || (sscanf(val.ptr, "%lf%c", &v, &mult) < 1) || (v < 0) || ((lowercase(&mult) != 'k') && (lowercase(&mult) != 'm') && (mult != ','))) { continue; } v *= (lowercase(&mult) == 'k') ? 1024 : ((lowercase(&mult) == 'm') ? 1048576 : 1); if (vec.len == 1 && vec.ptr[0] == '*') { throttle = (int)v; } else if (parse_net(vec.ptr, &net, &mask) > 0) { if ((remote_ip & mask) == net) { throttle = (int)v; } } else if (match_prefix(vec.ptr, vec.len, uri) > 0) { throttle = (int)v; } } return throttle; } static uint32_t get_remote_ip(const struct mg_connection *conn) { if (!conn) { return 0; } return ntohl(*(const uint32_t *)&conn->client.rsa.sin.sin_addr); } /* The mg_upload function is superseeded by mg_handle_form_request. */ #include "handle_form.inl" #if defined(MG_LEGACY_INTERFACE) /* Implement the deprecated mg_upload function by calling the new * mg_handle_form_request function. While mg_upload could only handle * HTML forms sent as POST request in multipart/form-data format * containing only file input elements, mg_handle_form_request can * handle all form input elements and all standard request methods. */ struct mg_upload_user_data { struct mg_connection *conn; const char *destination_dir; int num_uploaded_files; }; /* Helper function for deprecated mg_upload. */ static int mg_upload_field_found(const char *key, const char *filename, char *path, size_t pathlen, void *user_data) { int truncated = 0; struct mg_upload_user_data *fud = (struct mg_upload_user_data *)user_data; (void)key; if (!filename) { mg_cry_internal(fud->conn, "%s: No filename set", __func__); return FORM_FIELD_STORAGE_ABORT; } mg_snprintf(fud->conn, &truncated, path, pathlen - 1, "%s/%s", fud->destination_dir, filename); if (truncated) { mg_cry_internal(fud->conn, "%s: File path too long", __func__); return FORM_FIELD_STORAGE_ABORT; } return FORM_FIELD_STORAGE_STORE; } /* Helper function for deprecated mg_upload. */ static int mg_upload_field_get(const char *key, const char *value, size_t value_size, void *user_data) { /* Function should never be called */ (void)key; (void)value; (void)value_size; (void)user_data; return 0; } /* Helper function for deprecated mg_upload. */ static int mg_upload_field_stored(const char *path, long long file_size, void *user_data) { struct mg_upload_user_data *fud = (struct mg_upload_user_data *)user_data; (void)file_size; fud->num_uploaded_files++; fud->conn->phys_ctx->callbacks.upload(fud->conn, path); return 0; } /* Deprecated function mg_upload - use mg_handle_form_request instead. */ int mg_upload(struct mg_connection *conn, const char *destination_dir) { struct mg_upload_user_data fud = {conn, destination_dir, 0}; struct mg_form_data_handler fdh = {mg_upload_field_found, mg_upload_field_get, mg_upload_field_stored, 0}; int ret; fdh.user_data = (void *)&fud; ret = mg_handle_form_request(conn, &fdh); if (ret < 0) { mg_cry_internal(conn, "%s: Error while parsing the request", __func__); } return fud.num_uploaded_files; } #endif static int get_first_ssl_listener_index(const struct mg_context *ctx) { unsigned int i; int idx = -1; if (ctx) { for (i = 0; ((idx == -1) && (i < ctx->num_listening_sockets)); i++) { idx = ctx->listening_sockets[i].is_ssl ? ((int)(i)) : -1; } } return idx; } /* Return host (without port) */ /* Use mg_free to free the result */ static const char * alloc_get_host(struct mg_connection *conn) { char buf[1025]; size_t buflen = sizeof(buf); const char *host_header = get_header(conn->request_info.http_headers, conn->request_info.num_headers, "Host"); char *host; if (host_header != NULL) { char *pos; /* Create a local copy of the "Host" header, since it might be * modified here. */ mg_strlcpy(buf, host_header, buflen); buf[buflen - 1] = '\0'; host = buf; while (isspace((unsigned char)*host)) { host++; } /* If the "Host" is an IPv6 address, like [::1], parse until ] * is found. */ if (*host == '[') { pos = strchr(host, ']'); if (!pos) { /* Malformed hostname starts with '[', but no ']' found */ DEBUG_TRACE("%s", "Host name format error '[' without ']'"); return NULL; } /* terminate after ']' */ pos[1] = 0; } else { /* Otherwise, a ':' separates hostname and port number */ pos = strchr(host, ':'); if (pos != NULL) { *pos = '\0'; } } if (conn->ssl) { /* This is a HTTPS connection, maybe we have a hostname * from SNI (set in ssl_servername_callback). */ const char *sslhost = conn->dom_ctx->config[AUTHENTICATION_DOMAIN]; if (sslhost && (conn->dom_ctx != &(conn->phys_ctx->dd))) { /* We are not using the default domain */ if (mg_strcasecmp(host, sslhost)) { /* Mismatch between SNI domain and HTTP domain */ DEBUG_TRACE("Host mismatch: SNI: %s, HTTPS: %s", sslhost, host); return NULL; } } DEBUG_TRACE("HTTPS Host: %s", host); } else { struct mg_domain_context *dom = &(conn->phys_ctx->dd); while (dom) { if (!mg_strcasecmp(host, dom->config[AUTHENTICATION_DOMAIN])) { /* Found matching domain */ DEBUG_TRACE("HTTP domain %s found", dom->config[AUTHENTICATION_DOMAIN]); /* TODO: Check if this is a HTTP or HTTPS domain */ conn->dom_ctx = dom; break; } dom = dom->next; } DEBUG_TRACE("HTTP Host: %s", host); } } else { sockaddr_to_string(buf, buflen, &conn->client.lsa); host = buf; DEBUG_TRACE("IP: %s", host); } return mg_strdup_ctx(host, conn->phys_ctx); } static void redirect_to_https_port(struct mg_connection *conn, int ssl_index) { char target_url[MG_BUF_LEN]; int truncated = 0; conn->must_close = 1; /* Send host, port, uri and (if it exists) ?query_string */ if (conn->host) { /* Use "308 Permanent Redirect" */ int redirect_code = 308; /* Create target URL */ mg_snprintf( conn, &truncated, target_url, sizeof(target_url), "https://%s:%d%s%s%s", conn->host, #if defined(USE_IPV6) (conn->phys_ctx->listening_sockets[ssl_index].lsa.sa.sa_family == AF_INET6) ? (int)ntohs(conn->phys_ctx->listening_sockets[ssl_index] .lsa.sin6.sin6_port) : #endif (int)ntohs(conn->phys_ctx->listening_sockets[ssl_index] .lsa.sin.sin_port), conn->request_info.local_uri, (conn->request_info.query_string == NULL) ? "" : "?", (conn->request_info.query_string == NULL) ? "" : conn->request_info.query_string); /* Check overflow in location buffer (will not occur if MG_BUF_LEN * is used as buffer size) */ if (truncated) { mg_send_http_error(conn, 500, "%s", "Redirect URL too long"); return; } /* Use redirect helper function */ mg_send_http_redirect(conn, target_url, redirect_code); } } static void handler_info_acquire(struct mg_handler_info *handler_info) { pthread_mutex_lock(&handler_info->refcount_mutex); handler_info->refcount++; pthread_mutex_unlock(&handler_info->refcount_mutex); } static void handler_info_release(struct mg_handler_info *handler_info) { pthread_mutex_lock(&handler_info->refcount_mutex); handler_info->refcount--; pthread_cond_signal(&handler_info->refcount_cond); pthread_mutex_unlock(&handler_info->refcount_mutex); } static void handler_info_wait_unused(struct mg_handler_info *handler_info) { pthread_mutex_lock(&handler_info->refcount_mutex); while (handler_info->refcount) { pthread_cond_wait(&handler_info->refcount_cond, &handler_info->refcount_mutex); } pthread_mutex_unlock(&handler_info->refcount_mutex); } static void mg_set_handler_type(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx, const char *uri, int handler_type, int is_delete_request, mg_request_handler handler, struct mg_websocket_subprotocols *subprotocols, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, mg_authorization_handler auth_handler, void *cbdata) { struct mg_handler_info *tmp_rh, **lastref; size_t urilen = strlen(uri); if (handler_type == WEBSOCKET_HANDLER) { DEBUG_ASSERT(handler == NULL); DEBUG_ASSERT(is_delete_request || connect_handler != NULL || ready_handler != NULL || data_handler != NULL || close_handler != NULL); DEBUG_ASSERT(auth_handler == NULL); if (handler != NULL) { return; } if (!is_delete_request && (connect_handler == NULL) && (ready_handler == NULL) && (data_handler == NULL) && (close_handler == NULL)) { return; } if (auth_handler != NULL) { return; } } else if (handler_type == REQUEST_HANDLER) { DEBUG_ASSERT(connect_handler == NULL && ready_handler == NULL && data_handler == NULL && close_handler == NULL); DEBUG_ASSERT(is_delete_request || (handler != NULL)); DEBUG_ASSERT(auth_handler == NULL); if ((connect_handler != NULL) || (ready_handler != NULL) || (data_handler != NULL) || (close_handler != NULL)) { return; } if (!is_delete_request && (handler == NULL)) { return; } if (auth_handler != NULL) { return; } } else { /* AUTH_HANDLER */ DEBUG_ASSERT(handler == NULL); DEBUG_ASSERT(connect_handler == NULL && ready_handler == NULL && data_handler == NULL && close_handler == NULL); DEBUG_ASSERT(auth_handler != NULL); if (handler != NULL) { return; } if ((connect_handler != NULL) || (ready_handler != NULL) || (data_handler != NULL) || (close_handler != NULL)) { return; } if (!is_delete_request && (auth_handler == NULL)) { return; } } if (!phys_ctx || !dom_ctx) { return; } mg_lock_context(phys_ctx); /* first try to find an existing handler */ lastref = &(dom_ctx->handlers); for (tmp_rh = dom_ctx->handlers; tmp_rh != NULL; tmp_rh = tmp_rh->next) { if (tmp_rh->handler_type == handler_type) { if ((urilen == tmp_rh->uri_len) && !strcmp(tmp_rh->uri, uri)) { if (!is_delete_request) { /* update existing handler */ if (handler_type == REQUEST_HANDLER) { /* Wait for end of use before updating */ handler_info_wait_unused(tmp_rh); /* Ok, the handler is no more use -> Update it */ tmp_rh->handler = handler; } else if (handler_type == WEBSOCKET_HANDLER) { tmp_rh->subprotocols = subprotocols; tmp_rh->connect_handler = connect_handler; tmp_rh->ready_handler = ready_handler; tmp_rh->data_handler = data_handler; tmp_rh->close_handler = close_handler; } else { /* AUTH_HANDLER */ tmp_rh->auth_handler = auth_handler; } tmp_rh->cbdata = cbdata; } else { /* remove existing handler */ if (handler_type == REQUEST_HANDLER) { /* Wait for end of use before removing */ handler_info_wait_unused(tmp_rh); /* Ok, the handler is no more used -> Destroy resources */ pthread_cond_destroy(&tmp_rh->refcount_cond); pthread_mutex_destroy(&tmp_rh->refcount_mutex); } *lastref = tmp_rh->next; mg_free(tmp_rh->uri); mg_free(tmp_rh); } mg_unlock_context(phys_ctx); return; } } lastref = &(tmp_rh->next); } if (is_delete_request) { /* no handler to set, this was a remove request to a non-existing * handler */ mg_unlock_context(phys_ctx); return; } tmp_rh = (struct mg_handler_info *)mg_calloc_ctx(sizeof(struct mg_handler_info), 1, phys_ctx); if (tmp_rh == NULL) { mg_unlock_context(phys_ctx); mg_cry_internal(fc(phys_ctx), "%s", "Cannot create new request handler struct, OOM"); return; } tmp_rh->uri = mg_strdup_ctx(uri, phys_ctx); if (!tmp_rh->uri) { mg_unlock_context(phys_ctx); mg_free(tmp_rh); mg_cry_internal(fc(phys_ctx), "%s", "Cannot create new request handler struct, OOM"); return; } tmp_rh->uri_len = urilen; if (handler_type == REQUEST_HANDLER) { /* Init refcount mutex and condition */ if (0 != pthread_mutex_init(&tmp_rh->refcount_mutex, NULL)) { mg_unlock_context(phys_ctx); mg_free(tmp_rh); mg_cry_internal(fc(phys_ctx), "%s", "Cannot init refcount mutex"); return; } if (0 != pthread_cond_init(&tmp_rh->refcount_cond, NULL)) { mg_unlock_context(phys_ctx); pthread_mutex_destroy(&tmp_rh->refcount_mutex); mg_free(tmp_rh); mg_cry_internal(fc(phys_ctx), "%s", "Cannot init refcount cond"); return; } tmp_rh->refcount = 0; tmp_rh->handler = handler; } else if (handler_type == WEBSOCKET_HANDLER) { tmp_rh->subprotocols = subprotocols; tmp_rh->connect_handler = connect_handler; tmp_rh->ready_handler = ready_handler; tmp_rh->data_handler = data_handler; tmp_rh->close_handler = close_handler; } else { /* AUTH_HANDLER */ tmp_rh->auth_handler = auth_handler; } tmp_rh->cbdata = cbdata; tmp_rh->handler_type = handler_type; tmp_rh->next = NULL; *lastref = tmp_rh; mg_unlock_context(phys_ctx); } void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata) { mg_set_handler_type(ctx, &(ctx->dd), uri, REQUEST_HANDLER, handler == NULL, handler, NULL, NULL, NULL, NULL, NULL, NULL, cbdata); } void mg_set_websocket_handler(struct mg_context *ctx, const char *uri, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, void *cbdata) { mg_set_websocket_handler_with_subprotocols(ctx, uri, NULL, connect_handler, ready_handler, data_handler, close_handler, cbdata); } void mg_set_websocket_handler_with_subprotocols( struct mg_context *ctx, const char *uri, struct mg_websocket_subprotocols *subprotocols, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, void *cbdata) { int is_delete_request = (connect_handler == NULL) && (ready_handler == NULL) && (data_handler == NULL) && (close_handler == NULL); mg_set_handler_type(ctx, &(ctx->dd), uri, WEBSOCKET_HANDLER, is_delete_request, NULL, subprotocols, connect_handler, ready_handler, data_handler, close_handler, NULL, cbdata); } void mg_set_auth_handler(struct mg_context *ctx, const char *uri, mg_authorization_handler handler, void *cbdata) { mg_set_handler_type(ctx, &(ctx->dd), uri, AUTH_HANDLER, handler == NULL, NULL, NULL, NULL, NULL, NULL, NULL, handler, cbdata); } static int get_request_handler(struct mg_connection *conn, int handler_type, mg_request_handler *handler, struct mg_websocket_subprotocols **subprotocols, mg_websocket_connect_handler *connect_handler, mg_websocket_ready_handler *ready_handler, mg_websocket_data_handler *data_handler, mg_websocket_close_handler *close_handler, mg_authorization_handler *auth_handler, void **cbdata, struct mg_handler_info **handler_info) { const struct mg_request_info *request_info = mg_get_request_info(conn); if (request_info) { const char *uri = request_info->local_uri; size_t urilen = strlen(uri); struct mg_handler_info *tmp_rh; if (!conn || !conn->phys_ctx || !conn->dom_ctx) { return 0; } mg_lock_context(conn->phys_ctx); /* first try for an exact match */ for (tmp_rh = conn->dom_ctx->handlers; tmp_rh != NULL; tmp_rh = tmp_rh->next) { if (tmp_rh->handler_type == handler_type) { if ((urilen == tmp_rh->uri_len) && !strcmp(tmp_rh->uri, uri)) { if (handler_type == WEBSOCKET_HANDLER) { *subprotocols = tmp_rh->subprotocols; *connect_handler = tmp_rh->connect_handler; *ready_handler = tmp_rh->ready_handler; *data_handler = tmp_rh->data_handler; *close_handler = tmp_rh->close_handler; } else if (handler_type == REQUEST_HANDLER) { *handler = tmp_rh->handler; /* Acquire handler and give it back */ handler_info_acquire(tmp_rh); *handler_info = tmp_rh; } else { /* AUTH_HANDLER */ *auth_handler = tmp_rh->auth_handler; } *cbdata = tmp_rh->cbdata; mg_unlock_context(conn->phys_ctx); return 1; } } } /* next try for a partial match, we will accept uri/something */ for (tmp_rh = conn->dom_ctx->handlers; tmp_rh != NULL; tmp_rh = tmp_rh->next) { if (tmp_rh->handler_type == handler_type) { if ((tmp_rh->uri_len < urilen) && (uri[tmp_rh->uri_len] == '/') && (memcmp(tmp_rh->uri, uri, tmp_rh->uri_len) == 0)) { if (handler_type == WEBSOCKET_HANDLER) { *subprotocols = tmp_rh->subprotocols; *connect_handler = tmp_rh->connect_handler; *ready_handler = tmp_rh->ready_handler; *data_handler = tmp_rh->data_handler; *close_handler = tmp_rh->close_handler; } else if (handler_type == REQUEST_HANDLER) { *handler = tmp_rh->handler; /* Acquire handler and give it back */ handler_info_acquire(tmp_rh); *handler_info = tmp_rh; } else { /* AUTH_HANDLER */ *auth_handler = tmp_rh->auth_handler; } *cbdata = tmp_rh->cbdata; mg_unlock_context(conn->phys_ctx); return 1; } } } /* finally try for pattern match */ for (tmp_rh = conn->dom_ctx->handlers; tmp_rh != NULL; tmp_rh = tmp_rh->next) { if (tmp_rh->handler_type == handler_type) { if (match_prefix(tmp_rh->uri, tmp_rh->uri_len, uri) > 0) { if (handler_type == WEBSOCKET_HANDLER) { *subprotocols = tmp_rh->subprotocols; *connect_handler = tmp_rh->connect_handler; *ready_handler = tmp_rh->ready_handler; *data_handler = tmp_rh->data_handler; *close_handler = tmp_rh->close_handler; } else if (handler_type == REQUEST_HANDLER) { *handler = tmp_rh->handler; /* Acquire handler and give it back */ handler_info_acquire(tmp_rh); *handler_info = tmp_rh; } else { /* AUTH_HANDLER */ *auth_handler = tmp_rh->auth_handler; } *cbdata = tmp_rh->cbdata; mg_unlock_context(conn->phys_ctx); return 1; } } } mg_unlock_context(conn->phys_ctx); } return 0; /* none found */ } /* Check if the script file is in a path, allowed for script files. * This can be used if uploading files is possible not only for the server * admin, and the upload mechanism does not check the file extension. */ static int is_in_script_path(const struct mg_connection *conn, const char *path) { /* TODO (Feature): Add config value for allowed script path. * Default: All allowed. */ (void)conn; (void)path; return 1; } #if defined(USE_WEBSOCKET) && defined(MG_LEGACY_INTERFACE) static int deprecated_websocket_connect_wrapper(const struct mg_connection *conn, void *cbdata) { struct mg_callbacks *pcallbacks = (struct mg_callbacks *)cbdata; if (pcallbacks->websocket_connect) { return pcallbacks->websocket_connect(conn); } /* No handler set - assume "OK" */ return 0; } static void deprecated_websocket_ready_wrapper(struct mg_connection *conn, void *cbdata) { struct mg_callbacks *pcallbacks = (struct mg_callbacks *)cbdata; if (pcallbacks->websocket_ready) { pcallbacks->websocket_ready(conn); } } static int deprecated_websocket_data_wrapper(struct mg_connection *conn, int bits, char *data, size_t len, void *cbdata) { struct mg_callbacks *pcallbacks = (struct mg_callbacks *)cbdata; if (pcallbacks->websocket_data) { return pcallbacks->websocket_data(conn, bits, data, len); } /* No handler set - assume "OK" */ return 1; } #endif /* This is the heart of the Civetweb's logic. * This function is called when the request is read, parsed and validated, * and Civetweb must decide what action to take: serve a file, or * a directory, or call embedded function, etcetera. */ static void handle_request(struct mg_connection *conn) { struct mg_request_info *ri = &conn->request_info; char path[PATH_MAX]; int uri_len, ssl_index; int is_found = 0, is_script_resource = 0, is_websocket_request = 0, is_put_or_delete_request = 0, is_callback_resource = 0; int i; struct mg_file file = STRUCT_FILE_INITIALIZER; mg_request_handler callback_handler = NULL; struct mg_handler_info *handler_info = NULL; struct mg_websocket_subprotocols *subprotocols; mg_websocket_connect_handler ws_connect_handler = NULL; mg_websocket_ready_handler ws_ready_handler = NULL; mg_websocket_data_handler ws_data_handler = NULL; mg_websocket_close_handler ws_close_handler = NULL; void *callback_data = NULL; mg_authorization_handler auth_handler = NULL; void *auth_callback_data = NULL; int handler_type; time_t curtime = time(NULL); char date[64]; path[0] = 0; /* 1. get the request url */ /* 1.1. split into url and query string */ if ((conn->request_info.query_string = strchr(ri->request_uri, '?')) != NULL) { *((char *)conn->request_info.query_string++) = '\0'; } /* 1.2. do a https redirect, if required. Do not decode URIs yet. */ if (!conn->client.is_ssl && conn->client.ssl_redir) { ssl_index = get_first_ssl_listener_index(conn->phys_ctx); if (ssl_index >= 0) { redirect_to_https_port(conn, ssl_index); } else { /* A http to https forward port has been specified, * but no https port to forward to. */ mg_send_http_error(conn, 503, "%s", "Error: SSL forward not configured properly"); mg_cry_internal(conn, "%s", "Can not redirect to SSL, no SSL port available"); } return; } uri_len = (int)strlen(ri->local_uri); /* 1.3. decode url (if config says so) */ if (should_decode_url(conn)) { mg_url_decode( ri->local_uri, uri_len, (char *)ri->local_uri, uri_len + 1, 0); } /* 1.4. clean URIs, so a path like allowed_dir/../forbidden_file is * not possible */ remove_double_dots_and_double_slashes((char *)ri->local_uri); /* step 1. completed, the url is known now */ uri_len = (int)strlen(ri->local_uri); DEBUG_TRACE("URL: %s", ri->local_uri); /* 2. if this ip has limited speed, set it for this connection */ conn->throttle = set_throttle(conn->dom_ctx->config[THROTTLE], get_remote_ip(conn), ri->local_uri); /* 3. call a "handle everything" callback, if registered */ if (conn->phys_ctx->callbacks.begin_request != NULL) { /* Note that since V1.7 the "begin_request" function is called * before an authorization check. If an authorization check is * required, use a request_handler instead. */ i = conn->phys_ctx->callbacks.begin_request(conn); if (i > 0) { /* callback already processed the request. Store the return value as a status code for the access log. */ conn->status_code = i; discard_unread_request_data(conn); return; } else if (i == 0) { /* civetweb should process the request */ } else { /* unspecified - may change with the next version */ return; } } /* request not yet handled by a handler or redirect, so the request * is processed here */ /* 4. Check for CORS preflight requests and handle them (if configured). * https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS */ if (!strcmp(ri->request_method, "OPTIONS")) { /* Send a response to CORS preflights only if * access_control_allow_methods is not NULL and not an empty string. * In this case, scripts can still handle CORS. */ const char *cors_meth_cfg = conn->dom_ctx->config[ACCESS_CONTROL_ALLOW_METHODS]; const char *cors_orig_cfg = conn->dom_ctx->config[ACCESS_CONTROL_ALLOW_ORIGIN]; const char *cors_origin = get_header(ri->http_headers, ri->num_headers, "Origin"); const char *cors_acrm = get_header(ri->http_headers, ri->num_headers, "Access-Control-Request-Method"); /* Todo: check if cors_origin is in cors_orig_cfg. * Or, let the client check this. */ if ((cors_meth_cfg != NULL) && (*cors_meth_cfg != 0) && (cors_orig_cfg != NULL) && (*cors_orig_cfg != 0) && (cors_origin != NULL) && (cors_acrm != NULL)) { /* This is a valid CORS preflight, and the server is configured * to * handle it automatically. */ const char *cors_acrh = get_header(ri->http_headers, ri->num_headers, "Access-Control-Request-Headers"); gmt_time_string(date, sizeof(date), &curtime); mg_printf(conn, "HTTP/1.1 200 OK\r\n" "Date: %s\r\n" "Access-Control-Allow-Origin: %s\r\n" "Access-Control-Allow-Methods: %s\r\n" "Content-Length: 0\r\n" "Connection: %s\r\n", date, cors_orig_cfg, ((cors_meth_cfg[0] == '*') ? cors_acrm : cors_meth_cfg), suggest_connection_header(conn)); if (cors_acrh != NULL) { /* CORS request is asking for additional headers */ const char *cors_hdr_cfg = conn->dom_ctx->config[ACCESS_CONTROL_ALLOW_HEADERS]; if ((cors_hdr_cfg != NULL) && (*cors_hdr_cfg != 0)) { /* Allow only if access_control_allow_headers is * not NULL and not an empty string. If this * configuration is set to *, allow everything. * Otherwise this configuration must be a list * of allowed HTTP header names. */ mg_printf(conn, "Access-Control-Allow-Headers: %s\r\n", ((cors_hdr_cfg[0] == '*') ? cors_acrh : cors_hdr_cfg)); } } mg_printf(conn, "Access-Control-Max-Age: 60\r\n"); mg_printf(conn, "\r\n"); return; } } /* 5. interpret the url to find out how the request must be handled */ /* 5.1. first test, if the request targets the regular http(s):// * protocol namespace or the websocket ws(s):// protocol namespace. */ is_websocket_request = is_websocket_protocol(conn); #if defined(USE_WEBSOCKET) handler_type = is_websocket_request ? WEBSOCKET_HANDLER : REQUEST_HANDLER; #else handler_type = REQUEST_HANDLER; #endif /* defined(USE_WEBSOCKET) */ /* 5.2. check if the request will be handled by a callback */ if (get_request_handler(conn, handler_type, &callback_handler, &subprotocols, &ws_connect_handler, &ws_ready_handler, &ws_data_handler, &ws_close_handler, NULL, &callback_data, &handler_info)) { /* 5.2.1. A callback will handle this request. All requests * handled * by a callback have to be considered as requests to a script * resource. */ is_callback_resource = 1; is_script_resource = 1; is_put_or_delete_request = is_put_or_delete_method(conn); } else { no_callback_resource: /* 5.2.2. No callback is responsible for this request. The URI * addresses a file based resource (static content or Lua/cgi * scripts in the file system). */ is_callback_resource = 0; interpret_uri(conn, path, sizeof(path), &file.stat, &is_found, &is_script_resource, &is_websocket_request, &is_put_or_delete_request); } /* 6. authorization check */ /* 6.1. a custom authorization handler is installed */ if (get_request_handler(conn, AUTH_HANDLER, NULL, NULL, NULL, NULL, NULL, NULL, &auth_handler, &auth_callback_data, NULL)) { if (!auth_handler(conn, auth_callback_data)) { return; } } else if (is_put_or_delete_request && !is_script_resource && !is_callback_resource) { /* 6.2. this request is a PUT/DELETE to a real file */ /* 6.2.1. thus, the server must have real files */ #if defined(NO_FILES) if (1) { #else if (conn->dom_ctx->config[DOCUMENT_ROOT] == NULL) { #endif /* This server does not have any real files, thus the * PUT/DELETE methods are not valid. */ mg_send_http_error(conn, 405, "%s method not allowed", conn->request_info.request_method); return; } #if !defined(NO_FILES) /* 6.2.2. Check if put authorization for static files is * available. */ if (!is_authorized_for_put(conn)) { send_authorization_request(conn, NULL); return; } #endif } else { /* 6.3. This is either a OPTIONS, GET, HEAD or POST request, * or it is a PUT or DELETE request to a resource that does not * correspond to a file. Check authorization. */ if (!check_authorization(conn, path)) { send_authorization_request(conn, NULL); return; } } /* request is authorized or does not need authorization */ /* 7. check if there are request handlers for this uri */ if (is_callback_resource) { if (!is_websocket_request) { i = callback_handler(conn, callback_data); /* Callback handler will not be used anymore. Release it */ handler_info_release(handler_info); if (i > 0) { /* Do nothing, callback has served the request. Store * then return value as status code for the log and discard * all data from the client not used by the callback. */ conn->status_code = i; discard_unread_request_data(conn); } else { /* The handler did NOT handle the request. */ /* Some proper reactions would be: * a) close the connections without sending anything * b) send a 404 not found * c) try if there is a file matching the URI * It would be possible to do a, b or c in the callback * implementation, and return 1 - we cannot do anything * here, that is not possible in the callback. * * TODO: What would be the best reaction here? * (Note: The reaction may change, if there is a better *idea.) */ /* For the moment, use option c: We look for a proper file, * but since a file request is not always a script resource, * the authorization check might be different. */ interpret_uri(conn, path, sizeof(path), &file.stat, &is_found, &is_script_resource, &is_websocket_request, &is_put_or_delete_request); callback_handler = NULL; /* Here we are at a dead end: * According to URI matching, a callback should be * responsible for handling the request, * we called it, but the callback declared itself * not responsible. * We use a goto here, to get out of this dead end, * and continue with the default handling. * A goto here is simpler and better to understand * than some curious loop. */ goto no_callback_resource; } } else { #if defined(USE_WEBSOCKET) handle_websocket_request(conn, path, is_callback_resource, subprotocols, ws_connect_handler, ws_ready_handler, ws_data_handler, ws_close_handler, callback_data); #endif } return; } /* 8. handle websocket requests */ #if defined(USE_WEBSOCKET) if (is_websocket_request) { if (is_script_resource) { if (is_in_script_path(conn, path)) { /* Websocket Lua script */ handle_websocket_request(conn, path, 0 /* Lua Script */, NULL, NULL, NULL, NULL, NULL, conn->phys_ctx->user_data); } else { /* Script was in an illegal path */ mg_send_http_error(conn, 403, "%s", "Forbidden"); } } else { #if defined(MG_LEGACY_INTERFACE) handle_websocket_request( conn, path, !is_script_resource /* could be deprecated global callback */, NULL, deprecated_websocket_connect_wrapper, deprecated_websocket_ready_wrapper, deprecated_websocket_data_wrapper, NULL, conn->phys_ctx->user_data); #else mg_send_http_error(conn, 404, "%s", "Not found"); #endif } return; } else #endif #if defined(NO_FILES) /* 9a. In case the server uses only callbacks, this uri is * unknown. * Then, all request handling ends here. */ mg_send_http_error(conn, 404, "%s", "Not Found"); #else /* 9b. This request is either for a static file or resource handled * by a script file. Thus, a DOCUMENT_ROOT must exist. */ if (conn->dom_ctx->config[DOCUMENT_ROOT] == NULL) { mg_send_http_error(conn, 404, "%s", "Not Found"); return; } /* 10. Request is handled by a script */ if (is_script_resource) { handle_file_based_request(conn, path, &file); return; } /* 11. Handle put/delete/mkcol requests */ if (is_put_or_delete_request) { /* 11.1. PUT method */ if (!strcmp(ri->request_method, "PUT")) { put_file(conn, path); return; } /* 11.2. DELETE method */ if (!strcmp(ri->request_method, "DELETE")) { delete_file(conn, path); return; } /* 11.3. MKCOL method */ if (!strcmp(ri->request_method, "MKCOL")) { mkcol(conn, path); return; } /* 11.4. PATCH method * This method is not supported for static resources, * only for scripts (Lua, CGI) and callbacks. */ mg_send_http_error(conn, 405, "%s method not allowed", conn->request_info.request_method); return; } /* 11. File does not exist, or it was configured that it should be * hidden */ if (!is_found || (must_hide_file(conn, path))) { mg_send_http_error(conn, 404, "%s", "Not found"); return; } /* 12. Directory uris should end with a slash */ if (file.stat.is_directory && (uri_len > 0) && (ri->local_uri[uri_len - 1] != '/')) { gmt_time_string(date, sizeof(date), &curtime); mg_printf(conn, "HTTP/1.1 301 Moved Permanently\r\n" "Location: %s/\r\n" "Date: %s\r\n" /* "Cache-Control: private\r\n" (= default) */ "Content-Length: 0\r\n" "Connection: %s\r\n", ri->request_uri, date, suggest_connection_header(conn)); send_additional_header(conn); mg_printf(conn, "\r\n"); return; } /* 13. Handle other methods than GET/HEAD */ /* 13.1. Handle PROPFIND */ if (!strcmp(ri->request_method, "PROPFIND")) { handle_propfind(conn, path, &file.stat); return; } /* 13.2. Handle OPTIONS for files */ if (!strcmp(ri->request_method, "OPTIONS")) { /* This standard handler is only used for real files. * Scripts should support the OPTIONS method themselves, to allow a * maximum flexibility. * Lua and CGI scripts may fully support CORS this way (including * preflights). */ send_options(conn); return; } /* 13.3. everything but GET and HEAD (e.g. POST) */ if ((0 != strcmp(ri->request_method, "GET")) && (0 != strcmp(ri->request_method, "HEAD"))) { mg_send_http_error(conn, 405, "%s method not allowed", conn->request_info.request_method); return; } /* 14. directories */ if (file.stat.is_directory) { /* Substitute files have already been handled above. */ /* Here we can either generate and send a directory listing, * or send an "access denied" error. */ if (!mg_strcasecmp(conn->dom_ctx->config[ENABLE_DIRECTORY_LISTING], "yes")) { handle_directory_request(conn, path); } else { mg_send_http_error(conn, 403, "%s", "Error: Directory listing denied"); } return; } /* 15. read a normal file with GET or HEAD */ handle_file_based_request(conn, path, &file); #endif /* !defined(NO_FILES) */ } static void handle_file_based_request(struct mg_connection *conn, const char *path, struct mg_file *file) { if (!conn || !conn->dom_ctx) { return; } if (0) { #if defined(USE_LUA) } else if (match_prefix( conn->dom_ctx->config[LUA_SERVER_PAGE_EXTENSIONS], strlen(conn->dom_ctx->config[LUA_SERVER_PAGE_EXTENSIONS]), path) > 0) { if (is_in_script_path(conn, path)) { /* Lua server page: an SSI like page containing mostly plain * html * code * plus some tags with server generated contents. */ handle_lsp_request(conn, path, file, NULL); } else { /* Script was in an illegal path */ mg_send_http_error(conn, 403, "%s", "Forbidden"); } } else if (match_prefix(conn->dom_ctx->config[LUA_SCRIPT_EXTENSIONS], strlen( conn->dom_ctx->config[LUA_SCRIPT_EXTENSIONS]), path) > 0) { if (is_in_script_path(conn, path)) { /* Lua in-server module script: a CGI like script used to * generate * the * entire reply. */ mg_exec_lua_script(conn, path, NULL); } else { /* Script was in an illegal path */ mg_send_http_error(conn, 403, "%s", "Forbidden"); } #endif #if defined(USE_DUKTAPE) } else if (match_prefix( conn->dom_ctx->config[DUKTAPE_SCRIPT_EXTENSIONS], strlen(conn->dom_ctx->config[DUKTAPE_SCRIPT_EXTENSIONS]), path) > 0) { if (is_in_script_path(conn, path)) { /* Call duktape to generate the page */ mg_exec_duktape_script(conn, path); } else { /* Script was in an illegal path */ mg_send_http_error(conn, 403, "%s", "Forbidden"); } #endif #if !defined(NO_CGI) } else if (match_prefix(conn->dom_ctx->config[CGI_EXTENSIONS], strlen(conn->dom_ctx->config[CGI_EXTENSIONS]), path) > 0) { if (is_in_script_path(conn, path)) { /* CGI scripts may support all HTTP methods */ handle_cgi_request(conn, path); } else { /* Script was in an illegal path */ mg_send_http_error(conn, 403, "%s", "Forbidden"); } #endif /* !NO_CGI */ } else if (match_prefix(conn->dom_ctx->config[SSI_EXTENSIONS], strlen(conn->dom_ctx->config[SSI_EXTENSIONS]), path) > 0) { if (is_in_script_path(conn, path)) { handle_ssi_file_request(conn, path, file); } else { /* Script was in an illegal path */ mg_send_http_error(conn, 403, "%s", "Forbidden"); } #if !defined(NO_CACHING) } else if ((!conn->in_error_handler) && is_not_modified(conn, &file->stat)) { /* Send 304 "Not Modified" - this must not send any body data */ handle_not_modified_static_file_request(conn, file); #endif /* !NO_CACHING */ } else { handle_static_file_request(conn, path, file, NULL, NULL); } } static void close_all_listening_sockets(struct mg_context *ctx) { unsigned int i; if (!ctx) { return; } for (i = 0; i < ctx->num_listening_sockets; i++) { closesocket(ctx->listening_sockets[i].sock); ctx->listening_sockets[i].sock = INVALID_SOCKET; } mg_free(ctx->listening_sockets); ctx->listening_sockets = NULL; mg_free(ctx->listening_socket_fds); ctx->listening_socket_fds = NULL; } /* Valid listening port specification is: [ip_address:]port[s] * Examples for IPv4: 80, 443s, 127.0.0.1:3128, 192.0.2.3:8080s * Examples for IPv6: [::]:80, [::1]:80, * [2001:0db8:7654:3210:FEDC:BA98:7654:3210]:443s * see https://tools.ietf.org/html/rfc3513#section-2.2 * In order to bind to both, IPv4 and IPv6, you can either add * both ports using 8080,[::]:8080, or the short form +8080. * Both forms differ in detail: 8080,[::]:8080 create two sockets, * one only accepting IPv4 the other only IPv6. +8080 creates * one socket accepting IPv4 and IPv6. Depending on the IPv6 * environment, they might work differently, or might not work * at all - it must be tested what options work best in the * relevant network environment. */ static int parse_port_string(const struct vec *vec, struct socket *so, int *ip_version) { unsigned int a, b, c, d, port; int ch, len; const char *cb; #if defined(USE_IPV6) char buf[100] = {0}; #endif /* MacOS needs that. If we do not zero it, subsequent bind() will fail. * Also, all-zeroes in the socket address means binding to all addresses * for both IPv4 and IPv6 (INADDR_ANY and IN6ADDR_ANY_INIT). */ memset(so, 0, sizeof(*so)); so->lsa.sin.sin_family = AF_INET; *ip_version = 0; /* Initialize port and len as invalid. */ port = 0; len = 0; /* Test for different ways to format this string */ if (sscanf(vec->ptr, "%u.%u.%u.%u:%u%n", &a, &b, &c, &d, &port, &len) == 5) { /* Bind to a specific IPv4 address, e.g. 192.168.1.5:8080 */ so->lsa.sin.sin_addr.s_addr = htonl((a << 24) | (b << 16) | (c << 8) | d); so->lsa.sin.sin_port = htons((uint16_t)port); *ip_version = 4; #if defined(USE_IPV6) } else if (sscanf(vec->ptr, "[%49[^]]]:%u%n", buf, &port, &len) == 2 && mg_inet_pton( AF_INET6, buf, &so->lsa.sin6, sizeof(so->lsa.sin6))) { /* IPv6 address, examples: see above */ /* so->lsa.sin6.sin6_family = AF_INET6; already set by mg_inet_pton */ so->lsa.sin6.sin6_port = htons((uint16_t)port); *ip_version = 6; #endif } else if ((vec->ptr[0] == '+') && (sscanf(vec->ptr + 1, "%u%n", &port, &len) == 1)) { /* Port is specified with a +, bind to IPv6 and IPv4, INADDR_ANY */ /* Add 1 to len for the + character we skipped before */ len++; #if defined(USE_IPV6) /* Set socket family to IPv6, do not use IPV6_V6ONLY */ so->lsa.sin6.sin6_family = AF_INET6; so->lsa.sin6.sin6_port = htons((uint16_t)port); *ip_version = 4 + 6; #else /* Bind to IPv4 only, since IPv6 is not built in. */ so->lsa.sin.sin_port = htons((uint16_t)port); *ip_version = 4; #endif } else if (sscanf(vec->ptr, "%u%n", &port, &len) == 1) { /* If only port is specified, bind to IPv4, INADDR_ANY */ so->lsa.sin.sin_port = htons((uint16_t)port); *ip_version = 4; } else if ((cb = strchr(vec->ptr, ':')) != NULL) { /* String could be a hostname. This check algotithm * will only work for RFC 952 compliant hostnames, * starting with a letter, containing only letters, * digits and hyphen ('-'). Newer specs may allow * more, but this is not guaranteed here, since it * may interfere with rules for port option lists. */ /* According to RFC 1035, hostnames are restricted to 255 characters * in total (63 between two dots). */ char hostname[256]; size_t hostnlen = (size_t)(cb - vec->ptr); if (hostnlen >= sizeof(hostname)) { /* This would be invalid in any case */ *ip_version = 0; return 0; } memcpy(hostname, vec->ptr, hostnlen); hostname[hostnlen] = 0; if (mg_inet_pton( AF_INET, vec->ptr, &so->lsa.sin, sizeof(so->lsa.sin))) { if (sscanf(cb + 1, "%u%n", &port, &len) == 1) { *ip_version = 4; so->lsa.sin.sin_family = AF_INET; so->lsa.sin.sin_port = htons((uint16_t)port); len += (int)(hostnlen + 1); } else { port = 0; len = 0; } #if defined(USE_IPV6) } else if (mg_inet_pton(AF_INET6, vec->ptr, &so->lsa.sin6, sizeof(so->lsa.sin6))) { if (sscanf(cb + 1, "%u%n", &port, &len) == 1) { *ip_version = 6; so->lsa.sin6.sin6_family = AF_INET6; so->lsa.sin.sin_port = htons((uint16_t)port); len += (int)(hostnlen + 1); } else { port = 0; len = 0; } #endif } } else { /* Parsing failure. */ } /* sscanf and the option splitting code ensure the following condition */ if ((len < 0) && ((unsigned)len > (unsigned)vec->len)) { *ip_version = 0; return 0; } ch = vec->ptr[len]; /* Next character after the port number */ so->is_ssl = (ch == 's'); so->ssl_redir = (ch == 'r'); /* Make sure the port is valid and vector ends with 's', 'r' or ',' */ if (is_valid_port(port) && ((ch == '\0') || (ch == 's') || (ch == 'r') || (ch == ','))) { return 1; } /* Reset ip_version to 0 if there is an error */ *ip_version = 0; return 0; } /* Is there any SSL port in use? */ static int is_ssl_port_used(const char *ports) { if (ports) { /* There are several different allowed syntax variants: * - "80" for a single port using every network interface * - "localhost:80" for a single port using only localhost * - "80,localhost:8080" for two ports, one bound to localhost * - "80,127.0.0.1:8084,[::1]:8086" for three ports, one bound * to IPv4 localhost, one to IPv6 localhost * - "+80" use port 80 for IPv4 and IPv6 * - "+80r,+443s" port 80 (HTTP) is a redirect to port 443 (HTTPS), * for both: IPv4 and IPv4 * - "+443s,localhost:8080" port 443 (HTTPS) for every interface, * additionally port 8080 bound to localhost connections * * If we just look for 's' anywhere in the string, "localhost:80" * will be detected as SSL (false positive). * Looking for 's' after a digit may cause false positives in * "my24service:8080". * Looking from 's' backward if there are only ':' and numbers * before will not work for "24service:8080" (non SSL, port 8080) * or "24s" (SSL, port 24). * * Remark: Initially hostnames were not allowed to start with a * digit (according to RFC 952), this was allowed later (RFC 1123, * Section 2.1). * * To get this correct, the entire string must be parsed as a whole, * reading it as a list element for element and parsing with an * algorithm equivalent to parse_port_string. * * In fact, we use local interface names here, not arbitrary hostnames, * so in most cases the only name will be "localhost". * * So, for now, we use this simple algorithm, that may still return * a false positive in bizarre cases. */ int i; int portslen = (int)strlen(ports); char prevIsNumber = 0; for (i = 0; i < portslen; i++) { if (prevIsNumber && (ports[i] == 's' || ports[i] == 'r')) { return 1; } if (ports[i] >= '0' && ports[i] <= '9') { prevIsNumber = 1; } else { prevIsNumber = 0; } } } return 0; } static int set_ports_option(struct mg_context *phys_ctx) { const char *list; int on = 1; #if defined(USE_IPV6) int off = 0; #endif struct vec vec; struct socket so, *ptr; struct mg_pollfd *pfd; union usa usa; socklen_t len; int ip_version; int portsTotal = 0; int portsOk = 0; if (!phys_ctx) { return 0; } memset(&so, 0, sizeof(so)); memset(&usa, 0, sizeof(usa)); len = sizeof(usa); list = phys_ctx->dd.config[LISTENING_PORTS]; while ((list = next_option(list, &vec, NULL)) != NULL) { portsTotal++; if (!parse_port_string(&vec, &so, &ip_version)) { mg_cry_internal( fc(phys_ctx), "%.*s: invalid port spec (entry %i). Expecting list of: %s", (int)vec.len, vec.ptr, portsTotal, "[IP_ADDRESS:]PORT[s|r]"); continue; } #if !defined(NO_SSL) if (so.is_ssl && phys_ctx->dd.ssl_ctx == NULL) { mg_cry_internal(fc(phys_ctx), "Cannot add SSL socket (entry %i)", portsTotal); continue; } #endif if ((so.sock = socket(so.lsa.sa.sa_family, SOCK_STREAM, 6)) == INVALID_SOCKET) { mg_cry_internal(fc(phys_ctx), "cannot create socket (entry %i)", portsTotal); continue; } #if defined(_WIN32) /* Windows SO_REUSEADDR lets many procs binds to a * socket, SO_EXCLUSIVEADDRUSE makes the bind fail * if someone already has the socket -- DTL */ /* NOTE: If SO_EXCLUSIVEADDRUSE is used, * Windows might need a few seconds before * the same port can be used again in the * same process, so a short Sleep may be * required between mg_stop and mg_start. */ if (setsockopt(so.sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (SOCK_OPT_TYPE)&on, sizeof(on)) != 0) { /* Set reuse option, but don't abort on errors. */ mg_cry_internal( fc(phys_ctx), "cannot set socket option SO_EXCLUSIVEADDRUSE (entry %i)", portsTotal); } #else if (setsockopt(so.sock, SOL_SOCKET, SO_REUSEADDR, (SOCK_OPT_TYPE)&on, sizeof(on)) != 0) { /* Set reuse option, but don't abort on errors. */ mg_cry_internal(fc(phys_ctx), "cannot set socket option SO_REUSEADDR (entry %i)", portsTotal); } #endif if (ip_version > 4) { /* Could be 6 for IPv6 onlyor 10 (4+6) for IPv4+IPv6 */ #if defined(USE_IPV6) if (ip_version > 6) { if (so.lsa.sa.sa_family == AF_INET6 && setsockopt(so.sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&off, sizeof(off)) != 0) { /* Set IPv6 only option, but don't abort on errors. */ mg_cry_internal( fc(phys_ctx), "cannot set socket option IPV6_V6ONLY=off (entry %i)", portsTotal); } } else { if (so.lsa.sa.sa_family == AF_INET6 && setsockopt(so.sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on)) != 0) { /* Set IPv6 only option, but don't abort on errors. */ mg_cry_internal( fc(phys_ctx), "cannot set socket option IPV6_V6ONLY=on (entry %i)", portsTotal); } } #else mg_cry_internal(fc(phys_ctx), "%s", "IPv6 not available"); closesocket(so.sock); so.sock = INVALID_SOCKET; continue; #endif } if (so.lsa.sa.sa_family == AF_INET) { len = sizeof(so.lsa.sin); if (bind(so.sock, &so.lsa.sa, len) != 0) { mg_cry_internal(fc(phys_ctx), "cannot bind to %.*s: %d (%s)", (int)vec.len, vec.ptr, (int)ERRNO, strerror(errno)); closesocket(so.sock); so.sock = INVALID_SOCKET; continue; } } #if defined(USE_IPV6) else if (so.lsa.sa.sa_family == AF_INET6) { len = sizeof(so.lsa.sin6); if (bind(so.sock, &so.lsa.sa, len) != 0) { mg_cry_internal(fc(phys_ctx), "cannot bind to IPv6 %.*s: %d (%s)", (int)vec.len, vec.ptr, (int)ERRNO, strerror(errno)); closesocket(so.sock); so.sock = INVALID_SOCKET; continue; } } #endif else { mg_cry_internal( fc(phys_ctx), "cannot bind: address family not supported (entry %i)", portsTotal); closesocket(so.sock); so.sock = INVALID_SOCKET; continue; } if (listen(so.sock, SOMAXCONN) != 0) { mg_cry_internal(fc(phys_ctx), "cannot listen to %.*s: %d (%s)", (int)vec.len, vec.ptr, (int)ERRNO, strerror(errno)); closesocket(so.sock); so.sock = INVALID_SOCKET; continue; } if ((getsockname(so.sock, &(usa.sa), &len) != 0) || (usa.sa.sa_family != so.lsa.sa.sa_family)) { int err = (int)ERRNO; mg_cry_internal(fc(phys_ctx), "call to getsockname failed %.*s: %d (%s)", (int)vec.len, vec.ptr, err, strerror(errno)); closesocket(so.sock); so.sock = INVALID_SOCKET; continue; } /* Update lsa port in case of random free ports */ #if defined(USE_IPV6) if (so.lsa.sa.sa_family == AF_INET6) { so.lsa.sin6.sin6_port = usa.sin6.sin6_port; } else #endif { so.lsa.sin.sin_port = usa.sin.sin_port; } if ((ptr = (struct socket *) mg_realloc_ctx(phys_ctx->listening_sockets, (phys_ctx->num_listening_sockets + 1) * sizeof(phys_ctx->listening_sockets[0]), phys_ctx)) == NULL) { mg_cry_internal(fc(phys_ctx), "%s", "Out of memory"); closesocket(so.sock); so.sock = INVALID_SOCKET; continue; } if ((pfd = (struct mg_pollfd *) mg_realloc_ctx(phys_ctx->listening_socket_fds, (phys_ctx->num_listening_sockets + 1) * sizeof(phys_ctx->listening_socket_fds[0]), phys_ctx)) == NULL) { mg_cry_internal(fc(phys_ctx), "%s", "Out of memory"); closesocket(so.sock); so.sock = INVALID_SOCKET; mg_free(ptr); continue; } set_close_on_exec(so.sock, fc(phys_ctx)); phys_ctx->listening_sockets = ptr; phys_ctx->listening_sockets[phys_ctx->num_listening_sockets] = so; phys_ctx->listening_socket_fds = pfd; phys_ctx->num_listening_sockets++; portsOk++; } if (portsOk != portsTotal) { close_all_listening_sockets(phys_ctx); portsOk = 0; } return portsOk; } static const char * header_val(const struct mg_connection *conn, const char *header) { const char *header_value; if ((header_value = mg_get_header(conn, header)) == NULL) { return "-"; } else { return header_value; } } #if defined(MG_EXTERNAL_FUNCTION_log_access) static void log_access(const struct mg_connection *conn); #include "external_log_access.inl" #else static void log_access(const struct mg_connection *conn) { const struct mg_request_info *ri; struct mg_file fi; char date[64], src_addr[IP_ADDR_STR_LEN]; struct tm *tm; const char *referer; const char *user_agent; char buf[4096]; if (!conn || !conn->dom_ctx) { return; } if (conn->dom_ctx->config[ACCESS_LOG_FILE] != NULL) { if (mg_fopen(conn, conn->dom_ctx->config[ACCESS_LOG_FILE], MG_FOPEN_MODE_APPEND, &fi) == 0) { fi.access.fp = NULL; } } else { fi.access.fp = NULL; } /* Log is written to a file and/or a callback. If both are not set, * executing the rest of the function is pointless. */ if ((fi.access.fp == NULL) && (conn->phys_ctx->callbacks.log_access == NULL)) { return; } tm = localtime(&conn->conn_birth_time); if (tm != NULL) { strftime(date, sizeof(date), "%d/%b/%Y:%H:%M:%S %z", tm); } else { mg_strlcpy(date, "01/Jan/1970:00:00:00 +0000", sizeof(date)); date[sizeof(date) - 1] = '\0'; } ri = &conn->request_info; sockaddr_to_string(src_addr, sizeof(src_addr), &conn->client.rsa); referer = header_val(conn, "Referer"); user_agent = header_val(conn, "User-Agent"); mg_snprintf(conn, NULL, /* Ignore truncation in access log */ buf, sizeof(buf), "%s - %s [%s] \"%s %s%s%s HTTP/%s\" %d %" INT64_FMT " %s %s", src_addr, (ri->remote_user == NULL) ? "-" : ri->remote_user, date, ri->request_method ? ri->request_method : "-", ri->request_uri ? ri->request_uri : "-", ri->query_string ? "?" : "", ri->query_string ? ri->query_string : "", ri->http_version, conn->status_code, conn->num_bytes_sent, referer, user_agent); if (conn->phys_ctx->callbacks.log_access) { conn->phys_ctx->callbacks.log_access(conn, buf); } if (fi.access.fp) { int ok = 1; flockfile(fi.access.fp); if (fprintf(fi.access.fp, "%s\n", buf) < 1) { ok = 0; } if (fflush(fi.access.fp) != 0) { ok = 0; } funlockfile(fi.access.fp); if (mg_fclose(&fi.access) != 0) { ok = 0; } if (!ok) { mg_cry_internal(conn, "Error writing log file %s", conn->dom_ctx->config[ACCESS_LOG_FILE]); } } } #endif /* Externally provided function */ /* Verify given socket address against the ACL. * Return -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed. */ static int check_acl(struct mg_context *phys_ctx, uint32_t remote_ip) { int allowed, flag; uint32_t net, mask; struct vec vec; if (phys_ctx) { const char *list = phys_ctx->dd.config[ACCESS_CONTROL_LIST]; /* If any ACL is set, deny by default */ allowed = (list == NULL) ? '+' : '-'; while ((list = next_option(list, &vec, NULL)) != NULL) { flag = vec.ptr[0]; if ((flag != '+' && flag != '-') || (parse_net(&vec.ptr[1], &net, &mask) == 0)) { mg_cry_internal(fc(phys_ctx), "%s: subnet must be [+|-]x.x.x.x[/x]", __func__); return -1; } if (net == (remote_ip & mask)) { allowed = flag; } } return allowed == '+'; } return -1; } #if !defined(_WIN32) static int set_uid_option(struct mg_context *phys_ctx) { int success = 0; if (phys_ctx) { /* We are currently running as curr_uid. */ const uid_t curr_uid = getuid(); /* If set, we want to run as run_as_user. */ const char *run_as_user = phys_ctx->dd.config[RUN_AS_USER]; const struct passwd *to_pw = NULL; if (run_as_user != NULL && (to_pw = getpwnam(run_as_user)) == NULL) { /* run_as_user does not exist on the system. We can't proceed * further. */ mg_cry_internal(fc(phys_ctx), "%s: unknown user [%s]", __func__, run_as_user); } else if (run_as_user == NULL || curr_uid == to_pw->pw_uid) { /* There was either no request to change user, or we're already * running as run_as_user. Nothing else to do. */ success = 1; } else { /* Valid change request. */ if (setgid(to_pw->pw_gid) == -1) { mg_cry_internal(fc(phys_ctx), "%s: setgid(%s): %s", __func__, run_as_user, strerror(errno)); } else if (setgroups(0, NULL) == -1) { mg_cry_internal(fc(phys_ctx), "%s: setgroups(): %s", __func__, strerror(errno)); } else if (setuid(to_pw->pw_uid) == -1) { mg_cry_internal(fc(phys_ctx), "%s: setuid(%s): %s", __func__, run_as_user, strerror(errno)); } else { success = 1; } } } return success; } #endif /* !_WIN32 */ static void tls_dtor(void *key) { struct mg_workerTLS *tls = (struct mg_workerTLS *)key; /* key == pthread_getspecific(sTlsKey); */ if (tls) { if (tls->is_master == 2) { tls->is_master = -3; /* Mark memory as dead */ mg_free(tls); } } pthread_setspecific(sTlsKey, NULL); } #if !defined(NO_SSL) static int ssl_use_pem_file(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx, const char *pem, const char *chain); static const char *ssl_error(void); static int refresh_trust(struct mg_connection *conn) { static int reload_lock = 0; static long int data_check = 0; volatile int *p_reload_lock = (volatile int *)&reload_lock; struct stat cert_buf; long int t; const char *pem; const char *chain; int should_verify_peer; if ((pem = conn->dom_ctx->config[SSL_CERTIFICATE]) == NULL) { /* If peem is NULL and conn->phys_ctx->callbacks.init_ssl is not, * refresh_trust still can not work. */ return 0; } chain = conn->dom_ctx->config[SSL_CERTIFICATE_CHAIN]; if (chain == NULL) { /* pem is not NULL here */ chain = pem; } if (*chain == 0) { chain = NULL; } t = data_check; if (stat(pem, &cert_buf) != -1) { t = (long int)cert_buf.st_mtime; } if (data_check != t) { data_check = t; should_verify_peer = 0; if (conn->dom_ctx->config[SSL_DO_VERIFY_PEER] != NULL) { if (mg_strcasecmp(conn->dom_ctx->config[SSL_DO_VERIFY_PEER], "yes") == 0) { should_verify_peer = 1; } else if (mg_strcasecmp(conn->dom_ctx->config[SSL_DO_VERIFY_PEER], "optional") == 0) { should_verify_peer = 1; } } if (should_verify_peer) { char *ca_path = conn->dom_ctx->config[SSL_CA_PATH]; char *ca_file = conn->dom_ctx->config[SSL_CA_FILE]; if (SSL_CTX_load_verify_locations(conn->dom_ctx->ssl_ctx, ca_file, ca_path) != 1) { mg_cry_internal( fc(conn->phys_ctx), "SSL_CTX_load_verify_locations error: %s " "ssl_verify_peer requires setting " "either ssl_ca_path or ssl_ca_file. Is any of them " "present in " "the .conf file?", ssl_error()); return 0; } } if (1 == mg_atomic_inc(p_reload_lock)) { if (ssl_use_pem_file(conn->phys_ctx, conn->dom_ctx, pem, chain) == 0) { return 0; } *p_reload_lock = 0; } } /* lock while cert is reloading */ while (*p_reload_lock) { sleep(1); } return 1; } #if defined(OPENSSL_API_1_1) #else static pthread_mutex_t *ssl_mutexes; #endif /* OPENSSL_API_1_1 */ static int sslize(struct mg_connection *conn, SSL_CTX *s, int (*func)(SSL *), volatile int *stop_server, const struct mg_client_options *client_options) { int ret, err; int short_trust; unsigned timeout = 1024; unsigned i; if (!conn) { return 0; } short_trust = (conn->dom_ctx->config[SSL_SHORT_TRUST] != NULL) && (mg_strcasecmp(conn->dom_ctx->config[SSL_SHORT_TRUST], "yes") == 0); if (short_trust) { int trust_ret = refresh_trust(conn); if (!trust_ret) { return trust_ret; } } conn->ssl = SSL_new(s); if (conn->ssl == NULL) { return 0; } SSL_set_app_data(conn->ssl, (char *)conn); ret = SSL_set_fd(conn->ssl, conn->client.sock); if (ret != 1) { err = SSL_get_error(conn->ssl, ret); mg_cry_internal(conn, "SSL error %i, destroying SSL context", err); SSL_free(conn->ssl); conn->ssl = NULL; OPENSSL_REMOVE_THREAD_STATE(); return 0; } if (client_options) { if (client_options->host_name) { SSL_set_tlsext_host_name(conn->ssl, client_options->host_name); } } /* Reuse the request timeout for the SSL_Accept/SSL_connect timeout */ if (conn->dom_ctx->config[REQUEST_TIMEOUT]) { /* NOTE: The loop below acts as a back-off, so we can end * up sleeping for more (or less) than the REQUEST_TIMEOUT. */ timeout = atoi(conn->dom_ctx->config[REQUEST_TIMEOUT]); } /* SSL functions may fail and require to be called again: * see https://www.openssl.org/docs/manmaster/ssl/SSL_get_error.html * Here "func" could be SSL_connect or SSL_accept. */ for (i = 16; i <= timeout; i *= 2) { ret = func(conn->ssl); if (ret != 1) { err = SSL_get_error(conn->ssl, ret); if ((err == SSL_ERROR_WANT_CONNECT) || (err == SSL_ERROR_WANT_ACCEPT) || (err == SSL_ERROR_WANT_READ) || (err == SSL_ERROR_WANT_WRITE) || (err == SSL_ERROR_WANT_X509_LOOKUP)) { /* Need to retry the function call "later". * See https://linux.die.net/man/3/ssl_get_error * This is typical for non-blocking sockets. */ if (*stop_server) { /* Don't wait if the server is going to be stopped. */ break; } mg_sleep(i); } else if (err == SSL_ERROR_SYSCALL) { /* This is an IO error. Look at errno. */ err = errno; mg_cry_internal(conn, "SSL syscall error %i", err); break; } else { /* This is an SSL specific error, e.g. SSL_ERROR_SSL */ mg_cry_internal(conn, "sslize error: %s", ssl_error()); break; } } else { /* success */ break; } } if (ret != 1) { SSL_free(conn->ssl); conn->ssl = NULL; OPENSSL_REMOVE_THREAD_STATE(); return 0; } return 1; } /* Return OpenSSL error message (from CRYPTO lib) */ static const char * ssl_error(void) { unsigned long err; err = ERR_get_error(); return ((err == 0) ? "" : ERR_error_string(err, NULL)); } static int hexdump2string(void *mem, int memlen, char *buf, int buflen) { int i; const char hexdigit[] = "0123456789abcdef"; if ((memlen <= 0) || (buflen <= 0)) { return 0; } if (buflen < (3 * memlen)) { return 0; } for (i = 0; i < memlen; i++) { if (i > 0) { buf[3 * i - 1] = ' '; } buf[3 * i] = hexdigit[(((uint8_t *)mem)[i] >> 4) & 0xF]; buf[3 * i + 1] = hexdigit[((uint8_t *)mem)[i] & 0xF]; } buf[3 * memlen - 1] = 0; return 1; } static void ssl_get_client_cert_info(struct mg_connection *conn) { X509 *cert = SSL_get_peer_certificate(conn->ssl); if (cert) { char str_subject[1024]; char str_issuer[1024]; char str_finger[1024]; unsigned char buf[256]; char *str_serial = NULL; unsigned int ulen; int ilen; unsigned char *tmp_buf; unsigned char *tmp_p; /* Handle to algorithm used for fingerprint */ const EVP_MD *digest = EVP_get_digestbyname("sha1"); /* Get Subject and issuer */ X509_NAME *subj = X509_get_subject_name(cert); X509_NAME *iss = X509_get_issuer_name(cert); /* Get serial number */ ASN1_INTEGER *serial = X509_get_serialNumber(cert); /* Translate serial number to a hex string */ BIGNUM *serial_bn = ASN1_INTEGER_to_BN(serial, NULL); str_serial = BN_bn2hex(serial_bn); BN_free(serial_bn); /* Translate subject and issuer to a string */ (void)X509_NAME_oneline(subj, str_subject, (int)sizeof(str_subject)); (void)X509_NAME_oneline(iss, str_issuer, (int)sizeof(str_issuer)); /* Calculate SHA1 fingerprint and store as a hex string */ ulen = 0; /* ASN1_digest is deprecated. Do the calculation manually, * using EVP_Digest. */ ilen = i2d_X509(cert, NULL); tmp_buf = (ilen > 0) ? (unsigned char *)mg_malloc_ctx((unsigned)ilen + 1, conn->phys_ctx) : NULL; if (tmp_buf) { tmp_p = tmp_buf; (void)i2d_X509(cert, &tmp_p); if (!EVP_Digest( tmp_buf, (unsigned)ilen, buf, &ulen, digest, NULL)) { ulen = 0; } mg_free(tmp_buf); } if (!hexdump2string( buf, (int)ulen, str_finger, (int)sizeof(str_finger))) { *str_finger = 0; } conn->request_info.client_cert = (struct mg_client_cert *) mg_malloc_ctx(sizeof(struct mg_client_cert), conn->phys_ctx); if (conn->request_info.client_cert) { conn->request_info.client_cert->peer_cert = (void *)cert; conn->request_info.client_cert->subject = mg_strdup_ctx(str_subject, conn->phys_ctx); conn->request_info.client_cert->issuer = mg_strdup_ctx(str_issuer, conn->phys_ctx); conn->request_info.client_cert->serial = mg_strdup_ctx(str_serial, conn->phys_ctx); conn->request_info.client_cert->finger = mg_strdup_ctx(str_finger, conn->phys_ctx); } else { mg_cry_internal(conn, "%s", "Out of memory: Cannot allocate memory for client " "certificate"); } /* Strings returned from bn_bn2hex must be freed using OPENSSL_free, * see https://linux.die.net/man/3/bn_bn2hex */ OPENSSL_free(str_serial); } } #if defined(OPENSSL_API_1_1) #else static void ssl_locking_callback(int mode, int mutex_num, const char *file, int line) { (void)line; (void)file; if (mode & 1) { /* 1 is CRYPTO_LOCK */ (void)pthread_mutex_lock(&ssl_mutexes[mutex_num]); } else { (void)pthread_mutex_unlock(&ssl_mutexes[mutex_num]); } } #endif /* OPENSSL_API_1_1 */ #if !defined(NO_SSL_DL) static void * load_dll(char *ebuf, size_t ebuf_len, const char *dll_name, struct ssl_func *sw) { union { void *p; void (*fp)(void); } u; void *dll_handle; struct ssl_func *fp; int ok; int truncated = 0; if ((dll_handle = dlopen(dll_name, RTLD_LAZY)) == NULL) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s: cannot load %s", __func__, dll_name); return NULL; } ok = 1; for (fp = sw; fp->name != NULL; fp++) { #if defined(_WIN32) /* GetProcAddress() returns pointer to function */ u.fp = (void (*)(void))dlsym(dll_handle, fp->name); #else /* dlsym() on UNIX returns void *. ISO C forbids casts of data * pointers to function pointers. We need to use a union to make a * cast. */ u.p = dlsym(dll_handle, fp->name); #endif /* _WIN32 */ if (u.fp == NULL) { if (ok) { mg_snprintf(NULL, &truncated, ebuf, ebuf_len, "%s: %s: cannot find %s", __func__, dll_name, fp->name); ok = 0; } else { size_t cur_len = strlen(ebuf); if (!truncated) { mg_snprintf(NULL, &truncated, ebuf + cur_len, ebuf_len - cur_len - 3, ", %s", fp->name); if (truncated) { /* If truncated, add "..." */ strcat(ebuf, "..."); } } } /* Debug: * printf("Missing function: %s\n", fp->name); */ } else { fp->ptr = u.fp; } } if (!ok) { (void)dlclose(dll_handle); return NULL; } return dll_handle; } static void *ssllib_dll_handle; /* Store the ssl library handle. */ static void *cryptolib_dll_handle; /* Store the crypto library handle. */ #endif /* NO_SSL_DL */ #if defined(SSL_ALREADY_INITIALIZED) static int cryptolib_users = 1; /* Reference counter for crypto library. */ #else static int cryptolib_users = 0; /* Reference counter for crypto library. */ #endif static int initialize_ssl(char *ebuf, size_t ebuf_len) { #if defined(OPENSSL_API_1_1) if (ebuf_len > 0) { ebuf[0] = 0; } #if !defined(NO_SSL_DL) if (!cryptolib_dll_handle) { cryptolib_dll_handle = load_dll(ebuf, ebuf_len, CRYPTO_LIB, crypto_sw); if (!cryptolib_dll_handle) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s: error loading library %s", __func__, CRYPTO_LIB); DEBUG_TRACE("%s", ebuf); return 0; } } #endif /* NO_SSL_DL */ if (mg_atomic_inc(&cryptolib_users) > 1) { return 1; } #else /* not OPENSSL_API_1_1 */ int i, num_locks; size_t size; if (ebuf_len > 0) { ebuf[0] = 0; } #if !defined(NO_SSL_DL) if (!cryptolib_dll_handle) { cryptolib_dll_handle = load_dll(ebuf, ebuf_len, CRYPTO_LIB, crypto_sw); if (!cryptolib_dll_handle) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s: error loading library %s", __func__, CRYPTO_LIB); DEBUG_TRACE("%s", ebuf); return 0; } } #endif /* NO_SSL_DL */ if (mg_atomic_inc(&cryptolib_users) > 1) { return 1; } /* Initialize locking callbacks, needed for thread safety. * http://www.openssl.org/support/faq.html#PROG1 */ num_locks = CRYPTO_num_locks(); if (num_locks < 0) { num_locks = 0; } size = sizeof(pthread_mutex_t) * ((size_t)(num_locks)); /* allocate mutex array, if required */ if (num_locks == 0) { /* No mutex array required */ ssl_mutexes = NULL; } else { /* Mutex array required - allocate it */ ssl_mutexes = (pthread_mutex_t *)mg_malloc(size); /* Check OOM */ if (ssl_mutexes == NULL) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s: cannot allocate mutexes: %s", __func__, ssl_error()); DEBUG_TRACE("%s", ebuf); return 0; } /* initialize mutex array */ for (i = 0; i < num_locks; i++) { if (0 != pthread_mutex_init(&ssl_mutexes[i], &pthread_mutex_attr)) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s: error initializing mutex %i of %i", __func__, i, num_locks); DEBUG_TRACE("%s", ebuf); mg_free(ssl_mutexes); return 0; } } } CRYPTO_set_locking_callback(&ssl_locking_callback); CRYPTO_set_id_callback(&mg_current_thread_id); #endif /* OPENSSL_API_1_1 */ #if !defined(NO_SSL_DL) if (!ssllib_dll_handle) { ssllib_dll_handle = load_dll(ebuf, ebuf_len, SSL_LIB, ssl_sw); if (!ssllib_dll_handle) { #if !defined(OPENSSL_API_1_1) mg_free(ssl_mutexes); #endif DEBUG_TRACE("%s", ebuf); return 0; } } #endif /* NO_SSL_DL */ #if defined(OPENSSL_API_1_1) /* Initialize SSL library */ OPENSSL_init_ssl(0, NULL); OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); #else /* Initialize SSL library */ SSL_library_init(); SSL_load_error_strings(); #endif return 1; } static int ssl_use_pem_file(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx, const char *pem, const char *chain) { if (SSL_CTX_use_certificate_file(dom_ctx->ssl_ctx, pem, 1) == 0) { mg_cry_internal(fc(phys_ctx), "%s: cannot open certificate file %s: %s", __func__, pem, ssl_error()); return 0; } /* could use SSL_CTX_set_default_passwd_cb_userdata */ if (SSL_CTX_use_PrivateKey_file(dom_ctx->ssl_ctx, pem, 1) == 0) { mg_cry_internal(fc(phys_ctx), "%s: cannot open private key file %s: %s", __func__, pem, ssl_error()); return 0; } if (SSL_CTX_check_private_key(dom_ctx->ssl_ctx) == 0) { mg_cry_internal(fc(phys_ctx), "%s: certificate and private key do not match: %s", __func__, pem); return 0; } /* In contrast to OpenSSL, wolfSSL does not support certificate * chain files that contain private keys and certificates in * SSL_CTX_use_certificate_chain_file. * The CivetWeb-Server used pem-Files that contained both information. * In order to make wolfSSL work, it is split in two files. * One file that contains key and certificate used by the server and * an optional chain file for the ssl stack. */ if (chain) { if (SSL_CTX_use_certificate_chain_file(dom_ctx->ssl_ctx, chain) == 0) { mg_cry_internal(fc(phys_ctx), "%s: cannot use certificate chain file %s: %s", __func__, pem, ssl_error()); return 0; } } return 1; } #if defined(OPENSSL_API_1_1) static unsigned long ssl_get_protocol(int version_id) { long unsigned ret = (long unsigned)SSL_OP_ALL; if (version_id > 0) ret |= SSL_OP_NO_SSLv2; if (version_id > 1) ret |= SSL_OP_NO_SSLv3; if (version_id > 2) ret |= SSL_OP_NO_TLSv1; if (version_id > 3) ret |= SSL_OP_NO_TLSv1_1; return ret; } #else static long ssl_get_protocol(int version_id) { long ret = (long)SSL_OP_ALL; if (version_id > 0) ret |= SSL_OP_NO_SSLv2; if (version_id > 1) ret |= SSL_OP_NO_SSLv3; if (version_id > 2) ret |= SSL_OP_NO_TLSv1; if (version_id > 3) ret |= SSL_OP_NO_TLSv1_1; return ret; } #endif /* OPENSSL_API_1_1 */ /* SSL callback documentation: * https://www.openssl.org/docs/man1.1.0/ssl/SSL_set_info_callback.html * https://wiki.openssl.org/index.php/Manual:SSL_CTX_set_info_callback(3) * https://linux.die.net/man/3/ssl_set_info_callback */ /* Note: There is no "const" for the first argument in the documentation * examples, however some (maybe most, but not all) headers of OpenSSL versions * / OpenSSL compatibility layers have it. Having a different definition will * cause a warning in C and an error in C++. Use "const SSL *", while * automatical conversion from "SSL *" works for all compilers, but not other * way around */ static void ssl_info_callback(const SSL *ssl, int what, int ret) { (void)ret; if (what & SSL_CB_HANDSHAKE_START) { SSL_get_app_data(ssl); } if (what & SSL_CB_HANDSHAKE_DONE) { /* TODO: check for openSSL 1.1 */ //#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001 // ssl->s3->flags |= SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS; } } static int ssl_servername_callback(SSL *ssl, int *ad, void *arg) { struct mg_context *ctx = (struct mg_context *)arg; struct mg_domain_context *dom = (struct mg_domain_context *)ctx ? &(ctx->dd) : NULL; #if defined(GCC_DIAGNOSTIC) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" #endif /* defined(GCC_DIAGNOSTIC) */ /* We used an aligned pointer in SSL_set_app_data */ struct mg_connection *conn = (struct mg_connection *)SSL_get_app_data(ssl); #if defined(GCC_DIAGNOSTIC) #pragma GCC diagnostic pop #endif /* defined(GCC_DIAGNOSTIC) */ const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); (void)ad; if ((ctx == NULL) || (conn->phys_ctx == ctx)) { DEBUG_TRACE("%s", "internal error - assertion failed"); return SSL_TLSEXT_ERR_NOACK; } /* Old clients (Win XP) will not support SNI. Then, there * is no server name available in the request - we can * only work with the default certificate. * Multiple HTTPS hosts on one IP+port are only possible * with a certificate containing all alternative names. */ if ((servername == NULL) || (*servername == 0)) { DEBUG_TRACE("%s", "SSL connection not supporting SNI"); conn->dom_ctx = &(ctx->dd); SSL_set_SSL_CTX(ssl, conn->dom_ctx->ssl_ctx); return SSL_TLSEXT_ERR_NOACK; } DEBUG_TRACE("TLS connection to host %s", servername); while (dom) { if (!mg_strcasecmp(servername, dom->config[AUTHENTICATION_DOMAIN])) { /* Found matching domain */ DEBUG_TRACE("TLS domain %s found", dom->config[AUTHENTICATION_DOMAIN]); SSL_set_SSL_CTX(ssl, dom->ssl_ctx); conn->dom_ctx = dom; return SSL_TLSEXT_ERR_OK; } dom = dom->next; } /* Default domain */ DEBUG_TRACE("TLS default domain %s used", ctx->dd.config[AUTHENTICATION_DOMAIN]); conn->dom_ctx = &(ctx->dd); SSL_set_SSL_CTX(ssl, conn->dom_ctx->ssl_ctx); return SSL_TLSEXT_ERR_OK; } /* Setup SSL CTX as required by CivetWeb */ static int init_ssl_ctx_impl(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx, const char *pem, const char *chain) { int callback_ret; int should_verify_peer; int peer_certificate_optional; const char *ca_path; const char *ca_file; int use_default_verify_paths; int verify_depth; struct timespec now_mt; md5_byte_t ssl_context_id[16]; md5_state_t md5state; int protocol_ver; #if defined(OPENSSL_API_1_1) if ((dom_ctx->ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) { mg_cry_internal(fc(phys_ctx), "SSL_CTX_new (server) error: %s", ssl_error()); return 0; } #else if ((dom_ctx->ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) { mg_cry_internal(fc(phys_ctx), "SSL_CTX_new (server) error: %s", ssl_error()); return 0; } #endif /* OPENSSL_API_1_1 */ SSL_CTX_clear_options(dom_ctx->ssl_ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1); protocol_ver = atoi(dom_ctx->config[SSL_PROTOCOL_VERSION]); SSL_CTX_set_options(dom_ctx->ssl_ctx, ssl_get_protocol(protocol_ver)); SSL_CTX_set_options(dom_ctx->ssl_ctx, SSL_OP_SINGLE_DH_USE); SSL_CTX_set_options(dom_ctx->ssl_ctx, SSL_OP_CIPHER_SERVER_PREFERENCE); SSL_CTX_set_options(dom_ctx->ssl_ctx, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION); SSL_CTX_set_options(dom_ctx->ssl_ctx, SSL_OP_NO_COMPRESSION); #if !defined(NO_SSL_DL) SSL_CTX_set_ecdh_auto(dom_ctx->ssl_ctx, 1); #endif /* NO_SSL_DL */ /* In SSL documentation examples callback defined without const specifier * 'void (*)(SSL *, int, int)' See: * https://www.openssl.org/docs/man1.0.2/ssl/ssl.html * https://www.openssl.org/docs/man1.1.0/ssl/ssl.html * But in the source code const SSL is used: * 'void (*)(const SSL *, int, int)' See: * https://github.com/openssl/openssl/blob/1d97c8435171a7af575f73c526d79e1ef0ee5960/ssl/ssl.h#L1173 * Problem about wrong documentation described, but not resolved: * https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/1147526 * Wrong const cast ignored on C or can be suppressed by compiler flags. * But when compiled with modern C++ compiler, correct const should be * provided */ SSL_CTX_set_info_callback(dom_ctx->ssl_ctx, ssl_info_callback); SSL_CTX_set_tlsext_servername_callback(dom_ctx->ssl_ctx, ssl_servername_callback); SSL_CTX_set_tlsext_servername_arg(dom_ctx->ssl_ctx, phys_ctx); /* If a callback has been specified, call it. */ callback_ret = (phys_ctx->callbacks.init_ssl == NULL) ? 0 : (phys_ctx->callbacks.init_ssl(dom_ctx->ssl_ctx, phys_ctx->user_data)); /* If callback returns 0, civetweb sets up the SSL certificate. * If it returns 1, civetweb assumes the calback already did this. * If it returns -1, initializing ssl fails. */ if (callback_ret < 0) { mg_cry_internal(fc(phys_ctx), "SSL callback returned error: %i", callback_ret); return 0; } if (callback_ret > 0) { /* Callback did everything. */ return 1; } /* Use some combination of start time, domain and port as a SSL * context ID. This should be unique on the current machine. */ md5_init(&md5state); clock_gettime(CLOCK_MONOTONIC, &now_mt); md5_append(&md5state, (const md5_byte_t *)&now_mt, sizeof(now_mt)); md5_append(&md5state, (const md5_byte_t *)phys_ctx->dd.config[LISTENING_PORTS], strlen(phys_ctx->dd.config[LISTENING_PORTS])); md5_append(&md5state, (const md5_byte_t *)dom_ctx->config[AUTHENTICATION_DOMAIN], strlen(dom_ctx->config[AUTHENTICATION_DOMAIN])); md5_append(&md5state, (const md5_byte_t *)phys_ctx, sizeof(*phys_ctx)); md5_append(&md5state, (const md5_byte_t *)dom_ctx, sizeof(*dom_ctx)); md5_finish(&md5state, ssl_context_id); SSL_CTX_set_session_id_context(dom_ctx->ssl_ctx, (unsigned char *)ssl_context_id, sizeof(ssl_context_id)); if (pem != NULL) { if (!ssl_use_pem_file(phys_ctx, dom_ctx, pem, chain)) { return 0; } } /* Should we support client certificates? */ /* Default is "no". */ should_verify_peer = 0; peer_certificate_optional = 0; if (dom_ctx->config[SSL_DO_VERIFY_PEER] != NULL) { if (mg_strcasecmp(dom_ctx->config[SSL_DO_VERIFY_PEER], "yes") == 0) { /* Yes, they are mandatory */ should_verify_peer = 1; peer_certificate_optional = 0; } else if (mg_strcasecmp(dom_ctx->config[SSL_DO_VERIFY_PEER], "optional") == 0) { /* Yes, they are optional */ should_verify_peer = 1; peer_certificate_optional = 1; } } use_default_verify_paths = (dom_ctx->config[SSL_DEFAULT_VERIFY_PATHS] != NULL) && (mg_strcasecmp(dom_ctx->config[SSL_DEFAULT_VERIFY_PATHS], "yes") == 0); if (should_verify_peer) { ca_path = dom_ctx->config[SSL_CA_PATH]; ca_file = dom_ctx->config[SSL_CA_FILE]; if (SSL_CTX_load_verify_locations(dom_ctx->ssl_ctx, ca_file, ca_path) != 1) { mg_cry_internal(fc(phys_ctx), "SSL_CTX_load_verify_locations error: %s " "ssl_verify_peer requires setting " "either ssl_ca_path or ssl_ca_file. " "Is any of them present in the " ".conf file?", ssl_error()); return 0; } if (peer_certificate_optional) { SSL_CTX_set_verify(dom_ctx->ssl_ctx, SSL_VERIFY_PEER, NULL); } else { SSL_CTX_set_verify(dom_ctx->ssl_ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); } if (use_default_verify_paths && (SSL_CTX_set_default_verify_paths(dom_ctx->ssl_ctx) != 1)) { mg_cry_internal(fc(phys_ctx), "SSL_CTX_set_default_verify_paths error: %s", ssl_error()); return 0; } if (dom_ctx->config[SSL_VERIFY_DEPTH]) { verify_depth = atoi(dom_ctx->config[SSL_VERIFY_DEPTH]); SSL_CTX_set_verify_depth(dom_ctx->ssl_ctx, verify_depth); } } if (dom_ctx->config[SSL_CIPHER_LIST] != NULL) { if (SSL_CTX_set_cipher_list(dom_ctx->ssl_ctx, dom_ctx->config[SSL_CIPHER_LIST]) != 1) { mg_cry_internal(fc(phys_ctx), "SSL_CTX_set_cipher_list error: %s", ssl_error()); } } return 1; } /* Check if SSL is required. * If so, dynamically load SSL library * and set up ctx->ssl_ctx pointer. */ static int init_ssl_ctx(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx) { void *ssl_ctx = 0; int callback_ret; const char *pem; const char *chain; char ebuf[128]; if (!phys_ctx) { return 0; } if (!dom_ctx) { dom_ctx = &(phys_ctx->dd); } if (!is_ssl_port_used(dom_ctx->config[LISTENING_PORTS])) { /* No SSL port is set. No need to setup SSL. */ return 1; } /* Check for external SSL_CTX */ callback_ret = (phys_ctx->callbacks.external_ssl_ctx == NULL) ? 0 : (phys_ctx->callbacks.external_ssl_ctx(&ssl_ctx, phys_ctx->user_data)); if (callback_ret < 0) { mg_cry_internal(fc(phys_ctx), "external_ssl_ctx callback returned error: %i", callback_ret); return 0; } else if (callback_ret > 0) { dom_ctx->ssl_ctx = (SSL_CTX *)ssl_ctx; if (!initialize_ssl(ebuf, sizeof(ebuf))) { mg_cry_internal(fc(phys_ctx), "%s", ebuf); return 0; } return 1; } /* else: external_ssl_ctx does not exist or returns 0, * CivetWeb should continue initializing SSL */ /* If PEM file is not specified and the init_ssl callback * is not specified, setup will fail. */ if (((pem = dom_ctx->config[SSL_CERTIFICATE]) == NULL) && (phys_ctx->callbacks.init_ssl == NULL)) { /* No certificate and no callback: * Essential data to set up TLS is missing. */ mg_cry_internal(fc(phys_ctx), "Initializing SSL failed: -%s is not set", config_options[SSL_CERTIFICATE].name); return 0; } chain = dom_ctx->config[SSL_CERTIFICATE_CHAIN]; if (chain == NULL) { chain = pem; } if ((chain != NULL) && (*chain == 0)) { chain = NULL; } if (!initialize_ssl(ebuf, sizeof(ebuf))) { mg_cry_internal(fc(phys_ctx), "%s", ebuf); return 0; } return init_ssl_ctx_impl(phys_ctx, dom_ctx, pem, chain); } static void uninitialize_ssl(void) { #if defined(OPENSSL_API_1_1) if (mg_atomic_dec(&cryptolib_users) == 0) { /* Shutdown according to * https://wiki.openssl.org/index.php/Library_Initialization#Cleanup * http://stackoverflow.com/questions/29845527/how-to-properly-uninitialize-openssl */ CONF_modules_unload(1); #else int i; if (mg_atomic_dec(&cryptolib_users) == 0) { /* Shutdown according to * https://wiki.openssl.org/index.php/Library_Initialization#Cleanup * http://stackoverflow.com/questions/29845527/how-to-properly-uninitialize-openssl */ CRYPTO_set_locking_callback(NULL); CRYPTO_set_id_callback(NULL); ENGINE_cleanup(); CONF_modules_unload(1); ERR_free_strings(); EVP_cleanup(); CRYPTO_cleanup_all_ex_data(); OPENSSL_REMOVE_THREAD_STATE(); for (i = 0; i < CRYPTO_num_locks(); i++) { pthread_mutex_destroy(&ssl_mutexes[i]); } mg_free(ssl_mutexes); ssl_mutexes = NULL; #endif /* OPENSSL_API_1_1 */ } } #endif /* !NO_SSL */ static int set_gpass_option(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx) { if (phys_ctx) { struct mg_file file = STRUCT_FILE_INITIALIZER; const char *path; if (!dom_ctx) { dom_ctx = &(phys_ctx->dd); } path = dom_ctx->config[GLOBAL_PASSWORDS_FILE]; if ((path != NULL) && !mg_stat(fc(phys_ctx), path, &file.stat)) { mg_cry_internal(fc(phys_ctx), "Cannot open %s: %s", path, strerror(ERRNO)); return 0; } return 1; } return 0; } static int set_acl_option(struct mg_context *phys_ctx) { return check_acl(phys_ctx, (uint32_t)0x7f000001UL) != -1; } static void reset_per_request_attributes(struct mg_connection *conn) { if (!conn) { return; } conn->connection_type = CONNECTION_TYPE_INVALID; /* Not yet a valid request/response */ conn->num_bytes_sent = conn->consumed_content = 0; conn->path_info = NULL; conn->status_code = -1; conn->content_len = -1; conn->is_chunked = 0; conn->must_close = 0; conn->request_len = 0; conn->throttle = 0; conn->data_len = 0; conn->chunk_remainder = 0; conn->accept_gzip = 0; conn->response_info.content_length = conn->request_info.content_length = -1; conn->response_info.http_version = conn->request_info.http_version = NULL; conn->response_info.num_headers = conn->request_info.num_headers = 0; conn->response_info.status_text = NULL; conn->response_info.status_code = 0; conn->request_info.remote_user = NULL; conn->request_info.request_method = NULL; conn->request_info.request_uri = NULL; conn->request_info.local_uri = NULL; #if defined(MG_LEGACY_INTERFACE) /* Legacy before split into local_uri and request_uri */ conn->request_info.uri = NULL; #endif } #if 0 /* Note: set_sock_timeout is not required for non-blocking sockets. * Leave this function here (commented out) for reference until * CivetWeb 1.9 is tested, and the tests confirme this function is * no longer required. */ static int set_sock_timeout(SOCKET sock, int milliseconds) { int r0 = 0, r1, r2; #if defined(_WIN32) /* Windows specific */ DWORD tv = (DWORD)milliseconds; #else /* Linux, ... (not Windows) */ struct timeval tv; /* TCP_USER_TIMEOUT/RFC5482 (http://tools.ietf.org/html/rfc5482): * max. time waiting for the acknowledged of TCP data before the connection * will be forcefully closed and ETIMEDOUT is returned to the application. * If this option is not set, the default timeout of 20-30 minutes is used. */ /* #define TCP_USER_TIMEOUT (18) */ #if defined(TCP_USER_TIMEOUT) unsigned int uto = (unsigned int)milliseconds; r0 = setsockopt(sock, 6, TCP_USER_TIMEOUT, (const void *)&uto, sizeof(uto)); #endif memset(&tv, 0, sizeof(tv)); tv.tv_sec = milliseconds / 1000; tv.tv_usec = (milliseconds * 1000) % 1000000; #endif /* _WIN32 */ r1 = setsockopt( sock, SOL_SOCKET, SO_RCVTIMEO, (SOCK_OPT_TYPE)&tv, sizeof(tv)); r2 = setsockopt( sock, SOL_SOCKET, SO_SNDTIMEO, (SOCK_OPT_TYPE)&tv, sizeof(tv)); return r0 || r1 || r2; } #endif static int set_tcp_nodelay(SOCKET sock, int nodelay_on) { if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (SOCK_OPT_TYPE)&nodelay_on, sizeof(nodelay_on)) != 0) { /* Error */ return 1; } /* OK */ return 0; } static void close_socket_gracefully(struct mg_connection *conn) { #if defined(_WIN32) char buf[MG_BUF_LEN]; int n; #endif struct linger linger; int error_code = 0; int linger_timeout = -2; socklen_t opt_len = sizeof(error_code); if (!conn) { return; } /* http://msdn.microsoft.com/en-us/library/ms739165(v=vs.85).aspx: * "Note that enabling a nonzero timeout on a nonblocking socket * is not recommended.", so set it to blocking now */ set_blocking_mode(conn->client.sock); /* Send FIN to the client */ shutdown(conn->client.sock, SHUTDOWN_WR); #if defined(_WIN32) /* Read and discard pending incoming data. If we do not do that and * close * the socket, the data in the send buffer may be discarded. This * behaviour is seen on Windows, when client keeps sending data * when server decides to close the connection; then when client * does recv() it gets no data back. */ do { n = pull_inner(NULL, conn, buf, sizeof(buf), /* Timeout in s: */ 1.0); } while (n > 0); #endif if (conn->dom_ctx->config[LINGER_TIMEOUT]) { linger_timeout = atoi(conn->dom_ctx->config[LINGER_TIMEOUT]); } /* Set linger option according to configuration */ if (linger_timeout >= 0) { /* Set linger option to avoid socket hanging out after close. This * prevent ephemeral port exhaust problem under high QPS. */ linger.l_onoff = 1; #if defined(_MSC_VER) #pragma warning(push) #pragma warning(disable : 4244) #endif #if defined(GCC_DIAGNOSTIC) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" #endif /* Data type of linger structure elements may differ, * so we don't know what cast we need here. * Disable type conversion warnings. */ linger.l_linger = (linger_timeout + 999) / 1000; #if defined(GCC_DIAGNOSTIC) #pragma GCC diagnostic pop #endif #if defined(_MSC_VER) #pragma warning(pop) #endif } else { linger.l_onoff = 0; linger.l_linger = 0; } if (linger_timeout < -1) { /* Default: don't configure any linger */ } else if (getsockopt(conn->client.sock, SOL_SOCKET, SO_ERROR, #if defined(_WIN32) /* WinSock uses different data type here */ (char *)&error_code, #else &error_code, #endif &opt_len) != 0) { /* Cannot determine if socket is already closed. This should * not occur and never did in a test. Log an error message * and continue. */ mg_cry_internal(conn, "%s: getsockopt(SOL_SOCKET SO_ERROR) failed: %s", __func__, strerror(ERRNO)); } else if (error_code == ECONNRESET) { /* Socket already closed by client/peer, close socket without linger */ } else { /* Set linger timeout */ if (setsockopt(conn->client.sock, SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(linger)) != 0) { mg_cry_internal( conn, "%s: setsockopt(SOL_SOCKET SO_LINGER(%i,%i)) failed: %s", __func__, linger.l_onoff, linger.l_linger, strerror(ERRNO)); } } /* Now we know that our FIN is ACK-ed, safe to close */ closesocket(conn->client.sock); conn->client.sock = INVALID_SOCKET; } static void close_connection(struct mg_connection *conn) { #if defined(USE_SERVER_STATS) conn->conn_state = 6; /* to close */ #endif #if defined(USE_LUA) && defined(USE_WEBSOCKET) if (conn->lua_websocket_state) { lua_websocket_close(conn, conn->lua_websocket_state); conn->lua_websocket_state = NULL; } #endif mg_lock_connection(conn); /* Set close flag, so keep-alive loops will stop */ conn->must_close = 1; /* call the connection_close callback if assigned */ if (conn->phys_ctx->callbacks.connection_close != NULL) { if (conn->phys_ctx->context_type == CONTEXT_SERVER) { conn->phys_ctx->callbacks.connection_close(conn); } } /* Reset user data, after close callback is called. * Do not reuse it. If the user needs a destructor, * it must be done in the connection_close callback. */ mg_set_user_connection_data(conn, NULL); #if defined(USE_SERVER_STATS) conn->conn_state = 7; /* closing */ #endif #if !defined(NO_SSL) if (conn->ssl != NULL) { /* Run SSL_shutdown twice to ensure completely close SSL connection */ SSL_shutdown(conn->ssl); SSL_free(conn->ssl); OPENSSL_REMOVE_THREAD_STATE(); conn->ssl = NULL; } #endif if (conn->client.sock != INVALID_SOCKET) { close_socket_gracefully(conn); conn->client.sock = INVALID_SOCKET; } if (conn->host) { mg_free((void *)conn->host); conn->host = NULL; } mg_unlock_connection(conn); #if defined(USE_SERVER_STATS) conn->conn_state = 8; /* closed */ #endif } void mg_close_connection(struct mg_connection *conn) { #if defined(USE_WEBSOCKET) struct mg_context *client_ctx = NULL; #endif /* defined(USE_WEBSOCKET) */ if ((conn == NULL) || (conn->phys_ctx == NULL)) { return; } #if defined(USE_WEBSOCKET) if (conn->phys_ctx->context_type == CONTEXT_SERVER) { if (conn->in_websocket_handling) { /* Set close flag, so the server thread can exit. */ conn->must_close = 1; return; } } if (conn->phys_ctx->context_type == CONTEXT_WS_CLIENT) { unsigned int i; /* ws/wss client */ client_ctx = conn->phys_ctx; /* client context: loops must end */ client_ctx->stop_flag = 1; conn->must_close = 1; /* We need to get the client thread out of the select/recv call * here. */ /* Since we use a sleep quantum of some seconds to check for recv * timeouts, we will just wait a few seconds in mg_join_thread. */ /* join worker thread */ for (i = 0; i < client_ctx->cfg_worker_threads; i++) { if (client_ctx->worker_threadids[i] != 0) { mg_join_thread(client_ctx->worker_threadids[i]); } } } #endif /* defined(USE_WEBSOCKET) */ close_connection(conn); #if !defined(NO_SSL) if (conn->client_ssl_ctx != NULL) { SSL_CTX_free((SSL_CTX *)conn->client_ssl_ctx); } #endif #if defined(USE_WEBSOCKET) if (client_ctx != NULL) { /* free context */ mg_free(client_ctx->worker_threadids); mg_free(client_ctx); (void)pthread_mutex_destroy(&conn->mutex); mg_free(conn); } else if (conn->phys_ctx->context_type == CONTEXT_HTTP_CLIENT) { mg_free(conn); } #else if (conn->phys_ctx->context_type == CONTEXT_HTTP_CLIENT) { /* Client */ mg_free(conn); } #endif /* defined(USE_WEBSOCKET) */ } /* Only for memory statistics */ static struct mg_context common_client_context; static struct mg_connection * mg_connect_client_impl(const struct mg_client_options *client_options, int use_ssl, char *ebuf, size_t ebuf_len) { struct mg_connection *conn = NULL; SOCKET sock; union usa sa; struct sockaddr *psa; socklen_t len; unsigned max_req_size = (unsigned)atoi(config_options[MAX_REQUEST_SIZE].default_value); /* Size of structures, aligned to 8 bytes */ size_t conn_size = ((sizeof(struct mg_connection) + 7) >> 3) << 3; size_t ctx_size = ((sizeof(struct mg_context) + 7) >> 3) << 3; conn = (struct mg_connection *)mg_calloc_ctx( 1, conn_size + ctx_size + max_req_size, &common_client_context); if (conn == NULL) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "calloc(): %s", strerror(ERRNO)); return NULL; } #if defined(GCC_DIAGNOSTIC) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" #endif /* defined(GCC_DIAGNOSTIC) */ /* conn_size is aligned to 8 bytes */ conn->phys_ctx = (struct mg_context *)(((char *)conn) + conn_size); #if defined(GCC_DIAGNOSTIC) #pragma GCC diagnostic pop #endif /* defined(GCC_DIAGNOSTIC) */ conn->buf = (((char *)conn) + conn_size + ctx_size); conn->buf_size = (int)max_req_size; conn->phys_ctx->context_type = CONTEXT_HTTP_CLIENT; conn->dom_ctx = &(conn->phys_ctx->dd); if (!connect_socket(&common_client_context, client_options->host, client_options->port, use_ssl, ebuf, ebuf_len, &sock, &sa)) { /* ebuf is set by connect_socket, * free all memory and return NULL; */ mg_free(conn); return NULL; } #if !defined(NO_SSL) #if defined(OPENSSL_API_1_1) if (use_ssl && (conn->client_ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "SSL_CTX_new error"); closesocket(sock); mg_free(conn); return NULL; } #else if (use_ssl && (conn->client_ssl_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "SSL_CTX_new error"); closesocket(sock); mg_free(conn); return NULL; } #endif /* OPENSSL_API_1_1 */ #endif /* NO_SSL */ #if defined(USE_IPV6) len = (sa.sa.sa_family == AF_INET) ? sizeof(conn->client.rsa.sin) : sizeof(conn->client.rsa.sin6); psa = (sa.sa.sa_family == AF_INET) ? (struct sockaddr *)&(conn->client.rsa.sin) : (struct sockaddr *)&(conn->client.rsa.sin6); #else len = sizeof(conn->client.rsa.sin); psa = (struct sockaddr *)&(conn->client.rsa.sin); #endif conn->client.sock = sock; conn->client.lsa = sa; if (getsockname(sock, psa, &len) != 0) { mg_cry_internal(conn, "%s: getsockname() failed: %s", __func__, strerror(ERRNO)); } conn->client.is_ssl = use_ssl ? 1 : 0; if (0 != pthread_mutex_init(&conn->mutex, &pthread_mutex_attr)) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "Can not create mutex"); #if !defined(NO_SSL) SSL_CTX_free(conn->client_ssl_ctx); #endif closesocket(sock); mg_free(conn); return NULL; } #if !defined(NO_SSL) if (use_ssl) { common_client_context.dd.ssl_ctx = conn->client_ssl_ctx; /* TODO: Check ssl_verify_peer and ssl_ca_path here. * SSL_CTX_set_verify call is needed to switch off server * certificate checking, which is off by default in OpenSSL and * on in yaSSL. */ /* TODO: SSL_CTX_set_verify(conn->client_ssl_ctx, * SSL_VERIFY_PEER, verify_ssl_server); */ if (client_options->client_cert) { if (!ssl_use_pem_file(&common_client_context, &(common_client_context.dd), client_options->client_cert, NULL)) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "Can not use SSL client certificate"); SSL_CTX_free(conn->client_ssl_ctx); closesocket(sock); mg_free(conn); return NULL; } } if (client_options->server_cert) { SSL_CTX_load_verify_locations(conn->client_ssl_ctx, client_options->server_cert, NULL); SSL_CTX_set_verify(conn->client_ssl_ctx, SSL_VERIFY_PEER, NULL); } else { SSL_CTX_set_verify(conn->client_ssl_ctx, SSL_VERIFY_NONE, NULL); } if (!sslize(conn, conn->client_ssl_ctx, SSL_connect, &(conn->phys_ctx->stop_flag), client_options)) { mg_snprintf(NULL, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "SSL connection error"); SSL_CTX_free(conn->client_ssl_ctx); closesocket(sock); mg_free(conn); return NULL; } } #endif if (0 != set_non_blocking_mode(sock)) { mg_cry_internal(conn, "Cannot set non-blocking mode for client %s:%i", client_options->host, client_options->port); } return conn; } CIVETWEB_API struct mg_connection * mg_connect_client_secure(const struct mg_client_options *client_options, char *error_buffer, size_t error_buffer_size) { return mg_connect_client_impl(client_options, 1, error_buffer, error_buffer_size); } struct mg_connection * mg_connect_client(const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size) { struct mg_client_options opts; memset(&opts, 0, sizeof(opts)); opts.host = host; opts.port = port; return mg_connect_client_impl(&opts, use_ssl, error_buffer, error_buffer_size); } static const struct { const char *proto; size_t proto_len; unsigned default_port; } abs_uri_protocols[] = {{"http://", 7, 80}, {"https://", 8, 443}, {"ws://", 5, 80}, {"wss://", 6, 443}, {NULL, 0, 0}}; /* Check if the uri is valid. * return 0 for invalid uri, * return 1 for *, * return 2 for relative uri, * return 3 for absolute uri without port, * return 4 for absolute uri with port */ static int get_uri_type(const char *uri) { int i; const char *hostend, *portbegin; char *portend; unsigned long port; /* According to the HTTP standard * http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2 * URI can be an asterisk (*) or should start with slash (relative uri), * or it should start with the protocol (absolute uri). */ if ((uri[0] == '*') && (uri[1] == '\0')) { /* asterisk */ return 1; } /* Valid URIs according to RFC 3986 * (https://www.ietf.org/rfc/rfc3986.txt) * must only contain reserved characters :/?#[]@!$&'()*+,;= * and unreserved characters A-Z a-z 0-9 and -._~ * and % encoded symbols. */ for (i = 0; uri[i] != 0; i++) { if (uri[i] < 33) { /* control characters and spaces are invalid */ return 0; } if (uri[i] > 126) { /* non-ascii characters must be % encoded */ return 0; } else { switch (uri[i]) { case '"': /* 34 */ case '<': /* 60 */ case '>': /* 62 */ case '\\': /* 92 */ case '^': /* 94 */ case '`': /* 96 */ case '{': /* 123 */ case '|': /* 124 */ case '}': /* 125 */ return 0; default: /* character is ok */ break; } } } /* A relative uri starts with a / character */ if (uri[0] == '/') { /* relative uri */ return 2; } /* It could be an absolute uri: */ /* This function only checks if the uri is valid, not if it is * addressing the current server. So civetweb can also be used * as a proxy server. */ for (i = 0; abs_uri_protocols[i].proto != NULL; i++) { if (mg_strncasecmp(uri, abs_uri_protocols[i].proto, abs_uri_protocols[i].proto_len) == 0) { hostend = strchr(uri + abs_uri_protocols[i].proto_len, '/'); if (!hostend) { return 0; } portbegin = strchr(uri + abs_uri_protocols[i].proto_len, ':'); if (!portbegin) { return 3; } port = strtoul(portbegin + 1, &portend, 10); if ((portend != hostend) || (port <= 0) || !is_valid_port(port)) { return 0; } return 4; } } return 0; } /* Return NULL or the relative uri at the current server */ static const char * get_rel_url_at_current_server(const char *uri, const struct mg_connection *conn) { const char *server_domain; size_t server_domain_len; size_t request_domain_len = 0; unsigned long port = 0; int i, auth_domain_check_enabled; const char *hostbegin = NULL; const char *hostend = NULL; const char *portbegin; char *portend; auth_domain_check_enabled = !mg_strcasecmp(conn->dom_ctx->config[ENABLE_AUTH_DOMAIN_CHECK], "yes"); /* DNS is case insensitive, so use case insensitive string compare here */ for (i = 0; abs_uri_protocols[i].proto != NULL; i++) { if (mg_strncasecmp(uri, abs_uri_protocols[i].proto, abs_uri_protocols[i].proto_len) == 0) { hostbegin = uri + abs_uri_protocols[i].proto_len; hostend = strchr(hostbegin, '/'); if (!hostend) { return 0; } portbegin = strchr(hostbegin, ':'); if ((!portbegin) || (portbegin > hostend)) { port = abs_uri_protocols[i].default_port; request_domain_len = (size_t)(hostend - hostbegin); } else { port = strtoul(portbegin + 1, &portend, 10); if ((portend != hostend) || (port <= 0) || !is_valid_port(port)) { return 0; } request_domain_len = (size_t)(portbegin - hostbegin); } /* protocol found, port set */ break; } } if (!port) { /* port remains 0 if the protocol is not found */ return 0; } /* Check if the request is directed to a different server. */ /* First check if the port is the same (IPv4 and IPv6). */ #if defined(USE_IPV6) if (conn->client.lsa.sa.sa_family == AF_INET6) { if (ntohs(conn->client.lsa.sin6.sin6_port) != port) { /* Request is directed to a different port */ return 0; } } else #endif { if (ntohs(conn->client.lsa.sin.sin_port) != port) { /* Request is directed to a different port */ return 0; } } /* Finally check if the server corresponds to the authentication * domain of the server (the server domain). * Allow full matches (like http://mydomain.com/path/file.ext), and * allow subdomain matches (like http://www.mydomain.com/path/file.ext), * but do not allow substrings (like * http://notmydomain.com/path/file.ext * or http://mydomain.com.fake/path/file.ext). */ if (auth_domain_check_enabled) { server_domain = conn->dom_ctx->config[AUTHENTICATION_DOMAIN]; server_domain_len = strlen(server_domain); if ((server_domain_len == 0) || (hostbegin == NULL)) { return 0; } if ((request_domain_len == server_domain_len) && (!memcmp(server_domain, hostbegin, server_domain_len))) { /* Request is directed to this server - full name match. */ } else { if (request_domain_len < (server_domain_len + 2)) { /* Request is directed to another server: The server name * is longer than the request name. * Drop this case here to avoid overflows in the * following checks. */ return 0; } if (hostbegin[request_domain_len - server_domain_len - 1] != '.') { /* Request is directed to another server: It could be a * substring * like notmyserver.com */ return 0; } if (0 != memcmp(server_domain, hostbegin + request_domain_len - server_domain_len, server_domain_len)) { /* Request is directed to another server: * The server name is different. */ return 0; } } } return hostend; } static int get_message(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err) { if (ebuf_len > 0) { ebuf[0] = '\0'; } *err = 0; reset_per_request_attributes(conn); if (!conn) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Internal error"); *err = 500; return 0; } /* Set the time the request was received. This value should be used for * timeouts. */ clock_gettime(CLOCK_MONOTONIC, &(conn->req_time)); conn->request_len = read_message(NULL, conn, conn->buf, conn->buf_size, &conn->data_len); DEBUG_ASSERT(conn->request_len < 0 || conn->data_len >= conn->request_len); if ((conn->request_len >= 0) && (conn->data_len < conn->request_len)) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Invalid message size"); *err = 500; return 0; } if ((conn->request_len == 0) && (conn->data_len == conn->buf_size)) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Message too large"); *err = 413; return 0; } if (conn->request_len <= 0) { if (conn->data_len > 0) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Malformed message"); *err = 400; } else { /* Server did not recv anything -> just close the connection */ conn->must_close = 1; mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "No data received"); *err = 0; } return 0; } return 1; } static int get_request(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err) { const char *cl; if (!get_message(conn, ebuf, ebuf_len, err)) { return 0; } if (parse_http_request(conn->buf, conn->buf_size, &conn->request_info) <= 0) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Bad request"); *err = 400; return 0; } /* Message is a valid request */ /* Is there a "host" ? */ if (conn->host != NULL) { mg_free((void *)conn->host); } conn->host = alloc_get_host(conn); if (!conn->host) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Bad request: Host mismatch"); *err = 400; return 0; } /* Do we know the content length? */ if ((cl = get_header(conn->request_info.http_headers, conn->request_info.num_headers, "Content-Length")) != NULL) { /* Request/response has content length set */ char *endptr = NULL; conn->content_len = strtoll(cl, &endptr, 10); if (endptr == cl) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Bad request"); *err = 411; return 0; } /* Publish the content length back to the request info. */ conn->request_info.content_length = conn->content_len; } else if ((cl = get_header(conn->request_info.http_headers, conn->request_info.num_headers, "Transfer-Encoding")) != NULL && !mg_strcasecmp(cl, "chunked")) { conn->is_chunked = 1; conn->content_len = -1; /* unknown content length */ } else { const struct mg_http_method_info *meth = get_http_method_info(conn->request_info.request_method); if (!meth) { /* No valid HTTP method */ mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Bad request"); *err = 411; return 0; } if (meth->request_has_body) { /* POST or PUT request without content length set */ conn->content_len = -1; /* unknown content length */ } else { /* Other request */ conn->content_len = 0; /* No content */ } } conn->connection_type = CONNECTION_TYPE_REQUEST; /* Valid request */ return 1; } /* conn is assumed to be valid in this internal function */ static int get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err) { const char *cl; if (!get_message(conn, ebuf, ebuf_len, err)) { return 0; } if (parse_http_response(conn->buf, conn->buf_size, &conn->response_info) <= 0) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Bad response"); *err = 400; return 0; } /* Message is a valid response */ /* Do we know the content length? */ if ((cl = get_header(conn->response_info.http_headers, conn->response_info.num_headers, "Content-Length")) != NULL) { /* Request/response has content length set */ char *endptr = NULL; conn->content_len = strtoll(cl, &endptr, 10); if (endptr == cl) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Bad request"); *err = 411; return 0; } /* Publish the content length back to the response info. */ conn->response_info.content_length = conn->content_len; /* TODO: check if it is still used in response_info */ conn->request_info.content_length = conn->content_len; } else if ((cl = get_header(conn->response_info.http_headers, conn->response_info.num_headers, "Transfer-Encoding")) != NULL && !mg_strcasecmp(cl, "chunked")) { conn->is_chunked = 1; conn->content_len = -1; /* unknown content length */ } else { conn->content_len = -1; /* unknown content length */ } conn->connection_type = CONNECTION_TYPE_RESPONSE; /* Valid response */ return 1; } int mg_get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout) { int err, ret; char txt[32]; /* will not overflow */ char *save_timeout; char *new_timeout; if (ebuf_len > 0) { ebuf[0] = '\0'; } if (!conn) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Parameter error"); return -1; } /* Implementation of API function for HTTP clients */ save_timeout = conn->dom_ctx->config[REQUEST_TIMEOUT]; if (timeout >= 0) { mg_snprintf(conn, NULL, txt, sizeof(txt), "%i", timeout); new_timeout = txt; /* Not required for non-blocking sockets. set_sock_timeout(conn->client.sock, timeout); */ } else { new_timeout = NULL; } conn->dom_ctx->config[REQUEST_TIMEOUT] = new_timeout; ret = get_response(conn, ebuf, ebuf_len, &err); conn->dom_ctx->config[REQUEST_TIMEOUT] = save_timeout; #if defined(MG_LEGACY_INTERFACE) /* TODO: 1) uri is deprecated; * 2) here, ri.uri is the http response code */ conn->request_info.uri = conn->request_info.request_uri; #endif conn->request_info.local_uri = conn->request_info.request_uri; /* TODO (mid): Define proper return values - maybe return length? * For the first test use <0 for error and >0 for OK */ return (ret == 0) ? -1 : +1; } struct mg_connection * mg_download(const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len, const char *fmt, ...) { struct mg_connection *conn; va_list ap; int i; int reqerr; if (ebuf_len > 0) { ebuf[0] = '\0'; } va_start(ap, fmt); /* open a connection */ conn = mg_connect_client(host, port, use_ssl, ebuf, ebuf_len); if (conn != NULL) { i = mg_vprintf(conn, fmt, ap); if (i <= 0) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, ebuf_len, "%s", "Error sending request"); } else { get_response(conn, ebuf, ebuf_len, &reqerr); #if defined(MG_LEGACY_INTERFACE) /* TODO: 1) uri is deprecated; * 2) here, ri.uri is the http response code */ conn->request_info.uri = conn->request_info.request_uri; #endif conn->request_info.local_uri = conn->request_info.request_uri; } } /* if an error occurred, close the connection */ if ((ebuf[0] != '\0') && (conn != NULL)) { mg_close_connection(conn); conn = NULL; } va_end(ap); return conn; } struct websocket_client_thread_data { struct mg_connection *conn; mg_websocket_data_handler data_handler; mg_websocket_close_handler close_handler; void *callback_data; }; #if defined(USE_WEBSOCKET) #if defined(_WIN32) static unsigned __stdcall websocket_client_thread(void *data) #else static void * websocket_client_thread(void *data) #endif { struct websocket_client_thread_data *cdata = (struct websocket_client_thread_data *)data; #if !defined(_WIN32) struct sigaction sa; /* Ignore SIGPIPE */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, NULL); #endif mg_set_thread_name("ws-clnt"); if (cdata->conn->phys_ctx) { if (cdata->conn->phys_ctx->callbacks.init_thread) { /* 3 indicates a websocket client thread */ /* TODO: check if conn->phys_ctx can be set */ cdata->conn->phys_ctx->callbacks.init_thread(cdata->conn->phys_ctx, 3); } } read_websocket(cdata->conn, cdata->data_handler, cdata->callback_data); DEBUG_TRACE("%s", "Websocket client thread exited\n"); if (cdata->close_handler != NULL) { cdata->close_handler(cdata->conn, cdata->callback_data); } /* The websocket_client context has only this thread. If it runs out, set the stop_flag to 2 (= "stopped"). */ cdata->conn->phys_ctx->stop_flag = 2; mg_free((void *)cdata); #if defined(_WIN32) return 0; #else return NULL; #endif } #endif struct mg_connection * mg_connect_websocket_client(const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, mg_websocket_data_handler data_func, mg_websocket_close_handler close_func, void *user_data) { struct mg_connection *conn = NULL; #if defined(USE_WEBSOCKET) struct mg_context *newctx = NULL; struct websocket_client_thread_data *thread_data; static const char *magic = "x3JJHMbDL1EzLkh9GBhXDw=="; static const char *handshake_req; if (origin != NULL) { handshake_req = "GET %s HTTP/1.1\r\n" "Host: %s\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Key: %s\r\n" "Sec-WebSocket-Version: 13\r\n" "Origin: %s\r\n" "\r\n"; } else { handshake_req = "GET %s HTTP/1.1\r\n" "Host: %s\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Key: %s\r\n" "Sec-WebSocket-Version: 13\r\n" "\r\n"; } #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wformat-nonliteral" #endif /* Establish the client connection and request upgrade */ conn = mg_download(host, port, use_ssl, error_buffer, error_buffer_size, handshake_req, path, host, magic, origin); #if defined(__clang__) #pragma clang diagnostic pop #endif /* Connection object will be null if something goes wrong */ if (conn == NULL) { if (!*error_buffer) { /* There should be already an error message */ mg_snprintf(conn, NULL, /* No truncation check for ebuf */ error_buffer, error_buffer_size, "Unexpected error"); } return NULL; } if (conn->response_info.status_code != 101) { /* We sent an "upgrade" request. For a correct websocket * protocol handshake, we expect a "101 Continue" response. * Otherwise it is a protocol violation. Maybe the HTTP * Server does not know websockets. */ if (!*error_buffer) { /* set an error, if not yet set */ mg_snprintf(conn, NULL, /* No truncation check for ebuf */ error_buffer, error_buffer_size, "Unexpected server reply"); } DEBUG_TRACE("Websocket client connect error: %s\r\n", error_buffer); mg_free(conn); return NULL; } /* For client connections, mg_context is fake. Since we need to set a * callback function, we need to create a copy and modify it. */ newctx = (struct mg_context *)mg_malloc(sizeof(struct mg_context)); if (!newctx) { DEBUG_TRACE("%s\r\n", "Out of memory"); mg_free(conn); return NULL; } memcpy(newctx, conn->phys_ctx, sizeof(struct mg_context)); newctx->user_data = user_data; newctx->context_type = CONTEXT_WS_CLIENT; /* ws/wss client context */ newctx->cfg_worker_threads = 1; /* one worker thread will be created */ newctx->worker_threadids = (pthread_t *)mg_calloc_ctx(newctx->cfg_worker_threads, sizeof(pthread_t), newctx); conn->phys_ctx = newctx; conn->dom_ctx = &(newctx->dd); thread_data = (struct websocket_client_thread_data *) mg_calloc_ctx(sizeof(struct websocket_client_thread_data), 1, newctx); if (!thread_data) { DEBUG_TRACE("%s\r\n", "Out of memory"); mg_free(newctx); mg_free(conn); return NULL; } thread_data->conn = conn; thread_data->data_handler = data_func; thread_data->close_handler = close_func; thread_data->callback_data = user_data; /* Start a thread to read the websocket client connection * This thread will automatically stop when mg_disconnect is * called on the client connection */ if (mg_start_thread_with_id(websocket_client_thread, (void *)thread_data, newctx->worker_threadids) != 0) { mg_free((void *)thread_data); mg_free((void *)newctx->worker_threadids); mg_free((void *)newctx); mg_free((void *)conn); conn = NULL; DEBUG_TRACE("%s", "Websocket client connect thread could not be started\r\n"); } #else /* Appease "unused parameter" warnings */ (void)host; (void)port; (void)use_ssl; (void)error_buffer; (void)error_buffer_size; (void)path; (void)origin; (void)user_data; (void)data_func; (void)close_func; #endif return conn; } /* Prepare connection data structure */ static void init_connection(struct mg_connection *conn) { /* Is keep alive allowed by the server */ int keep_alive_enabled = !mg_strcasecmp(conn->dom_ctx->config[ENABLE_KEEP_ALIVE], "yes"); if (!keep_alive_enabled) { conn->must_close = 1; } /* Important: on new connection, reset the receiving buffer. Credit * goes to crule42. */ conn->data_len = 0; conn->handled_requests = 0; mg_set_user_connection_data(conn, NULL); #if defined(USE_SERVER_STATS) conn->conn_state = 2; /* init */ #endif /* call the init_connection callback if assigned */ if (conn->phys_ctx->callbacks.init_connection != NULL) { if (conn->phys_ctx->context_type == CONTEXT_SERVER) { void *conn_data = NULL; conn->phys_ctx->callbacks.init_connection(conn, &conn_data); mg_set_user_connection_data(conn, conn_data); } } } /* Process a connection - may handle multiple requests * using the same connection. * Must be called with a valid connection (conn and * conn->phys_ctx must be valid). */ static void process_new_connection(struct mg_connection *conn) { struct mg_request_info *ri = &conn->request_info; int keep_alive, discard_len; char ebuf[100]; const char *hostend; int reqerr, uri_type; #if defined(USE_SERVER_STATS) int mcon = mg_atomic_inc(&(conn->phys_ctx->active_connections)); mg_atomic_add(&(conn->phys_ctx->total_connections), 1); if (mcon > (conn->phys_ctx->max_connections)) { /* could use atomic compare exchange, but this * seems overkill for statistics data */ conn->phys_ctx->max_connections = mcon; } #endif init_connection(conn); DEBUG_TRACE("Start processing connection from %s", conn->request_info.remote_addr); /* Loop over multiple requests sent using the same connection * (while "keep alive"). */ do { DEBUG_TRACE("calling get_request (%i times for this connection)", conn->handled_requests + 1); #if defined(USE_SERVER_STATS) conn->conn_state = 3; /* ready */ #endif if (!get_request(conn, ebuf, sizeof(ebuf), &reqerr)) { /* The request sent by the client could not be understood by * the server, or it was incomplete or a timeout. Send an * error message and close the connection. */ if (reqerr > 0) { DEBUG_ASSERT(ebuf[0] != '\0'); mg_send_http_error(conn, reqerr, "%s", ebuf); } } else if (strcmp(ri->http_version, "1.0") && strcmp(ri->http_version, "1.1")) { mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, sizeof(ebuf), "Bad HTTP version: [%s]", ri->http_version); mg_send_http_error(conn, 505, "%s", ebuf); } if (ebuf[0] == '\0') { uri_type = get_uri_type(conn->request_info.request_uri); switch (uri_type) { case 1: /* Asterisk */ conn->request_info.local_uri = NULL; break; case 2: /* relative uri */ conn->request_info.local_uri = conn->request_info.request_uri; break; case 3: case 4: /* absolute uri (with/without port) */ hostend = get_rel_url_at_current_server( conn->request_info.request_uri, conn); if (hostend) { conn->request_info.local_uri = hostend; } else { conn->request_info.local_uri = NULL; } break; default: mg_snprintf(conn, NULL, /* No truncation check for ebuf */ ebuf, sizeof(ebuf), "Invalid URI"); mg_send_http_error(conn, 400, "%s", ebuf); conn->request_info.local_uri = NULL; break; } #if defined(MG_LEGACY_INTERFACE) /* Legacy before split into local_uri and request_uri */ conn->request_info.uri = conn->request_info.local_uri; #endif } DEBUG_TRACE("http: %s, error: %s", (ri->http_version ? ri->http_version : "none"), (ebuf[0] ? ebuf : "none")); if (ebuf[0] == '\0') { if (conn->request_info.local_uri) { /* handle request to local server */ #if defined(USE_SERVER_STATS) conn->conn_state = 4; /* processing */ #endif handle_request(conn); #if defined(USE_SERVER_STATS) conn->conn_state = 5; /* processed */ mg_atomic_add(&(conn->phys_ctx->total_data_read), conn->consumed_content); mg_atomic_add(&(conn->phys_ctx->total_data_written), conn->num_bytes_sent); #endif DEBUG_TRACE("%s", "handle_request done"); if (conn->phys_ctx->callbacks.end_request != NULL) { conn->phys_ctx->callbacks.end_request(conn, conn->status_code); DEBUG_TRACE("%s", "end_request callback done"); } log_access(conn); } else { /* TODO: handle non-local request (PROXY) */ conn->must_close = 1; } } else { conn->must_close = 1; } if (ri->remote_user != NULL) { mg_free((void *)ri->remote_user); /* Important! When having connections with and without auth * would cause double free and then crash */ ri->remote_user = NULL; } /* NOTE(lsm): order is important here. should_keep_alive() call * is using parsed request, which will be invalid after * memmove's below. * Therefore, memorize should_keep_alive() result now for later * use in loop exit condition. */ keep_alive = (conn->phys_ctx->stop_flag == 0) && should_keep_alive(conn) && (conn->content_len >= 0); /* Discard all buffered data for this request */ discard_len = ((conn->content_len >= 0) && (conn->request_len > 0) && ((conn->request_len + conn->content_len) < (int64_t)conn->data_len)) ? (int)(conn->request_len + conn->content_len) : conn->data_len; DEBUG_ASSERT(discard_len >= 0); if (discard_len < 0) { DEBUG_TRACE("internal error: discard_len = %li", (long int)discard_len); break; } conn->data_len -= discard_len; if (conn->data_len > 0) { DEBUG_TRACE("discard_len = %lu", (long unsigned)discard_len); memmove(conn->buf, conn->buf + discard_len, (size_t)conn->data_len); } DEBUG_ASSERT(conn->data_len >= 0); DEBUG_ASSERT(conn->data_len <= conn->buf_size); if ((conn->data_len < 0) || (conn->data_len > conn->buf_size)) { DEBUG_TRACE("internal error: data_len = %li, buf_size = %li", (long int)conn->data_len, (long int)conn->buf_size); break; } conn->handled_requests++; } while (keep_alive); DEBUG_TRACE("Done processing connection from %s (%f sec)", conn->request_info.remote_addr, difftime(time(NULL), conn->conn_birth_time)); close_connection(conn); #if defined(USE_SERVER_STATS) mg_atomic_add(&(conn->phys_ctx->total_requests), conn->handled_requests); mg_atomic_dec(&(conn->phys_ctx->active_connections)); #endif } #if defined(ALTERNATIVE_QUEUE) static void produce_socket(struct mg_context *ctx, const struct socket *sp) { unsigned int i; while (!ctx->stop_flag) { for (i = 0; i < ctx->cfg_worker_threads; i++) { /* find a free worker slot and signal it */ if (ctx->client_socks[i].in_use == 2) { (void)pthread_mutex_lock(&ctx->thread_mutex); if ((ctx->client_socks[i].in_use == 2) && !ctx->stop_flag) { ctx->client_socks[i] = *sp; ctx->client_socks[i].in_use = 1; /* socket has been moved to the consumer */ (void)pthread_mutex_unlock(&ctx->thread_mutex); (void)event_signal(ctx->client_wait_events[i]); return; } (void)pthread_mutex_unlock(&ctx->thread_mutex); } } /* queue is full */ mg_sleep(1); } /* must consume */ set_blocking_mode(sp->sock); closesocket(sp->sock); } static int consume_socket(struct mg_context *ctx, struct socket *sp, int thread_index) { DEBUG_TRACE("%s", "going idle"); (void)pthread_mutex_lock(&ctx->thread_mutex); ctx->client_socks[thread_index].in_use = 2; (void)pthread_mutex_unlock(&ctx->thread_mutex); event_wait(ctx->client_wait_events[thread_index]); (void)pthread_mutex_lock(&ctx->thread_mutex); *sp = ctx->client_socks[thread_index]; if (ctx->stop_flag) { (void)pthread_mutex_unlock(&ctx->thread_mutex); if (sp->in_use == 1) { /* must consume */ set_blocking_mode(sp->sock); closesocket(sp->sock); } return 0; } (void)pthread_mutex_unlock(&ctx->thread_mutex); if (sp->in_use == 1) { DEBUG_TRACE("grabbed socket %d, going busy", sp->sock); return 1; } /* must not reach here */ DEBUG_ASSERT(0); return 0; } #else /* ALTERNATIVE_QUEUE */ /* Worker threads take accepted socket from the queue */ static int consume_socket(struct mg_context *ctx, struct socket *sp, int thread_index) { #define QUEUE_SIZE(ctx) ((int)(ARRAY_SIZE(ctx->queue))) (void)thread_index; (void)pthread_mutex_lock(&ctx->thread_mutex); DEBUG_TRACE("%s", "going idle"); /* If the queue is empty, wait. We're idle at this point. */ while ((ctx->sq_head == ctx->sq_tail) && (ctx->stop_flag == 0)) { pthread_cond_wait(&ctx->sq_full, &ctx->thread_mutex); } /* If we're stopping, sq_head may be equal to sq_tail. */ if (ctx->sq_head > ctx->sq_tail) { /* Copy socket from the queue and increment tail */ *sp = ctx->queue[ctx->sq_tail % QUEUE_SIZE(ctx)]; ctx->sq_tail++; DEBUG_TRACE("grabbed socket %d, going busy", sp ? sp->sock : -1); /* Wrap pointers if needed */ while (ctx->sq_tail > QUEUE_SIZE(ctx)) { ctx->sq_tail -= QUEUE_SIZE(ctx); ctx->sq_head -= QUEUE_SIZE(ctx); } } (void)pthread_cond_signal(&ctx->sq_empty); (void)pthread_mutex_unlock(&ctx->thread_mutex); return !ctx->stop_flag; #undef QUEUE_SIZE } /* Master thread adds accepted socket to a queue */ static void produce_socket(struct mg_context *ctx, const struct socket *sp) { #define QUEUE_SIZE(ctx) ((int)(ARRAY_SIZE(ctx->queue))) if (!ctx) { return; } (void)pthread_mutex_lock(&ctx->thread_mutex); /* If the queue is full, wait */ while ((ctx->stop_flag == 0) && (ctx->sq_head - ctx->sq_tail >= QUEUE_SIZE(ctx))) { (void)pthread_cond_wait(&ctx->sq_empty, &ctx->thread_mutex); } if (ctx->sq_head - ctx->sq_tail < QUEUE_SIZE(ctx)) { /* Copy socket to the queue and increment head */ ctx->queue[ctx->sq_head % QUEUE_SIZE(ctx)] = *sp; ctx->sq_head++; DEBUG_TRACE("queued socket %d", sp ? sp->sock : -1); } (void)pthread_cond_signal(&ctx->sq_full); (void)pthread_mutex_unlock(&ctx->thread_mutex); #undef QUEUE_SIZE } #endif /* ALTERNATIVE_QUEUE */ struct worker_thread_args { struct mg_context *ctx; int index; }; static void * worker_thread_run(struct worker_thread_args *thread_args) { struct mg_context *ctx = thread_args->ctx; struct mg_connection *conn; struct mg_workerTLS tls; #if defined(MG_LEGACY_INTERFACE) uint32_t addr; #endif mg_set_thread_name("worker"); tls.is_master = 0; tls.thread_idx = (unsigned)mg_atomic_inc(&thread_idx_max); #if defined(_WIN32) tls.pthread_cond_helper_mutex = CreateEvent(NULL, FALSE, FALSE, NULL); #endif /* Initialize thread local storage before calling any callback */ pthread_setspecific(sTlsKey, &tls); if (ctx->callbacks.init_thread) { /* call init_thread for a worker thread (type 1) */ ctx->callbacks.init_thread(ctx, 1); } /* Connection structure has been pre-allocated */ if (((int)thread_args->index < 0) || ((unsigned)thread_args->index >= (unsigned)ctx->cfg_worker_threads)) { mg_cry_internal(fc(ctx), "Internal error: Invalid worker index %i", (int)thread_args->index); return NULL; } conn = ctx->worker_connections + thread_args->index; /* Request buffers are not pre-allocated. They are private to the * request and do not contain any state information that might be * of interest to anyone observing a server status. */ conn->buf = (char *)mg_malloc_ctx(ctx->max_request_size, conn->phys_ctx); if (conn->buf == NULL) { mg_cry_internal(fc(ctx), "Out of memory: Cannot allocate buffer for worker %i", (int)thread_args->index); return NULL; } conn->buf_size = (int)ctx->max_request_size; conn->phys_ctx = ctx; conn->dom_ctx = &(ctx->dd); /* Use default domain and default host */ conn->host = NULL; /* until we have more information. */ conn->thread_index = thread_args->index; conn->request_info.user_data = ctx->user_data; /* Allocate a mutex for this connection to allow communication both * within the request handler and from elsewhere in the application */ if (0 != pthread_mutex_init(&conn->mutex, &pthread_mutex_attr)) { mg_free(conn->buf); mg_cry_internal(fc(ctx), "%s", "Cannot create mutex"); return NULL; } #if defined(USE_SERVER_STATS) conn->conn_state = 1; /* not consumed */ #endif /* Call consume_socket() even when ctx->stop_flag > 0, to let it * signal sq_empty condvar to wake up the master waiting in * produce_socket() */ while (consume_socket(ctx, &conn->client, conn->thread_index)) { conn->conn_birth_time = time(NULL); /* Fill in IP, port info early so even if SSL setup below fails, * error handler would have the corresponding info. * Thanks to Johannes Winkelmann for the patch. */ #if defined(USE_IPV6) if (conn->client.rsa.sa.sa_family == AF_INET6) { conn->request_info.remote_port = ntohs(conn->client.rsa.sin6.sin6_port); } else #endif { conn->request_info.remote_port = ntohs(conn->client.rsa.sin.sin_port); } sockaddr_to_string(conn->request_info.remote_addr, sizeof(conn->request_info.remote_addr), &conn->client.rsa); DEBUG_TRACE("Start processing connection from %s", conn->request_info.remote_addr); conn->request_info.is_ssl = conn->client.is_ssl; if (conn->client.is_ssl) { #if !defined(NO_SSL) /* HTTPS connection */ if (sslize(conn, conn->dom_ctx->ssl_ctx, SSL_accept, &(conn->phys_ctx->stop_flag), NULL)) { /* conn->dom_ctx is set in get_request */ /* Get SSL client certificate information (if set) */ ssl_get_client_cert_info(conn); /* process HTTPS connection */ process_new_connection(conn); /* Free client certificate info */ if (conn->request_info.client_cert) { mg_free((void *)(conn->request_info.client_cert->subject)); mg_free((void *)(conn->request_info.client_cert->issuer)); mg_free((void *)(conn->request_info.client_cert->serial)); mg_free((void *)(conn->request_info.client_cert->finger)); /* Free certificate memory */ X509_free( (X509 *)conn->request_info.client_cert->peer_cert); conn->request_info.client_cert->peer_cert = 0; conn->request_info.client_cert->subject = 0; conn->request_info.client_cert->issuer = 0; conn->request_info.client_cert->serial = 0; conn->request_info.client_cert->finger = 0; mg_free(conn->request_info.client_cert); conn->request_info.client_cert = 0; } } else { /* make sure the connection is cleaned up on SSL failure */ close_connection(conn); } #endif } else { /* process HTTP connection */ process_new_connection(conn); } DEBUG_TRACE("%s", "Connection closed"); } pthread_setspecific(sTlsKey, NULL); #if defined(_WIN32) CloseHandle(tls.pthread_cond_helper_mutex); #endif pthread_mutex_destroy(&conn->mutex); /* Free the request buffer. */ conn->buf_size = 0; mg_free(conn->buf); conn->buf = NULL; #if defined(USE_SERVER_STATS) conn->conn_state = 9; /* done */ #endif DEBUG_TRACE("%s", "exiting"); return NULL; } /* Threads have different return types on Windows and Unix. */ #if defined(_WIN32) static unsigned __stdcall worker_thread(void *thread_func_param) { struct worker_thread_args *pwta = (struct worker_thread_args *)thread_func_param; worker_thread_run(pwta); mg_free(thread_func_param); return 0; } #else static void * worker_thread(void *thread_func_param) { struct worker_thread_args *pwta = (struct worker_thread_args *)thread_func_param; struct sigaction sa; /* Ignore SIGPIPE */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, NULL); worker_thread_run(pwta); mg_free(thread_func_param); return NULL; } #endif /* _WIN32 */ /* This is an internal function, thus all arguments are expected to be * valid - a NULL check is not required. */ static void accept_new_connection(const struct socket *listener, struct mg_context *ctx) { struct socket so; char src_addr[IP_ADDR_STR_LEN]; socklen_t len = sizeof(so.rsa); int on = 1; if ((so.sock = accept(listener->sock, &so.rsa.sa, &len)) == INVALID_SOCKET) { } else if (!check_acl(ctx, ntohl(*(uint32_t *)&so.rsa.sin.sin_addr))) { sockaddr_to_string(src_addr, sizeof(src_addr), &so.rsa); mg_cry_internal(fc(ctx), "%s: %s is not allowed to connect", __func__, src_addr); closesocket(so.sock); } else { /* Put so socket structure into the queue */ DEBUG_TRACE("Accepted socket %d", (int)so.sock); set_close_on_exec(so.sock, fc(ctx)); so.is_ssl = listener->is_ssl; so.ssl_redir = listener->ssl_redir; if (getsockname(so.sock, &so.lsa.sa, &len) != 0) { mg_cry_internal(fc(ctx), "%s: getsockname() failed: %s", __func__, strerror(ERRNO)); } /* Set TCP keep-alive. This is needed because if HTTP-level * keep-alive * is enabled, and client resets the connection, server won't get * TCP FIN or RST and will keep the connection open forever. With * TCP keep-alive, next keep-alive handshake will figure out that * the client is down and will close the server end. * Thanks to Igor Klopov who suggested the patch. */ if (setsockopt(so.sock, SOL_SOCKET, SO_KEEPALIVE, (SOCK_OPT_TYPE)&on, sizeof(on)) != 0) { mg_cry_internal( fc(ctx), "%s: setsockopt(SOL_SOCKET SO_KEEPALIVE) failed: %s", __func__, strerror(ERRNO)); } /* Disable TCP Nagle's algorithm. Normally TCP packets are coalesced * to effectively fill up the underlying IP packet payload and * reduce the overhead of sending lots of small buffers. However * this hurts the server's throughput (ie. operations per second) * when HTTP 1.1 persistent connections are used and the responses * are relatively small (eg. less than 1400 bytes). */ if ((ctx->dd.config[CONFIG_TCP_NODELAY] != NULL) && (!strcmp(ctx->dd.config[CONFIG_TCP_NODELAY], "1"))) { if (set_tcp_nodelay(so.sock, 1) != 0) { mg_cry_internal( fc(ctx), "%s: setsockopt(IPPROTO_TCP TCP_NODELAY) failed: %s", __func__, strerror(ERRNO)); } } /* We are using non-blocking sockets. Thus, the * set_sock_timeout(so.sock, timeout); * call is no longer required. */ /* The "non blocking" property should already be * inherited from the parent socket. Set it for * non-compliant socket implementations. */ set_non_blocking_mode(so.sock); so.in_use = 0; produce_socket(ctx, &so); } } static void master_thread_run(void *thread_func_param) { struct mg_context *ctx = (struct mg_context *)thread_func_param; struct mg_workerTLS tls; struct mg_pollfd *pfd; unsigned int i; unsigned int workerthreadcount; if (!ctx) { return; } mg_set_thread_name("master"); /* Increase priority of the master thread */ #if defined(_WIN32) SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); #elif defined(USE_MASTER_THREAD_PRIORITY) int min_prio = sched_get_priority_min(SCHED_RR); int max_prio = sched_get_priority_max(SCHED_RR); if ((min_prio >= 0) && (max_prio >= 0) && ((USE_MASTER_THREAD_PRIORITY) <= max_prio) && ((USE_MASTER_THREAD_PRIORITY) >= min_prio)) { struct sched_param sched_param = {0}; sched_param.sched_priority = (USE_MASTER_THREAD_PRIORITY); pthread_setschedparam(pthread_self(), SCHED_RR, &sched_param); } #endif /* Initialize thread local storage */ #if defined(_WIN32) tls.pthread_cond_helper_mutex = CreateEvent(NULL, FALSE, FALSE, NULL); #endif tls.is_master = 1; pthread_setspecific(sTlsKey, &tls); if (ctx->callbacks.init_thread) { /* Callback for the master thread (type 0) */ ctx->callbacks.init_thread(ctx, 0); } /* Server starts *now* */ ctx->start_time = time(NULL); /* Start the server */ pfd = ctx->listening_socket_fds; while (ctx->stop_flag == 0) { for (i = 0; i < ctx->num_listening_sockets; i++) { pfd[i].fd = ctx->listening_sockets[i].sock; pfd[i].events = POLLIN; } if (poll(pfd, ctx->num_listening_sockets, 200) > 0) { for (i = 0; i < ctx->num_listening_sockets; i++) { /* NOTE(lsm): on QNX, poll() returns POLLRDNORM after the * successful poll, and POLLIN is defined as * (POLLRDNORM | POLLRDBAND) * Therefore, we're checking pfd[i].revents & POLLIN, not * pfd[i].revents == POLLIN. */ if ((ctx->stop_flag == 0) && (pfd[i].revents & POLLIN)) { accept_new_connection(&ctx->listening_sockets[i], ctx); } } } } /* Here stop_flag is 1 - Initiate shutdown. */ DEBUG_TRACE("%s", "stopping workers"); /* Stop signal received: somebody called mg_stop. Quit. */ close_all_listening_sockets(ctx); /* Wakeup workers that are waiting for connections to handle. */ #if defined(ALTERNATIVE_QUEUE) for (i = 0; i < ctx->cfg_worker_threads; i++) { event_signal(ctx->client_wait_events[i]); } #else (void)pthread_mutex_lock(&ctx->thread_mutex); pthread_cond_broadcast(&ctx->sq_full); (void)pthread_mutex_unlock(&ctx->thread_mutex); #endif /* Join all worker threads to avoid leaking threads. */ workerthreadcount = ctx->cfg_worker_threads; for (i = 0; i < workerthreadcount; i++) { if (ctx->worker_threadids[i] != 0) { mg_join_thread(ctx->worker_threadids[i]); } } #if defined(USE_LUA) /* Free Lua state of lua background task */ if (ctx->lua_background_state) { lua_State *lstate = (lua_State *)ctx->lua_background_state; lua_getglobal(lstate, LUABACKGROUNDPARAMS); if (lua_istable(lstate, -1)) { reg_boolean(lstate, "shutdown", 1); lua_pop(lstate, 1); mg_sleep(2); } lua_close(lstate); ctx->lua_background_state = 0; } #endif DEBUG_TRACE("%s", "exiting"); #if defined(_WIN32) CloseHandle(tls.pthread_cond_helper_mutex); #endif pthread_setspecific(sTlsKey, NULL); /* Signal mg_stop() that we're done. * WARNING: This must be the very last thing this * thread does, as ctx becomes invalid after this line. */ ctx->stop_flag = 2; } /* Threads have different return types on Windows and Unix. */ #if defined(_WIN32) static unsigned __stdcall master_thread(void *thread_func_param) { master_thread_run(thread_func_param); return 0; } #else static void * master_thread(void *thread_func_param) { struct sigaction sa; /* Ignore SIGPIPE */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sa, NULL); master_thread_run(thread_func_param); return NULL; } #endif /* _WIN32 */ static void free_context(struct mg_context *ctx) { int i; struct mg_handler_info *tmp_rh; if (ctx == NULL) { return; } if (ctx->callbacks.exit_context) { ctx->callbacks.exit_context(ctx); } /* All threads exited, no sync is needed. Destroy thread mutex and * condvars */ (void)pthread_mutex_destroy(&ctx->thread_mutex); #if defined(ALTERNATIVE_QUEUE) mg_free(ctx->client_socks); for (i = 0; (unsigned)i < ctx->cfg_worker_threads; i++) { event_destroy(ctx->client_wait_events[i]); } mg_free(ctx->client_wait_events); #else (void)pthread_cond_destroy(&ctx->sq_empty); (void)pthread_cond_destroy(&ctx->sq_full); #endif /* Destroy other context global data structures mutex */ (void)pthread_mutex_destroy(&ctx->nonce_mutex); #if defined(USE_TIMERS) timers_exit(ctx); #endif /* Deallocate config parameters */ for (i = 0; i < NUM_OPTIONS; i++) { if (ctx->dd.config[i] != NULL) { #if defined(_MSC_VER) #pragma warning(suppress : 6001) #endif mg_free(ctx->dd.config[i]); } } /* Deallocate request handlers */ while (ctx->dd.handlers) { tmp_rh = ctx->dd.handlers; ctx->dd.handlers = tmp_rh->next; if (tmp_rh->handler_type == REQUEST_HANDLER) { pthread_cond_destroy(&tmp_rh->refcount_cond); pthread_mutex_destroy(&tmp_rh->refcount_mutex); } mg_free(tmp_rh->uri); mg_free(tmp_rh); } #if !defined(NO_SSL) /* Deallocate SSL context */ if (ctx->dd.ssl_ctx != NULL) { void *ssl_ctx = (void *)ctx->dd.ssl_ctx; int callback_ret = (ctx->callbacks.external_ssl_ctx == NULL) ? 0 : (ctx->callbacks.external_ssl_ctx(&ssl_ctx, ctx->user_data)); if (callback_ret == 0) { SSL_CTX_free(ctx->dd.ssl_ctx); } /* else: ignore error and ommit SSL_CTX_free in case * callback_ret is 1 */ } #endif /* !NO_SSL */ /* Deallocate worker thread ID array */ if (ctx->worker_threadids != NULL) { mg_free(ctx->worker_threadids); } /* Deallocate worker thread ID array */ if (ctx->worker_connections != NULL) { mg_free(ctx->worker_connections); } /* deallocate system name string */ mg_free(ctx->systemName); /* Deallocate context itself */ mg_free(ctx); } void mg_stop(struct mg_context *ctx) { pthread_t mt; if (!ctx) { return; } /* We don't use a lock here. Calling mg_stop with the same ctx from * two threads is not allowed. */ mt = ctx->masterthreadid; if (mt == 0) { return; } ctx->masterthreadid = 0; /* Set stop flag, so all threads know they have to exit. */ ctx->stop_flag = 1; /* Wait until everything has stopped. */ while (ctx->stop_flag != 2) { (void)mg_sleep(10); } mg_join_thread(mt); free_context(ctx); #if defined(_WIN32) (void)WSACleanup(); #endif /* _WIN32 */ } static void get_system_name(char **sysName) { #if defined(_WIN32) #if !defined(__SYMBIAN32__) #if defined(_WIN32_WCE) *sysName = mg_strdup("WinCE"); #else char name[128]; DWORD dwVersion = 0; DWORD dwMajorVersion = 0; DWORD dwMinorVersion = 0; DWORD dwBuild = 0; BOOL wowRet, isWoW = FALSE; #if defined(_MSC_VER) #pragma warning(push) /* GetVersion was declared deprecated */ #pragma warning(disable : 4996) #endif dwVersion = GetVersion(); #if defined(_MSC_VER) #pragma warning(pop) #endif dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); dwBuild = ((dwVersion < 0x80000000) ? (DWORD)(HIWORD(dwVersion)) : 0); (void)dwBuild; wowRet = IsWow64Process(GetCurrentProcess(), &isWoW); sprintf(name, "Windows %u.%u%s", (unsigned)dwMajorVersion, (unsigned)dwMinorVersion, (wowRet ? (isWoW ? " (WoW64)" : "") : " (?)")); *sysName = mg_strdup(name); #endif #else *sysName = mg_strdup("Symbian"); #endif #else struct utsname name; memset(&name, 0, sizeof(name)); uname(&name); *sysName = mg_strdup(name.sysname); #endif } struct mg_context * mg_start(const struct mg_callbacks *callbacks, void *user_data, const char **options) { struct mg_context *ctx; const char *name, *value, *default_value; int idx, ok, workerthreadcount; unsigned int i; int itmp; void (*exit_callback)(const struct mg_context *ctx) = 0; struct mg_workerTLS tls; #if defined(_WIN32) WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); #endif /* _WIN32 */ /* Allocate context and initialize reasonable general case defaults. */ if ((ctx = (struct mg_context *)mg_calloc(1, sizeof(*ctx))) == NULL) { return NULL; } /* Random number generator will initialize at the first call */ ctx->dd.auth_nonce_mask = (uint64_t)get_random() ^ (uint64_t)(ptrdiff_t)(options); if (mg_init_library_called == 0) { /* Legacy INIT, if mg_start is called without mg_init_library. * Note: This may cause a memory leak */ const char *ports_option = config_options[LISTENING_PORTS].default_value; if (options) { const char **run_options = options; const char *optname = config_options[LISTENING_PORTS].name; /* Try to find the "listening_ports" option */ while (*run_options) { if (!strcmp(*run_options, optname)) { ports_option = run_options[1]; } run_options += 2; } } if (is_ssl_port_used(ports_option)) { /* Initialize with SSL support */ mg_init_library(MG_FEATURES_TLS); } else { /* Initialize without SSL support */ mg_init_library(MG_FEATURES_DEFAULT); } } tls.is_master = -1; tls.thread_idx = (unsigned)mg_atomic_inc(&thread_idx_max); #if defined(_WIN32) tls.pthread_cond_helper_mutex = NULL; #endif pthread_setspecific(sTlsKey, &tls); ok = (0 == pthread_mutex_init(&ctx->thread_mutex, &pthread_mutex_attr)); #if !defined(ALTERNATIVE_QUEUE) ok &= (0 == pthread_cond_init(&ctx->sq_empty, NULL)); ok &= (0 == pthread_cond_init(&ctx->sq_full, NULL)); #endif ok &= (0 == pthread_mutex_init(&ctx->nonce_mutex, &pthread_mutex_attr)); if (!ok) { /* Fatal error - abort start. However, this situation should never * occur in practice. */ mg_cry_internal(fc(ctx), "%s", "Cannot initialize thread synchronization objects"); mg_free(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } if (callbacks) { ctx->callbacks = *callbacks; exit_callback = callbacks->exit_context; ctx->callbacks.exit_context = 0; } ctx->user_data = user_data; ctx->dd.handlers = NULL; ctx->dd.next = NULL; #if defined(USE_LUA) && defined(USE_WEBSOCKET) ctx->dd.shared_lua_websockets = NULL; #endif /* Store options */ while (options && (name = *options++) != NULL) { if ((idx = get_option_index(name)) == -1) { mg_cry_internal(fc(ctx), "Invalid option: %s", name); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } else if ((value = *options++) == NULL) { mg_cry_internal(fc(ctx), "%s: option value cannot be NULL", name); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } if (ctx->dd.config[idx] != NULL) { mg_cry_internal(fc(ctx), "warning: %s: duplicate option", name); mg_free(ctx->dd.config[idx]); } ctx->dd.config[idx] = mg_strdup_ctx(value, ctx); DEBUG_TRACE("[%s] -> [%s]", name, value); } /* Set default value if needed */ for (i = 0; config_options[i].name != NULL; i++) { default_value = config_options[i].default_value; if ((ctx->dd.config[i] == NULL) && (default_value != NULL)) { ctx->dd.config[i] = mg_strdup_ctx(default_value, ctx); } } /* Request size option */ itmp = atoi(ctx->dd.config[MAX_REQUEST_SIZE]); if (itmp < 1024) { mg_cry_internal(fc(ctx), "%s", "max_request_size too small"); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } ctx->max_request_size = (unsigned)itmp; /* Worker thread count option */ workerthreadcount = atoi(ctx->dd.config[NUM_THREADS]); if (workerthreadcount > MAX_WORKER_THREADS) { mg_cry_internal(fc(ctx), "%s", "Too many worker threads"); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } if (workerthreadcount <= 0) { mg_cry_internal(fc(ctx), "%s", "Invalid number of worker threads"); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } /* Document root */ #if defined(NO_FILES) if (ctx->dd.config[DOCUMENT_ROOT] != NULL) { mg_cry_internal(fc(ctx), "%s", "Document root must not be set"); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } #endif get_system_name(&ctx->systemName); #if defined(USE_LUA) /* If a Lua background script has been configured, start it. */ if (ctx->dd.config[LUA_BACKGROUND_SCRIPT] != NULL) { char ebuf[256]; struct vec opt_vec; struct vec eq_vec; const char *sparams; lua_State *state = mg_prepare_lua_context_script( ctx->dd.config[LUA_BACKGROUND_SCRIPT], ctx, ebuf, sizeof(ebuf)); if (!state) { mg_cry_internal(fc(ctx), "lua_background_script error: %s", ebuf); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } ctx->lua_background_state = (void *)state; lua_newtable(state); reg_boolean(state, "shutdown", 0); sparams = ctx->dd.config[LUA_BACKGROUND_SCRIPT_PARAMS]; while ((sparams = next_option(sparams, &opt_vec, &eq_vec)) != NULL) { reg_llstring( state, opt_vec.ptr, opt_vec.len, eq_vec.ptr, eq_vec.len); if (mg_strncasecmp(sparams, opt_vec.ptr, opt_vec.len) == 0) break; } lua_setglobal(state, LUABACKGROUNDPARAMS); } else { ctx->lua_background_state = 0; } #endif /* NOTE(lsm): order is important here. SSL certificates must * be initialized before listening ports. UID must be set last. */ if (!set_gpass_option(ctx, NULL) || #if !defined(NO_SSL) !init_ssl_ctx(ctx, NULL) || #endif !set_ports_option(ctx) || #if !defined(_WIN32) !set_uid_option(ctx) || #endif !set_acl_option(ctx)) { free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } ctx->cfg_worker_threads = ((unsigned int)(workerthreadcount)); ctx->worker_threadids = (pthread_t *)mg_calloc_ctx(ctx->cfg_worker_threads, sizeof(pthread_t), ctx); if (ctx->worker_threadids == NULL) { mg_cry_internal(fc(ctx), "%s", "Not enough memory for worker thread ID array"); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } ctx->worker_connections = (struct mg_connection *)mg_calloc_ctx(ctx->cfg_worker_threads, sizeof(struct mg_connection), ctx); if (ctx->worker_connections == NULL) { mg_cry_internal(fc(ctx), "%s", "Not enough memory for worker thread connection array"); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } #if defined(ALTERNATIVE_QUEUE) ctx->client_wait_events = (void **)mg_calloc_ctx(sizeof(ctx->client_wait_events[0]), ctx->cfg_worker_threads, ctx); if (ctx->client_wait_events == NULL) { mg_cry_internal(fc(ctx), "%s", "Not enough memory for worker event array"); mg_free(ctx->worker_threadids); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } ctx->client_socks = (struct socket *)mg_calloc_ctx(sizeof(ctx->client_socks[0]), ctx->cfg_worker_threads, ctx); if (ctx->client_socks == NULL) { mg_cry_internal(fc(ctx), "%s", "Not enough memory for worker socket array"); mg_free(ctx->client_wait_events); mg_free(ctx->worker_threadids); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } for (i = 0; (unsigned)i < ctx->cfg_worker_threads; i++) { ctx->client_wait_events[i] = event_create(); if (ctx->client_wait_events[i] == 0) { mg_cry_internal(fc(ctx), "Error creating worker event %i", i); while (i > 0) { i--; event_destroy(ctx->client_wait_events[i]); } mg_free(ctx->client_socks); mg_free(ctx->client_wait_events); mg_free(ctx->worker_threadids); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } } #endif #if defined(USE_TIMERS) if (timers_init(ctx) != 0) { mg_cry_internal(fc(ctx), "%s", "Error creating timers"); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } #endif /* Context has been created - init user libraries */ if (ctx->callbacks.init_context) { ctx->callbacks.init_context(ctx); } ctx->callbacks.exit_context = exit_callback; ctx->context_type = CONTEXT_SERVER; /* server context */ /* Start master (listening) thread */ mg_start_thread_with_id(master_thread, ctx, &ctx->masterthreadid); /* Start worker threads */ for (i = 0; i < ctx->cfg_worker_threads; i++) { struct worker_thread_args *wta = (struct worker_thread_args *) mg_malloc_ctx(sizeof(struct worker_thread_args), ctx); if (wta) { wta->ctx = ctx; wta->index = (int)i; } if ((wta == NULL) || (mg_start_thread_with_id(worker_thread, wta, &ctx->worker_threadids[i]) != 0)) { /* thread was not created */ if (wta != NULL) { mg_free(wta); } if (i > 0) { mg_cry_internal(fc(ctx), "Cannot start worker thread %i: error %ld", i + 1, (long)ERRNO); } else { mg_cry_internal(fc(ctx), "Cannot create threads: error %ld", (long)ERRNO); free_context(ctx); pthread_setspecific(sTlsKey, NULL); return NULL; } break; } } pthread_setspecific(sTlsKey, NULL); return ctx; } #if defined(MG_EXPERIMENTAL_INTERFACES) /* Add an additional domain to an already running web server. */ int mg_start_domain(struct mg_context *ctx, const char **options) { const char *name; const char *value; const char *default_value; struct mg_domain_context *new_dom; struct mg_domain_context *dom; int idx, i; if ((ctx == NULL) || (ctx->stop_flag != 0) || (options == NULL)) { return -1; } new_dom = (struct mg_domain_context *) mg_calloc_ctx(1, sizeof(struct mg_domain_context), ctx); if (!new_dom) { /* Out of memory */ return -6; } /* Store options - TODO: unite duplicate code */ while (options && (name = *options++) != NULL) { if ((idx = get_option_index(name)) == -1) { mg_cry_internal(fc(ctx), "Invalid option: %s", name); mg_free(new_dom); return -2; } else if ((value = *options++) == NULL) { mg_cry_internal(fc(ctx), "%s: option value cannot be NULL", name); mg_free(new_dom); return -2; } if (new_dom->config[idx] != NULL) { mg_cry_internal(fc(ctx), "warning: %s: duplicate option", name); mg_free(new_dom->config[idx]); } new_dom->config[idx] = mg_strdup_ctx(value, ctx); DEBUG_TRACE("[%s] -> [%s]", name, value); } /* Authentication domain is mandatory */ /* TODO: Maybe use a new option hostname? */ if (!new_dom->config[AUTHENTICATION_DOMAIN]) { mg_cry_internal(fc(ctx), "%s", "authentication domain required"); mg_free(new_dom); return -4; } /* Set default value if needed. Take the config value from * ctx as a default value. */ for (i = 0; config_options[i].name != NULL; i++) { default_value = ctx->dd.config[i]; if ((new_dom->config[i] == NULL) && (default_value != NULL)) { new_dom->config[i] = mg_strdup_ctx(default_value, ctx); } } new_dom->handlers = NULL; new_dom->next = NULL; new_dom->nonce_count = 0; new_dom->auth_nonce_mask = (uint64_t)get_random() ^ ((uint64_t)get_random() << 31); #if defined(USE_LUA) && defined(USE_WEBSOCKET) new_dom->shared_lua_websockets = NULL; #endif if (!init_ssl_ctx(ctx, new_dom)) { /* Init SSL failed */ mg_free(new_dom); return -3; } /* Add element to linked list. */ mg_lock_context(ctx); idx = 0; dom = &(ctx->dd); for (;;) { if (!strcasecmp(new_dom->config[AUTHENTICATION_DOMAIN], dom->config[AUTHENTICATION_DOMAIN])) { /* Domain collision */ mg_cry_internal(fc(ctx), "domain %s already in use", new_dom->config[AUTHENTICATION_DOMAIN]); mg_free(new_dom); return -5; } /* Count number of domains */ idx++; if (dom->next == NULL) { dom->next = new_dom; break; } dom = dom->next; } mg_unlock_context(ctx); /* Return domain number */ return idx; } #endif /* Feature check API function */ unsigned mg_check_feature(unsigned feature) { static const unsigned feature_set = 0 /* Set bits for available features according to API documentation. * This bit mask is created at compile time, according to the active * preprocessor defines. It is a single const value at runtime. */ #if !defined(NO_FILES) | MG_FEATURES_FILES #endif #if !defined(NO_SSL) | MG_FEATURES_SSL #endif #if !defined(NO_CGI) | MG_FEATURES_CGI #endif #if defined(USE_IPV6) | MG_FEATURES_IPV6 #endif #if defined(USE_WEBSOCKET) | MG_FEATURES_WEBSOCKET #endif #if defined(USE_LUA) | MG_FEATURES_LUA #endif #if defined(USE_DUKTAPE) | MG_FEATURES_SSJS #endif #if !defined(NO_CACHING) | MG_FEATURES_CACHE #endif #if defined(USE_SERVER_STATS) | MG_FEATURES_STATS #endif #if defined(USE_ZLIB) | MG_FEATURES_COMPRESSION #endif /* Set some extra bits not defined in the API documentation. * These bits may change without further notice. */ #if defined(MG_LEGACY_INTERFACE) | 0x00008000u #endif #if defined(MG_EXPERIMENTAL_INTERFACES) | 0x00004000u #endif #if defined(MEMORY_DEBUGGING) | 0x00001000u #endif #if defined(USE_TIMERS) | 0x00020000u #endif #if !defined(NO_NONCE_CHECK) | 0x00040000u #endif #if !defined(NO_POPEN) | 0x00080000u #endif ; return (feature & feature_set); } /* strcat with additional NULL check to avoid clang scan-build warning. */ #define strcat0(a, b) \ { \ if ((a != NULL) && (b != NULL)) { \ strcat(a, b); \ } \ } /* Get system information. It can be printed or stored by the caller. * Return the size of available information. */ static int mg_get_system_info_impl(char *buffer, int buflen) { char block[256]; int system_info_length = 0; #if defined(_WIN32) const char *eol = "\r\n"; #else const char *eol = "\n"; #endif const char *eoobj = "}"; int reserved_len = (int)strlen(eoobj) + (int)strlen(eol); if ((buffer == NULL) || (buflen < 1)) { buflen = 0; } else { *buffer = 0; } mg_snprintf(NULL, NULL, block, sizeof(block), "{%s", eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } /* Server version */ { const char *version = mg_version(); mg_snprintf(NULL, NULL, block, sizeof(block), "\"version\" : \"%s\",%s", version, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } } /* System info */ { #if defined(_WIN32) DWORD dwVersion = 0; DWORD dwMajorVersion = 0; DWORD dwMinorVersion = 0; SYSTEM_INFO si; GetSystemInfo(&si); #if defined(_MSC_VER) #pragma warning(push) /* GetVersion was declared deprecated */ #pragma warning(disable : 4996) #endif dwVersion = GetVersion(); #if defined(_MSC_VER) #pragma warning(pop) #endif dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); mg_snprintf(NULL, NULL, block, sizeof(block), "\"os\" : \"Windows %u.%u\",%s", (unsigned)dwMajorVersion, (unsigned)dwMinorVersion, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } mg_snprintf(NULL, NULL, block, sizeof(block), "\"cpu\" : \"type %u, cores %u, mask %x\",%s", (unsigned)si.wProcessorArchitecture, (unsigned)si.dwNumberOfProcessors, (unsigned)si.dwActiveProcessorMask, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #else struct utsname name; memset(&name, 0, sizeof(name)); uname(&name); mg_snprintf(NULL, NULL, block, sizeof(block), "\"os\" : \"%s %s (%s) - %s\",%s", name.sysname, name.version, name.release, name.machine, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #endif } /* Features */ { mg_snprintf(NULL, NULL, block, sizeof(block), "\"features\" : %lu,%s" "\"feature_list\" : \"Server:%s%s%s%s%s%s%s%s%s\",%s", (unsigned long)mg_check_feature(0xFFFFFFFFu), eol, mg_check_feature(MG_FEATURES_FILES) ? " Files" : "", mg_check_feature(MG_FEATURES_SSL) ? " HTTPS" : "", mg_check_feature(MG_FEATURES_CGI) ? " CGI" : "", mg_check_feature(MG_FEATURES_IPV6) ? " IPv6" : "", mg_check_feature(MG_FEATURES_WEBSOCKET) ? " WebSockets" : "", mg_check_feature(MG_FEATURES_LUA) ? " Lua" : "", mg_check_feature(MG_FEATURES_SSJS) ? " JavaScript" : "", mg_check_feature(MG_FEATURES_CACHE) ? " Cache" : "", mg_check_feature(MG_FEATURES_STATS) ? " Stats" : "", eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #if defined(USE_LUA) mg_snprintf(NULL, NULL, block, sizeof(block), "\"lua_version\" : \"%u (%s)\",%s", (unsigned)LUA_VERSION_NUM, LUA_RELEASE, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #endif #if defined(USE_DUKTAPE) mg_snprintf(NULL, NULL, block, sizeof(block), "\"javascript\" : \"Duktape %u.%u.%u\",%s", (unsigned)DUK_VERSION / 10000, ((unsigned)DUK_VERSION / 100) % 100, (unsigned)DUK_VERSION % 100, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #endif } /* Build date */ { #if defined(GCC_DIAGNOSTIC) #if GCC_VERSION >= 40900 #pragma GCC diagnostic push /* Disable bogus compiler warning -Wdate-time, appeared in gcc5 */ #pragma GCC diagnostic ignored "-Wdate-time" #endif #endif mg_snprintf(NULL, NULL, block, sizeof(block), "\"build\" : \"%s\",%s", __DATE__, eol); #if defined(GCC_DIAGNOSTIC) #if GCC_VERSION >= 40900 #pragma GCC diagnostic pop #endif #endif system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } } /* Compiler information */ /* http://sourceforge.net/p/predef/wiki/Compilers/ */ { #if defined(_MSC_VER) mg_snprintf(NULL, NULL, block, sizeof(block), "\"compiler\" : \"MSC: %u (%u)\",%s", (unsigned)_MSC_VER, (unsigned)_MSC_FULL_VER, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #elif defined(__MINGW64__) mg_snprintf(NULL, NULL, block, sizeof(block), "\"compiler\" : \"MinGW64: %u.%u\",%s", (unsigned)__MINGW64_VERSION_MAJOR, (unsigned)__MINGW64_VERSION_MINOR, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } mg_snprintf(NULL, NULL, block, sizeof(block), "\"compiler\" : \"MinGW32: %u.%u\",%s", (unsigned)__MINGW32_MAJOR_VERSION, (unsigned)__MINGW32_MINOR_VERSION, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #elif defined(__MINGW32__) mg_snprintf(NULL, NULL, block, sizeof(block), "\"compiler\" : \"MinGW32: %u.%u\",%s", (unsigned)__MINGW32_MAJOR_VERSION, (unsigned)__MINGW32_MINOR_VERSION, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #elif defined(__clang__) mg_snprintf(NULL, NULL, block, sizeof(block), "\"compiler\" : \"clang: %u.%u.%u (%s)\",%s", __clang_major__, __clang_minor__, __clang_patchlevel__, __clang_version__, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #elif defined(__GNUC__) mg_snprintf(NULL, NULL, block, sizeof(block), "\"compiler\" : \"gcc: %u.%u.%u\",%s", (unsigned)__GNUC__, (unsigned)__GNUC_MINOR__, (unsigned)__GNUC_PATCHLEVEL__, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #elif defined(__INTEL_COMPILER) mg_snprintf(NULL, NULL, block, sizeof(block), "\"compiler\" : \"Intel C/C++: %u\",%s", (unsigned)__INTEL_COMPILER, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #elif defined(__BORLANDC__) mg_snprintf(NULL, NULL, block, sizeof(block), "\"compiler\" : \"Borland C: 0x%x\",%s", (unsigned)__BORLANDC__, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #elif defined(__SUNPRO_C) mg_snprintf(NULL, NULL, block, sizeof(block), "\"compiler\" : \"Solaris: 0x%x\",%s", (unsigned)__SUNPRO_C, eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #else mg_snprintf(NULL, NULL, block, sizeof(block), "\"compiler\" : \"other\",%s", eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } #endif } /* Determine 32/64 bit data mode. * see https://en.wikipedia.org/wiki/64-bit_computing */ { mg_snprintf(NULL, NULL, block, sizeof(block), "\"data_model\" : \"int:%u/%u/%u/%u, float:%u/%u/%u, " "char:%u/%u, " "ptr:%u, size:%u, time:%u\"%s", (unsigned)sizeof(short), (unsigned)sizeof(int), (unsigned)sizeof(long), (unsigned)sizeof(long long), (unsigned)sizeof(float), (unsigned)sizeof(double), (unsigned)sizeof(long double), (unsigned)sizeof(char), (unsigned)sizeof(wchar_t), (unsigned)sizeof(void *), (unsigned)sizeof(size_t), (unsigned)sizeof(time_t), eol); system_info_length += (int)strlen(block); if (system_info_length < buflen) { strcat0(buffer, block); } } /* Terminate string */ if ((buflen > 0) && buffer && buffer[0]) { if (system_info_length < buflen) { strcat0(buffer, eoobj); strcat0(buffer, eol); } } system_info_length += reserved_len; return system_info_length; } #if defined(USE_SERVER_STATS) /* Get context information. It can be printed or stored by the caller. * Return the size of available information. */ static int mg_get_context_info_impl(const struct mg_context *ctx, char *buffer, int buflen) { char block[256]; int context_info_length = 0; #if defined(_WIN32) const char *eol = "\r\n"; #else const char *eol = "\n"; #endif struct mg_memory_stat *ms = get_memory_stat((struct mg_context *)ctx); const char *eoobj = "}"; int reserved_len = (int)strlen(eoobj) + (int)strlen(eol); if ((buffer == NULL) || (buflen < 1)) { buflen = 0; } else { *buffer = 0; } mg_snprintf(NULL, NULL, block, sizeof(block), "{%s", eol); context_info_length += (int)strlen(block); if (context_info_length < buflen) { strcat0(buffer, block); } if (ms) { /* <-- should be always true */ /* Memory information */ mg_snprintf(NULL, NULL, block, sizeof(block), "\"memory\" : {%s" "\"blocks\" : %i,%s" "\"used\" : %" INT64_FMT ",%s" "\"maxUsed\" : %" INT64_FMT "%s" "}%s%s", eol, ms->blockCount, eol, ms->totalMemUsed, eol, ms->maxMemUsed, eol, (ctx ? "," : ""), eol); context_info_length += (int)strlen(block); if (context_info_length + reserved_len < buflen) { strcat0(buffer, block); } } if (ctx) { /* Declare all variables at begin of the block, to comply * with old C standards. */ char start_time_str[64] = {0}; char now_str[64] = {0}; time_t start_time = ctx->start_time; time_t now = time(NULL); /* Connections information */ mg_snprintf(NULL, NULL, block, sizeof(block), "\"connections\" : {%s" "\"active\" : %i,%s" "\"maxActive\" : %i,%s" "\"total\" : %" INT64_FMT "%s" "},%s", eol, ctx->active_connections, eol, ctx->max_connections, eol, ctx->total_connections, eol, eol); context_info_length += (int)strlen(block); if (context_info_length + reserved_len < buflen) { strcat0(buffer, block); } /* Requests information */ mg_snprintf(NULL, NULL, block, sizeof(block), "\"requests\" : {%s" "\"total\" : %" INT64_FMT "%s" "},%s", eol, ctx->total_requests, eol, eol); context_info_length += (int)strlen(block); if (context_info_length + reserved_len < buflen) { strcat0(buffer, block); } /* Data information */ mg_snprintf(NULL, NULL, block, sizeof(block), "\"data\" : {%s" "\"read\" : %" INT64_FMT "%s," "\"written\" : %" INT64_FMT "%s" "},%s", eol, ctx->total_data_read, eol, ctx->total_data_written, eol, eol); context_info_length += (int)strlen(block); if (context_info_length + reserved_len < buflen) { strcat0(buffer, block); } /* Execution time information */ gmt_time_string(start_time_str, sizeof(start_time_str) - 1, &start_time); gmt_time_string(now_str, sizeof(now_str) - 1, &now); mg_snprintf(NULL, NULL, block, sizeof(block), "\"time\" : {%s" "\"uptime\" : %.0f,%s" "\"start\" : \"%s\",%s" "\"now\" : \"%s\"%s" "}%s", eol, difftime(now, start_time), eol, start_time_str, eol, now_str, eol, eol); context_info_length += (int)strlen(block); if (context_info_length + reserved_len < buflen) { strcat0(buffer, block); } } /* Terminate string */ if ((buflen > 0) && buffer && buffer[0]) { if (context_info_length < buflen) { strcat0(buffer, eoobj); strcat0(buffer, eol); } } context_info_length += reserved_len; return context_info_length; } #endif #if defined(MG_EXPERIMENTAL_INTERFACES) /* Get connection information. It can be printed or stored by the caller. * Return the size of available information. */ static int mg_get_connection_info_impl(const struct mg_context *ctx, int idx, char *buffer, int buflen) { const struct mg_connection *conn; const struct mg_request_info *ri; char block[256]; int connection_info_length = 0; int state = 0; const char *state_str = "unknown"; #if defined(_WIN32) const char *eol = "\r\n"; #else const char *eol = "\n"; #endif const char *eoobj = "}"; int reserved_len = (int)strlen(eoobj) + (int)strlen(eol); if ((buffer == NULL) || (buflen < 1)) { buflen = 0; } else { *buffer = 0; } if ((ctx == NULL) || (idx < 0)) { /* Parameter error */ return 0; } if ((unsigned)idx >= ctx->cfg_worker_threads) { /* Out of range */ return 0; } /* Take connection [idx]. This connection is not locked in * any way, so some other thread might use it. */ conn = (ctx->worker_connections) + idx; /* Initialize output string */ mg_snprintf(NULL, NULL, block, sizeof(block), "{%s", eol); connection_info_length += (int)strlen(block); if (connection_info_length < buflen) { strcat0(buffer, block); } /* Init variables */ ri = &(conn->request_info); #if defined(USE_SERVER_STATS) state = conn->conn_state; /* State as string */ switch (state) { case 0: state_str = "undefined"; break; case 1: state_str = "not used"; break; case 2: state_str = "init"; break; case 3: state_str = "ready"; break; case 4: state_str = "processing"; break; case 5: state_str = "processed"; break; case 6: state_str = "to close"; break; case 7: state_str = "closing"; break; case 8: state_str = "closed"; break; case 9: state_str = "done"; break; } #endif /* Connection info */ if ((state >= 3) && (state < 9)) { mg_snprintf(NULL, NULL, block, sizeof(block), "\"connection\" : {%s" "\"remote\" : {%s" "\"protocol\" : \"%s\",%s" "\"addr\" : \"%s\",%s" "\"port\" : %u%s" "},%s" "\"handled_requests\" : %u%s" "},%s", eol, eol, get_proto_name(conn), eol, ri->remote_addr, eol, ri->remote_port, eol, eol, conn->handled_requests, eol, eol); connection_info_length += (int)strlen(block); if (connection_info_length + reserved_len < buflen) { strcat0(buffer, block); } } /* Request info */ if ((state >= 4) && (state < 6)) { mg_snprintf(NULL, NULL, block, sizeof(block), "\"request_info\" : {%s" "\"method\" : \"%s\",%s" "\"uri\" : \"%s\",%s" "\"query\" : %s%s%s%s" "},%s", eol, ri->request_method, eol, ri->request_uri, eol, ri->query_string ? "\"" : "", ri->query_string ? ri->query_string : "null", ri->query_string ? "\"" : "", eol, eol); connection_info_length += (int)strlen(block); if (connection_info_length + reserved_len < buflen) { strcat0(buffer, block); } } /* Execution time information */ if ((state >= 2) && (state < 9)) { char start_time_str[64] = {0}; char now_str[64] = {0}; time_t start_time = conn->conn_birth_time; time_t now = time(NULL); gmt_time_string(start_time_str, sizeof(start_time_str) - 1, &start_time); gmt_time_string(now_str, sizeof(now_str) - 1, &now); mg_snprintf(NULL, NULL, block, sizeof(block), "\"time\" : {%s" "\"uptime\" : %.0f,%s" "\"start\" : \"%s\",%s" "\"now\" : \"%s\"%s" "},%s", eol, difftime(now, start_time), eol, start_time_str, eol, now_str, eol, eol); connection_info_length += (int)strlen(block); if (connection_info_length + reserved_len < buflen) { strcat0(buffer, block); } } /* Remote user name */ if ((ri->remote_user) && (state < 9)) { mg_snprintf(NULL, NULL, block, sizeof(block), "\"user\" : {%s" "\"name\" : \"%s\",%s" "},%s", eol, ri->remote_user, eol, eol); connection_info_length += (int)strlen(block); if (connection_info_length + reserved_len < buflen) { strcat0(buffer, block); } } /* Data block */ if (state >= 3) { mg_snprintf(NULL, NULL, block, sizeof(block), "\"data\" : {%s" "\"read\" : %" INT64_FMT ",%s" "\"written\" : %" INT64_FMT "%s" "},%s", eol, conn->consumed_content, eol, conn->num_bytes_sent, eol, eol); connection_info_length += (int)strlen(block); if (connection_info_length + reserved_len < buflen) { strcat0(buffer, block); } } /* State */ mg_snprintf(NULL, NULL, block, sizeof(block), "\"state\" : \"%s\"%s", state_str, eol); connection_info_length += (int)strlen(block); if (connection_info_length + reserved_len < buflen) { strcat0(buffer, block); } /* Terminate string */ if ((buflen > 0) && buffer && buffer[0]) { if (connection_info_length < buflen) { strcat0(buffer, eoobj); strcat0(buffer, eol); } } connection_info_length += reserved_len; return connection_info_length; } #endif /* Get system information. It can be printed or stored by the caller. * Return the size of available information. */ int mg_get_system_info(char *buffer, int buflen) { if ((buffer == NULL) || (buflen < 1)) { return mg_get_system_info_impl(NULL, 0); } else { /* Reset buffer, so we can always use strcat. */ buffer[0] = 0; return mg_get_system_info_impl(buffer, buflen); } } /* Get context information. It can be printed or stored by the caller. * Return the size of available information. */ int mg_get_context_info(const struct mg_context *ctx, char *buffer, int buflen) { #if defined(USE_SERVER_STATS) if ((buffer == NULL) || (buflen < 1)) { return mg_get_context_info_impl(ctx, NULL, 0); } else { /* Reset buffer, so we can always use strcat. */ buffer[0] = 0; return mg_get_context_info_impl(ctx, buffer, buflen); } #else (void)ctx; if ((buffer != NULL) && (buflen > 0)) { buffer[0] = 0; } return 0; #endif } #if defined(MG_EXPERIMENTAL_INTERFACES) int mg_get_connection_info(const struct mg_context *ctx, int idx, char *buffer, int buflen) { if ((buffer == NULL) || (buflen < 1)) { return mg_get_connection_info_impl(ctx, idx, NULL, 0); } else { /* Reset buffer, so we can always use strcat. */ buffer[0] = 0; return mg_get_connection_info_impl(ctx, idx, buffer, buflen); } } #endif /* Initialize this library. This function does not need to be thread safe. */ unsigned mg_init_library(unsigned features) { #if !defined(NO_SSL) char ebuf[128]; #endif unsigned features_to_init = mg_check_feature(features & 0xFFu); unsigned features_inited = features_to_init; if (mg_init_library_called <= 0) { /* Not initialized yet */ if (0 != pthread_mutex_init(&global_lock_mutex, NULL)) { return 0; } } mg_global_lock(); if (mg_init_library_called <= 0) { if (0 != pthread_key_create(&sTlsKey, tls_dtor)) { /* Fatal error - abort start. However, this situation should * never occur in practice. */ mg_global_unlock(); return 0; } #if defined(_WIN32) InitializeCriticalSection(&global_log_file_lock); #endif #if !defined(_WIN32) pthread_mutexattr_init(&pthread_mutex_attr); pthread_mutexattr_settype(&pthread_mutex_attr, PTHREAD_MUTEX_RECURSIVE); #endif #if defined(USE_LUA) lua_init_optional_libraries(); #endif } mg_global_unlock(); #if !defined(NO_SSL) if (features_to_init & MG_FEATURES_SSL) { if (!mg_ssl_initialized) { if (initialize_ssl(ebuf, sizeof(ebuf))) { mg_ssl_initialized = 1; } else { (void)ebuf; DEBUG_TRACE("Initializing SSL failed: %s", ebuf); features_inited &= ~((unsigned)(MG_FEATURES_SSL)); } } else { /* ssl already initialized */ } } #endif /* Start WinSock for Windows */ mg_global_lock(); if (mg_init_library_called <= 0) { #if defined(_WIN32) WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); #endif /* _WIN32 */ mg_init_library_called = 1; } else { mg_init_library_called++; } mg_global_unlock(); return features_inited; } /* Un-initialize this library. */ unsigned mg_exit_library(void) { if (mg_init_library_called <= 0) { return 0; } mg_global_lock(); mg_init_library_called--; if (mg_init_library_called == 0) { #if defined(_WIN32) (void)WSACleanup(); #endif /* _WIN32 */ #if !defined(NO_SSL) if (mg_ssl_initialized) { uninitialize_ssl(); mg_ssl_initialized = 0; } #endif #if defined(_WIN32) (void)DeleteCriticalSection(&global_log_file_lock); #endif /* _WIN32 */ #if !defined(_WIN32) (void)pthread_mutexattr_destroy(&pthread_mutex_attr); #endif (void)pthread_key_delete(sTlsKey); #if defined(USE_LUA) lua_exit_optional_libraries(); #endif mg_global_unlock(); (void)pthread_mutex_destroy(&global_lock_mutex); return 1; } mg_global_unlock(); return 1; } /* End of civetweb.c */
73769.c
// SPDX-License-Identifier: GPL-2.0 /* * Memory preserving reboot related code. * * Created by: Hariprasad Nellitheertha ([email protected]) * Copyright (C) IBM Corporation, 2004. All rights reserved */ #include <linux/errno.h> #include <linux/crash_dump.h> #include <linux/uaccess.h> #include <linux/io.h> static ssize_t __copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, unsigned long offset, int userbuf, bool encrypted) { void *vaddr; if (!csize) return 0; if (encrypted) vaddr = (__force void *)ioremap_encrypted(pfn << PAGE_SHIFT, PAGE_SIZE); else vaddr = (__force void *)ioremap_cache(pfn << PAGE_SHIFT, PAGE_SIZE); if (!vaddr) return -ENOMEM; if (userbuf) { if (copy_to_user((void __user *)buf, vaddr + offset, csize)) { iounmap((void __iomem *)vaddr); return -EFAULT; } } else memcpy(buf, vaddr + offset, csize); set_iounmap_nonlazy(); iounmap((void __iomem *)vaddr); return csize; } /** * copy_oldmem_page - copy one page of memory * @pfn: page frame number to be copied * @buf: target memory address for the copy; this can be in kernel address * space or user address space (see @userbuf) * @csize: number of bytes to copy * @offset: offset in bytes into the page (based on pfn) to begin the copy * @userbuf: if set, @buf is in user address space, use copy_to_user(), * otherwise @buf is in kernel address space, use memcpy(). * * Copy a page from the old kernel's memory. For this page, there is no pte * mapped in the current kernel. We stitch up a pte, similar to kmap_atomic. */ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, unsigned long offset, int userbuf) { return __copy_oldmem_page(pfn, buf, csize, offset, userbuf, false); } /** * copy_oldmem_page_encrypted - same as copy_oldmem_page() above but ioremap the * memory with the encryption mask set to accommodate kdump on SME-enabled * machines. */ ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char *buf, size_t csize, unsigned long offset, int userbuf) { return __copy_oldmem_page(pfn, buf, csize, offset, userbuf, true); } ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos) { return read_from_oldmem(buf, count, ppos, 0, sev_active()); }
891361.c
/* * Copyright (C) 2005 Jan Hutter, Martin Willi * Copyright (C) 2009 Andreas Steffen * * HSR Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ #include "x509_pkcs10.h" #include <library.h> #include <utils/debug.h> #include <asn1/oid.h> #include <asn1/asn1.h> #include <asn1/asn1_parser.h> #include <credentials/keys/private_key.h> #include <collections/linked_list.h> #include <utils/identification.h> typedef struct private_x509_pkcs10_t private_x509_pkcs10_t; /** * Private data of a x509_pkcs10_t object. */ struct private_x509_pkcs10_t { /** * Public interface for this certificate. */ x509_pkcs10_t public; /** * PKCS#10 certificate request encoding in ASN.1 DER format */ chunk_t encoding; /** * PKCS#10 request body over which signature is computed */ chunk_t certificationRequestInfo; /** * Version of the PKCS#10 certificate request */ u_int version; /** * ID representing the certificate subject */ identification_t *subject; /** * List of subjectAltNames as identification_t */ linked_list_t *subjectAltNames; /** * certificate's embedded public key */ public_key_t *public_key; /** * challenge password */ chunk_t challengePassword; /** * Signature algorithm */ int algorithm; /** * Signature */ chunk_t signature; /** * Is the certificate request self-signed? */ bool self_signed; /** * Certificate request parsed from blob/file? */ bool parsed; /** * reference count */ refcount_t ref; }; /** * Imported from x509_cert.c */ extern void x509_parse_generalNames(chunk_t blob, int level0, bool implicit, linked_list_t *list); extern chunk_t x509_build_subjectAltNames(linked_list_t *list); METHOD(certificate_t, get_type, certificate_type_t, private_x509_pkcs10_t *this) { return CERT_PKCS10_REQUEST; } METHOD(certificate_t, get_subject, identification_t*, private_x509_pkcs10_t *this) { return this->subject; } METHOD(certificate_t, has_subject, id_match_t, private_x509_pkcs10_t *this, identification_t *subject) { return this->subject->matches(this->subject, subject); } METHOD(certificate_t, issued_by, bool, private_x509_pkcs10_t *this, certificate_t *issuer, signature_scheme_t *schemep) { public_key_t *key; signature_scheme_t scheme; bool valid; if (&this->public.interface.interface != issuer) { return FALSE; } if (this->self_signed) { return TRUE; } /* determine signature scheme */ scheme = signature_scheme_from_oid(this->algorithm); if (scheme == SIGN_UNKNOWN) { return FALSE; } /* get the public key contained in the certificate request */ key = this->public_key; if (!key) { return FALSE; } valid = key->verify(key, scheme, this->certificationRequestInfo, this->signature); if (valid && schemep) { *schemep = scheme; } return valid; } METHOD(certificate_t, get_public_key, public_key_t*, private_x509_pkcs10_t *this) { this->public_key->get_ref(this->public_key); return this->public_key; } METHOD(certificate_t, get_validity, bool, private_x509_pkcs10_t *this, time_t *when, time_t *not_before, time_t *not_after) { if (not_before) { *not_before = 0; } if (not_after) { *not_after = ~0; } return TRUE; } METHOD(certificate_t, get_encoding, bool, private_x509_pkcs10_t *this, cred_encoding_type_t type, chunk_t *encoding) { if (type == CERT_ASN1_DER) { *encoding = chunk_clone(this->encoding); return TRUE; } return lib->encoding->encode(lib->encoding, type, NULL, encoding, CRED_PART_PKCS10_ASN1_DER, this->encoding, CRED_PART_END); } METHOD(certificate_t, equals, bool, private_x509_pkcs10_t *this, certificate_t *other) { chunk_t encoding; bool equal; if (this == (private_x509_pkcs10_t*)other) { return TRUE; } if (other->get_type(other) != CERT_PKCS10_REQUEST) { return FALSE; } if (other->equals == (void*)equals) { /* skip allocation if we have the same implementation */ return chunk_equals(this->encoding, ((private_x509_pkcs10_t*)other)->encoding); } if (!other->get_encoding(other, CERT_ASN1_DER, &encoding)) { return FALSE; } equal = chunk_equals(this->encoding, encoding); free(encoding.ptr); return equal; } METHOD(certificate_t, get_ref, certificate_t*, private_x509_pkcs10_t *this) { ref_get(&this->ref); return &this->public.interface.interface; } METHOD(pkcs10_t, get_challengePassword, chunk_t, private_x509_pkcs10_t *this) { return this->challengePassword; } METHOD(pkcs10_t, create_subjectAltName_enumerator, enumerator_t*, private_x509_pkcs10_t *this) { return this->subjectAltNames->create_enumerator(this->subjectAltNames); } /** * ASN.1 definition of a PKCS#10 extension request */ static const asn1Object_t extensionRequestObjects[] = { { 0, "extensions", ASN1_SEQUENCE, ASN1_LOOP }, /* 0 */ { 1, "extension", ASN1_SEQUENCE, ASN1_NONE }, /* 1 */ { 2, "extnID", ASN1_OID, ASN1_BODY }, /* 2 */ { 2, "critical", ASN1_BOOLEAN, ASN1_DEF|ASN1_BODY }, /* 3 */ { 2, "extnValue", ASN1_OCTET_STRING, ASN1_BODY }, /* 4 */ { 1, "end loop", ASN1_EOC, ASN1_END }, /* 5 */ { 0, "exit", ASN1_EOC, ASN1_EXIT } }; #define PKCS10_EXTN_ID 2 #define PKCS10_EXTN_CRITICAL 3 #define PKCS10_EXTN_VALUE 4 /** * Parses a PKCS#10 extension request */ static bool parse_extension_request(private_x509_pkcs10_t *this, chunk_t blob, int level0) { asn1_parser_t *parser; chunk_t object; int objectID; int extn_oid = OID_UNKNOWN; bool success = FALSE; bool critical; parser = asn1_parser_create(extensionRequestObjects, blob); parser->set_top_level(parser, level0); while (parser->iterate(parser, &objectID, &object)) { u_int level = parser->get_level(parser)+1; switch (objectID) { case PKCS10_EXTN_ID: extn_oid = asn1_known_oid(object); break; case PKCS10_EXTN_CRITICAL: critical = object.len && *object.ptr; DBG2(DBG_ASN, " %s", critical ? "TRUE" : "FALSE"); break; case PKCS10_EXTN_VALUE: { switch (extn_oid) { case OID_SUBJECT_ALT_NAME: x509_parse_generalNames(object, level, FALSE, this->subjectAltNames); break; default: break; } break; } default: break; } } success = parser->success(parser); parser->destroy(parser); return success; } /** * Parses a PKCS#10 challenge password */ static bool parse_challengePassword(private_x509_pkcs10_t *this, chunk_t blob, int level) { char tag; if (blob.len < 2) { DBG1(DBG_ASN, "L%d - challengePassword: ASN.1 object smaller " "than 2 octets", level); return FALSE; } tag = *blob.ptr; if (tag < ASN1_UTF8STRING || tag > ASN1_IA5STRING) { DBG1(DBG_ASN, "L%d - challengePassword: ASN.1 object is not " "a character string", level); return FALSE; } if (asn1_length(&blob) == ASN1_INVALID_LENGTH) { DBG1(DBG_ASN, "L%d - challengePassword: ASN.1 object has an " "invalid length", level); return FALSE; } DBG2(DBG_ASN, "L%d - challengePassword:", level); DBG4(DBG_ASN, " '%.*s'", (int)blob.len, blob.ptr); return TRUE; } /** * ASN.1 definition of a PKCS#10 certificate request */ static const asn1Object_t certificationRequestObjects[] = { { 0, "certificationRequest", ASN1_SEQUENCE, ASN1_OBJ }, /* 0 */ { 1, "certificationRequestInfo", ASN1_SEQUENCE, ASN1_OBJ }, /* 1 */ { 2, "version", ASN1_INTEGER, ASN1_BODY }, /* 2 */ { 2, "subject", ASN1_SEQUENCE, ASN1_OBJ }, /* 3 */ { 2, "subjectPublicKeyInfo", ASN1_SEQUENCE, ASN1_RAW }, /* 4 */ { 2, "attributes", ASN1_CONTEXT_C_0, ASN1_LOOP }, /* 5 */ { 3, "attribute", ASN1_SEQUENCE, ASN1_NONE }, /* 6 */ { 4, "type", ASN1_OID, ASN1_BODY }, /* 7 */ { 4, "values", ASN1_SET, ASN1_LOOP }, /* 8 */ { 5, "value", ASN1_EOC, ASN1_RAW }, /* 9 */ { 4, "end loop", ASN1_EOC, ASN1_END }, /* 10 */ { 2, "end loop", ASN1_EOC, ASN1_END }, /* 11 */ { 1, "signatureAlgorithm", ASN1_EOC, ASN1_RAW }, /* 12 */ { 1, "signature", ASN1_BIT_STRING, ASN1_BODY }, /* 13 */ { 0, "exit", ASN1_EOC, ASN1_EXIT } }; #define PKCS10_CERT_REQUEST_INFO 1 #define PKCS10_VERSION 2 #define PKCS10_SUBJECT 3 #define PKCS10_SUBJECT_PUBLIC_KEY_INFO 4 #define PKCS10_ATTR_TYPE 7 #define PKCS10_ATTR_VALUE 9 #define PKCS10_ALGORITHM 12 #define PKCS10_SIGNATURE 13 /** * Parses a PKCS#10 certificate request */ static bool parse_certificate_request(private_x509_pkcs10_t *this) { asn1_parser_t *parser; chunk_t object; int objectID; int attr_oid = OID_UNKNOWN; bool success = FALSE; parser = asn1_parser_create(certificationRequestObjects, this->encoding); while (parser->iterate(parser, &objectID, &object)) { u_int level = parser->get_level(parser)+1; switch (objectID) { case PKCS10_CERT_REQUEST_INFO: this->certificationRequestInfo = object; break; case PKCS10_VERSION: if (object.len > 0 && *object.ptr != 0) { DBG1(DBG_ASN, "PKCS#10 certificate request format is " "not version 1"); goto end; } break; case PKCS10_SUBJECT: this->subject = identification_create_from_encoding(ID_DER_ASN1_DN, object); DBG2(DBG_ASN, " '%Y'", this->subject); break; case PKCS10_SUBJECT_PUBLIC_KEY_INFO: this->public_key = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY, BUILD_BLOB_ASN1_DER, object, BUILD_END); if (this->public_key == NULL) { goto end; } break; case PKCS10_ATTR_TYPE: attr_oid = asn1_known_oid(object); break; case PKCS10_ATTR_VALUE: switch (attr_oid) { case OID_EXTENSION_REQUEST: if (!parse_extension_request(this, object, level)) { goto end; } break; case OID_CHALLENGE_PASSWORD: if (!parse_challengePassword(this, object, level)) { goto end; } break; default: break; } break; case PKCS10_ALGORITHM: this->algorithm = asn1_parse_algorithmIdentifier(object, level, NULL); break; case PKCS10_SIGNATURE: this->signature = chunk_skip(object, 1); break; default: break; } } success = parser->success(parser); end: parser->destroy(parser); if (success) { /* check if the certificate request is self-signed */ if (issued_by(this, &this->public.interface.interface, NULL)) { this->self_signed = TRUE; } else { DBG1(DBG_LIB, "certificate request is not self-signed"); success = FALSE; } } return success; } METHOD(certificate_t, destroy, void, private_x509_pkcs10_t *this) { if (ref_put(&this->ref)) { this->subjectAltNames->destroy_offset(this->subjectAltNames, offsetof(identification_t, destroy)); DESTROY_IF(this->subject); DESTROY_IF(this->public_key); chunk_free(&this->encoding); if (!this->parsed) { /* only parsed certificate requests point these fields to "encoded" */ chunk_free(&this->certificationRequestInfo); chunk_free(&this->challengePassword); chunk_free(&this->signature); } free(this); } } /** * create an empty but initialized PKCS#10 certificate request */ static private_x509_pkcs10_t* create_empty(void) { private_x509_pkcs10_t *this; INIT(this, .public = { .interface = { .interface = { .get_type = _get_type, .get_subject = _get_subject, .get_issuer = _get_subject, .has_subject = _has_subject, .has_issuer = _has_subject, .issued_by = _issued_by, .get_public_key = _get_public_key, .get_validity = _get_validity, .get_encoding = _get_encoding, .equals = _equals, .get_ref = _get_ref, .destroy = _destroy, }, .get_challengePassword = _get_challengePassword, .create_subjectAltName_enumerator = _create_subjectAltName_enumerator, }, }, .subjectAltNames = linked_list_create(), .ref = 1, ); return this; } /** * Generate and sign a new certificate request */ static bool generate(private_x509_pkcs10_t *cert, private_key_t *sign_key, int digest_alg) { chunk_t key_info, subjectAltNames, attributes; chunk_t extensionRequest = chunk_empty; chunk_t challengePassword = chunk_empty; signature_scheme_t scheme; identification_t *subject; subject = cert->subject; cert->public_key = sign_key->get_public_key(sign_key); /* select signature scheme */ cert->algorithm = hasher_signature_algorithm_to_oid(digest_alg, sign_key->get_type(sign_key)); if (cert->algorithm == OID_UNKNOWN) { return FALSE; } scheme = signature_scheme_from_oid(cert->algorithm); if (!cert->public_key->get_encoding(cert->public_key, PUBKEY_SPKI_ASN1_DER, &key_info)) { return FALSE; } /* encode subjectAltNames */ subjectAltNames = x509_build_subjectAltNames(cert->subjectAltNames); if (subjectAltNames.ptr) { extensionRequest = asn1_wrap(ASN1_SEQUENCE, "mm", asn1_build_known_oid(OID_EXTENSION_REQUEST), asn1_wrap(ASN1_SET, "m", asn1_wrap(ASN1_SEQUENCE, "m", subjectAltNames) )); } if (cert->challengePassword.len > 0) { asn1_t type = asn1_is_printablestring(cert->challengePassword) ? ASN1_PRINTABLESTRING : ASN1_T61STRING; challengePassword = asn1_wrap(ASN1_SEQUENCE, "mm", asn1_build_known_oid(OID_CHALLENGE_PASSWORD), asn1_wrap(ASN1_SET, "m", asn1_simple_object(type, cert->challengePassword) ) ); } attributes = asn1_wrap(ASN1_CONTEXT_C_0, "mm", extensionRequest, challengePassword); cert->certificationRequestInfo = asn1_wrap(ASN1_SEQUENCE, "ccmm", ASN1_INTEGER_0, subject->get_encoding(subject), key_info, attributes); if (!sign_key->sign(sign_key, scheme, cert->certificationRequestInfo, &cert->signature)) { return FALSE; } cert->encoding = asn1_wrap(ASN1_SEQUENCE, "cmm", cert->certificationRequestInfo, asn1_algorithmIdentifier(cert->algorithm), asn1_bitstring("c", cert->signature)); return TRUE; } /** * See header. */ x509_pkcs10_t *x509_pkcs10_load(certificate_type_t type, va_list args) { chunk_t blob = chunk_empty; while (TRUE) { switch (va_arg(args, builder_part_t)) { case BUILD_BLOB_ASN1_DER: blob = va_arg(args, chunk_t); continue; case BUILD_END: break; default: return NULL; } break; } if (blob.ptr) { private_x509_pkcs10_t *cert = create_empty(); cert->encoding = chunk_clone(blob); cert->parsed = TRUE; if (parse_certificate_request(cert)) { return &cert->public; } destroy(cert); } return NULL; } /** * See header. */ x509_pkcs10_t *x509_pkcs10_gen(certificate_type_t type, va_list args) { private_x509_pkcs10_t *cert; private_key_t *sign_key = NULL; hash_algorithm_t digest_alg = HASH_SHA1; cert = create_empty(); while (TRUE) { switch (va_arg(args, builder_part_t)) { case BUILD_SIGNING_KEY: sign_key = va_arg(args, private_key_t*); continue; case BUILD_SUBJECT: cert->subject = va_arg(args, identification_t*); cert->subject = cert->subject->clone(cert->subject); continue; case BUILD_SUBJECT_ALTNAMES: { enumerator_t *enumerator; identification_t *id; linked_list_t *list; list = va_arg(args, linked_list_t*); enumerator = list->create_enumerator(list); while (enumerator->enumerate(enumerator, &id)) { cert->subjectAltNames->insert_last(cert->subjectAltNames, id->clone(id)); } enumerator->destroy(enumerator); continue; } case BUILD_CHALLENGE_PWD: cert->challengePassword = chunk_clone(va_arg(args, chunk_t)); continue; case BUILD_DIGEST_ALG: digest_alg = va_arg(args, int); continue; case BUILD_END: break; default: destroy(cert); return NULL; } break; } if (sign_key && generate(cert, sign_key, digest_alg)) { return &cert->public; } destroy(cert); return NULL; }
246045.c
//------------------------------------------------------------------------------ // GB_AxB: hard-coded functions for semiring: C<M>=A*B or A'*B //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_ek_slice.h" #include "GB_bracket.h" #include "GB_iterator.h" #include "GB_sort.h" #include "GB_atomics.h" #include "GB_AxB_saxpy3.h" #include "GB_AxB__include.h" // The C=A*B semiring is defined by the following types and operators: // A'*B function (dot2): GB_Adot2B__max_plus_fp64 // A'*B function (dot3): GB_Adot3B__max_plus_fp64 // C+=A'*B function (dot4): GB_Adot4B__max_plus_fp64 // A*B function (saxpy3): GB_Asaxpy3B__max_plus_fp64 // C type: double // A type: double // B type: double // Multiply: z = (aik + bkj) // Add: cij = fmax (cij, z) // 'any' monoid? 0 // atomic? 1 // OpenMP atomic? 0 // MultAdd: cij = fmax (cij, (aik + bkj)) // Identity: ((double) -INFINITY) // Terminal: if (cij == ((double) INFINITY)) break ; #define GB_ATYPE \ double #define GB_BTYPE \ double #define GB_CTYPE \ double // aik = Ax [pA] #define GB_GETA(aik,Ax,pA) \ double aik = Ax [pA] // bkj = Bx [pB] #define GB_GETB(bkj,Bx,pB) \ double bkj = Bx [pB] #define GB_CX(p) Cx [p] // multiply operator #define GB_MULT(z, x, y) \ z = (x + y) // multiply-add #define GB_MULTADD(z, x, y) \ z = fmax (z, (x + y)) // monoid identity value #define GB_IDENTITY \ ((double) -INFINITY) // break if cij reaches the terminal value (dot product only) #define GB_DOT_TERMINAL(cij) \ if (cij == ((double) INFINITY)) break ; // simd pragma for dot-product loop vectorization #define GB_PRAGMA_VECTORIZE_DOT \ ; // simd pragma for other loop vectorization #define GB_PRAGMA_VECTORIZE GB_PRAGMA_SIMD // declare the cij scalar #define GB_CIJ_DECLARE(cij) \ double cij // save the value of C(i,j) #define GB_CIJ_SAVE(cij,p) Cx [p] = cij // cij = Cx [pC] #define GB_GETC(cij,pC) \ cij = Cx [pC] // Cx [pC] = cij #define GB_PUTC(cij,pC) \ Cx [pC] = cij // Cx [p] = t #define GB_CIJ_WRITE(p,t) Cx [p] = t // C(i,j) += t #define GB_CIJ_UPDATE(p,t) \ Cx [p] = fmax (Cx [p], t) // x + y #define GB_ADD_FUNCTION(x,y) \ fmax (x, y) // type with size of GB_CTYPE, and can be used in compare-and-swap #define GB_CTYPE_PUN \ uint64_t // bit pattern for bool, 8-bit, 16-bit, and 32-bit integers #define GB_CTYPE_BITS \ 0 // 1 if monoid update can skipped entirely (the ANY monoid) #define GB_IS_ANY_MONOID \ 0 // 1 if monoid update is EQ #define GB_IS_EQ_MONOID \ 0 // 1 if monoid update can be done atomically, 0 otherwise #define GB_HAS_ATOMIC \ 1 // 1 if monoid update can be done with an OpenMP atomic update, 0 otherwise #if GB_MICROSOFT #define GB_HAS_OMP_ATOMIC \ 0 #else #define GB_HAS_OMP_ATOMIC \ 0 #endif // 1 for the ANY_PAIR semirings #define GB_IS_ANY_PAIR_SEMIRING \ 0 // 1 if PAIR is the multiply operator #define GB_IS_PAIR_MULTIPLIER \ 0 // atomic compare-exchange #define GB_ATOMIC_COMPARE_EXCHANGE(target, expected, desired) \ GB_ATOMIC_COMPARE_EXCHANGE_64 (target, expected, desired) #if GB_IS_ANY_PAIR_SEMIRING // result is purely symbolic; no numeric work to do. Hx is not used. #define GB_HX_WRITE(i,t) #define GB_CIJ_GATHER(p,i) #define GB_HX_UPDATE(i,t) #define GB_CIJ_MEMCPY(p,i,len) #else // Hx [i] = t #define GB_HX_WRITE(i,t) Hx [i] = t // Cx [p] = Hx [i] #define GB_CIJ_GATHER(p,i) Cx [p] = Hx [i] // Hx [i] += t #define GB_HX_UPDATE(i,t) \ Hx [i] = fmax (Hx [i], t) // memcpy (&(Cx [p]), &(Hx [i]), len) #define GB_CIJ_MEMCPY(p,i,len) \ memcpy (Cx +(p), Hx +(i), (len) * sizeof(double)) #endif // disable this semiring and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_MAX || GxB_NO_PLUS || GxB_NO_FP64 || GxB_NO_MAX_FP64 || GxB_NO_PLUS_FP64 || GxB_NO_MAX_PLUS_FP64) //------------------------------------------------------------------------------ // C=A'*B or C<!M>=A'*B: dot product (phase 2) //------------------------------------------------------------------------------ GrB_Info GB_Adot2B__max_plus_fp64 ( GrB_Matrix C, const GrB_Matrix M, const bool Mask_struct, const GrB_Matrix *Aslice, bool A_is_pattern, const GrB_Matrix B, bool B_is_pattern, int64_t *GB_RESTRICT B_slice, int64_t *GB_RESTRICT *C_counts, int nthreads, int naslice, int nbslice ) { // C<M>=A'*B now uses dot3 #if GB_DISABLE return (GrB_NO_VALUE) ; #else #define GB_PHASE_2_OF_2 #include "GB_AxB_dot2_meta.c" #undef GB_PHASE_2_OF_2 return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C<M>=A'*B: masked dot product method (phase 2) //------------------------------------------------------------------------------ GrB_Info GB_Adot3B__max_plus_fp64 ( GrB_Matrix C, const GrB_Matrix M, const bool Mask_struct, const GrB_Matrix A, bool A_is_pattern, const GrB_Matrix B, bool B_is_pattern, const GB_task_struct *GB_RESTRICT TaskList, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_AxB_dot3_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C+=A'*B: dense dot product //------------------------------------------------------------------------------ GrB_Info GB_Adot4B__max_plus_fp64 ( GrB_Matrix C, const GrB_Matrix A, bool A_is_pattern, int64_t *GB_RESTRICT A_slice, int naslice, const GrB_Matrix B, bool B_is_pattern, int64_t *GB_RESTRICT B_slice, int nbslice, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_AxB_dot4_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C=A*B, C<M>=A*B, C<!M>=A*B: saxpy3 method (Gustavson + Hash) //------------------------------------------------------------------------------ #include "GB_AxB_saxpy3_template.h" GrB_Info GB_Asaxpy3B__max_plus_fp64 ( GrB_Matrix C, const GrB_Matrix M, bool Mask_comp, const bool Mask_struct, const GrB_Matrix A, bool A_is_pattern, const GrB_Matrix B, bool B_is_pattern, GB_saxpy3task_struct *GB_RESTRICT TaskList, const int ntasks, const int nfine, const int nthreads, GB_Context Context ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_AxB_saxpy3_template.c" return (GrB_SUCCESS) ; #endif } #endif
261703.c
/*- * Copyright (c) 2003-2008 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "test.h" __FBSDID("$FreeBSD: soc2013/dpl/head/contrib/libarchive/tar/test/test_option_s.c 232436 2012-02-25 10:58:02Z mm $"); DEFINE_TEST(test_option_s) { struct stat st; /* Create a sample file hierarchy. */ assertMakeDir("in", 0755); assertMakeDir("in/d1", 0755); assertMakeFile("in/d1/foo", 0644, "foo"); assertMakeFile("in/d1/bar", 0644, "bar"); if (canSymlink()) { assertMakeFile("in/d1/realfile", 0644, "realfile"); assertMakeSymlink("in/d1/symlink", "realfile"); } assertMakeFile("in/d1/hardlink1", 0644, "hardlinkedfile"); assertMakeHardlink("in/d1/hardlink2", "in/d1/hardlink1"); /* Does tar support -s option ? */ systemf("%s -cf - -s /foo/bar/ in/d1/foo > NUL 2> check.err", testprog); assertEqualInt(0, stat("check.err", &st)); if (st.st_size != 0) { skipping("%s does not support -s option on this platform", testprog); return; } /* * Test 1: Filename substitution when creating archives. */ assertMakeDir("test1", 0755); systemf("%s -cf test1_1.tar -s /foo/bar/ in/d1/foo", testprog); systemf("%s -xf test1_1.tar -C test1", testprog); assertFileContents("foo", 3, "test1/in/d1/bar"); systemf("%s -cf test1_2.tar -s /d1/d2/ in/d1/foo", testprog); systemf("%s -xf test1_2.tar -C test1", testprog); assertFileContents("foo", 3, "test1/in/d2/foo"); /* * Test 2: Basic substitution when extracting archive. */ assertMakeDir("test2", 0755); systemf("%s -cf test2.tar in/d1/foo", testprog); systemf("%s -xf test2.tar -s /foo/bar/ -C test2", testprog); assertFileContents("foo", 3, "test2/in/d1/bar"); /* * Test 3: Files with empty names shouldn't be archived. */ systemf("%s -cf test3.tar -s ,in/d1/foo,, in/d1/foo", testprog); systemf("%s -tvf test3.tar > in.lst", testprog); assertEmptyFile("in.lst"); /* * Test 4: Multiple substitutions when extracting archive. */ assertMakeDir("test4", 0755); systemf("%s -cf test4.tar in/d1/foo in/d1/bar", testprog, testprog); systemf("%s -xf test4.tar -s /foo/bar/ -s }bar}baz} -C test4", testprog, testprog); assertFileContents("foo", 3, "test4/in/d1/bar"); assertFileContents("bar", 3, "test4/in/d1/baz"); /* * Test 5: Name-switching substitutions when extracting archive. */ assertMakeDir("test5", 0755); systemf("%s -cf test5.tar in/d1/foo in/d1/bar", testprog, testprog); systemf("%s -xf test5.tar -s /foo/bar/ -s }bar}foo} -C test5", testprog, testprog); assertFileContents("foo", 3, "test5/in/d1/bar"); assertFileContents("bar", 3, "test5/in/d1/foo"); /* * Test 6: symlinks get renamed by default */ if (canSymlink()) { /* At extraction time. */ assertMakeDir("test6a", 0755); systemf("%s -cf - in/d1 | %s -xf - -s /d1/d2/ -C test6a", testprog, testprog); assertFileContents("realfile", 8, "test6a/in/d2/realfile"); assertFileContents("realfile", 8, "test6a/in/d2/symlink"); assertIsSymlink("test6a/in/d2/symlink", "realfile"); /* At creation time. */ assertMakeDir("test6b", 0755); systemf("%s -cf - -s /d1/d2/ in/d1 | %s -xf - -C test6b", testprog, testprog); assertFileContents("realfile", 8, "test6b/in/d2/realfile"); assertFileContents("realfile", 8, "test6b/in/d2/symlink"); assertIsSymlink("test6b/in/d2/symlink", "realfile"); } /* * Test 7: selective renaming of symlink target */ if (canSymlink()) { /* At extraction. */ assertMakeDir("test7a", 0755); systemf("%s -cf - in/d1 | %s -xf - -s /realfile/realfile-renamed/ -C test7a", testprog, testprog); assertFileContents("realfile", 8, "test7a/in/d1/realfile-renamed"); assertFileContents("realfile", 8, "test7a/in/d1/symlink"); assertIsSymlink("test7a/in/d1/symlink", "realfile-renamed"); /* At creation. */ assertMakeDir("test7b", 0755); systemf("%s -cf - -s /realfile/realfile-renamed/ in/d1 | %s -xf - -C test7b", testprog, testprog); assertFileContents("realfile", 8, "test7b/in/d1/realfile-renamed"); assertFileContents("realfile", 8, "test7b/in/d1/symlink"); assertIsSymlink("test7b/in/d1/symlink", "realfile-renamed"); } /* * Test 8: hardlinks get renamed by default */ /* At extraction time. */ assertMakeDir("test8a", 0755); systemf("%s -cf test8a.tar in/d1", testprog); systemf("%s -xf test8a.tar -s /d1/d2/ -C test8a", testprog); assertIsHardlink("test8a/in/d2/hardlink1", "test8a/in/d2/hardlink2"); /* At creation time. */ assertMakeDir("test8b", 0755); systemf("%s -cf test8b.tar -s /d1/d2/ in/d1", testprog); systemf("%s -xf test8b.tar -C test8b", testprog); assertIsHardlink("test8b/in/d2/hardlink1", "test8b/in/d2/hardlink2"); /* * Test 9: selective renaming of hardlink target */ /* At extraction. (assuming hardlink2 is the hardlink entry) */ assertMakeDir("test9a", 0755); systemf("%s -cf test9a.tar in/d1", testprog); systemf("%s -xf test9a.tar -s /hardlink1/hardlink1-renamed/ -C test9a", testprog); assertIsHardlink("test9a/in/d1/hardlink1-renamed", "test9a/in/d1/hardlink2"); /* At extraction. (assuming hardlink1 is the hardlink entry) */ assertMakeDir("test9b", 0755); systemf("%s -cf test9b.tar in/d1", testprog); systemf("%s -xf test9b.tar -s /hardlink2/hardlink2-renamed/ -C test9b", testprog); assertIsHardlink("test9b/in/d1/hardlink1", "test9b/in/d1/hardlink2-renamed"); /* At creation. (assuming hardlink2 is the hardlink entry) */ assertMakeDir("test9c", 0755); systemf("%s -cf test9c.tar -s /hardlink1/hardlink1-renamed/ in/d1", testprog); systemf("%s -xf test9c.tar -C test9c", testprog); assertIsHardlink("test9c/in/d1/hardlink1-renamed", "test9c/in/d1/hardlink2"); /* At creation. (assuming hardlink1 is the hardlink entry) */ assertMakeDir("test9d", 0755); systemf("%s -cf test9d.tar -s /hardlink2/hardlink2-renamed/ in/d1", testprog); systemf("%s -xf test9d.tar -C test9d", testprog); assertIsHardlink("test9d/in/d1/hardlink1", "test9d/in/d1/hardlink2-renamed"); /* * Test 10: renaming symlink target without repointing symlink */ if (canSymlink()) { /* At extraction. */ assertMakeDir("test10a", 0755); systemf("%s -cf - in/d1 | %s -xf - -s /realfile/foo/S -s /foo/realfile/ -C test10a", testprog, testprog); assertFileContents("realfile", 8, "test10a/in/d1/foo"); assertFileContents("foo", 3, "test10a/in/d1/realfile"); assertFileContents("foo", 3, "test10a/in/d1/symlink"); assertIsSymlink("test10a/in/d1/symlink", "realfile"); /* At creation. */ assertMakeDir("test10b", 0755); systemf("%s -cf - -s /realfile/foo/S -s /foo/realfile/ in/d1 | %s -xf - -C test10b", testprog, testprog); assertFileContents("realfile", 8, "test10b/in/d1/foo"); assertFileContents("foo", 3, "test10b/in/d1/realfile"); assertFileContents("foo", 3, "test10b/in/d1/symlink"); assertIsSymlink("test10b/in/d1/symlink", "realfile"); } /* * Test 11: repointing symlink without renaming file */ if (canSymlink()) { /* At extraction. */ assertMakeDir("test11a", 0755); systemf("%s -cf - in/d1 | %s -xf - -s /realfile/foo/sR -C test11a", testprog, testprog); assertFileContents("foo", 3, "test11a/in/d1/foo"); assertFileContents("realfile", 8, "test11a/in/d1/realfile"); assertFileContents("foo", 3, "test11a/in/d1/symlink"); assertIsSymlink("test11a/in/d1/symlink", "foo"); /* At creation. */ assertMakeDir("test11b", 0755); systemf("%s -cf - -s /realfile/foo/R in/d1 | %s -xf - -C test11b", testprog, testprog); assertFileContents("foo", 3, "test11b/in/d1/foo"); assertFileContents("realfile", 8, "test11b/in/d1/realfile"); assertFileContents("foo", 3, "test11b/in/d1/symlink"); assertIsSymlink("test11b/in/d1/symlink", "foo"); } /* * Test 12: renaming hardlink target without changing hardlink. * (Requires a pre-built archive, since we otherwise can't know * which element will be stored as the hardlink.) */ extract_reference_file("test_option_s.tar.Z"); assertMakeDir("test12a", 0755); systemf("%s -xf test_option_s.tar.Z -s /hardlink1/foo/H -s /foo/hardlink1/ %s -C test12a", testprog, canSymlink()?"":"--exclude in/d1/symlink"); assertFileContents("foo", 3, "test12a/in/d1/hardlink1"); assertFileContents("hardlinkedfile", 14, "test12a/in/d1/foo"); assertFileContents("foo", 3, "test12a/in/d1/hardlink2"); assertIsHardlink("test12a/in/d1/hardlink1", "test12a/in/d1/hardlink2"); /* TODO: Expand this test to verify creation as well. * Since either hardlink1 or hardlink2 might get stored as a hardlink, * this will either requiring testing both cases and accepting either * pass, or some very creative renames that can be tested regardless. */ /* * Test 13: repoint hardlink without changing files * (Requires a pre-built archive, since we otherwise can't know * which element will be stored as the hardlink.) */ extract_reference_file("test_option_s.tar.Z"); assertMakeDir("test13a", 0755); systemf("%s -xf test_option_s.tar.Z -s /hardlink1/foo/Rh -s /foo/hardlink1/Rh %s -C test13a", testprog, canSymlink()?"":"--exclude in/d1/symlink"); assertFileContents("foo", 3, "test13a/in/d1/foo"); assertFileContents("hardlinkedfile", 14, "test13a/in/d1/hardlink1"); assertFileContents("foo", 3, "test13a/in/d1/hardlink2"); assertIsHardlink("test13a/in/d1/foo", "test13a/in/d1/hardlink2"); /* TODO: See above; expand this test to verify renames at creation. */ }
19078.c
/* * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) * From ASN.1 module "NBIOT-RRC-Definitions" * found in "/home/user/openairinterface5g/openair2/RRC/LTE/MESSAGES/asn1c/ASN1_files/lte-rrc-14.7.0.asn1" * `asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example -D /home/user/openairinterface5g/cmake_targets/lte_build_oai/build/CMakeFiles/RRC_Rel14` */ #include "CQI-NPDCCH-NB-r14.h" /* * This type is implemented using NativeEnumerated, * so here we adjust the DEF accordingly. */ asn_per_constraints_t asn_PER_type_CQI_NPDCCH_NB_r14_constr_1 CC_NOTUSED = { { APC_CONSTRAINED, 4, 4, 0, 12 } /* (0..12) */, { APC_UNCONSTRAINED, -1, -1, 0, 0 }, 0, 0 /* No PER value map */ }; static const asn_INTEGER_enum_map_t asn_MAP_CQI_NPDCCH_NB_r14_value2enum_1[] = { { 0, 14, "noMeasurements" }, { 1, 14, "candidateRep-A" }, { 2, 14, "candidateRep-B" }, { 3, 14, "candidateRep-C" }, { 4, 14, "candidateRep-D" }, { 5, 14, "candidateRep-E" }, { 6, 14, "candidateRep-F" }, { 7, 14, "candidateRep-G" }, { 8, 14, "candidateRep-H" }, { 9, 14, "candidateRep-I" }, { 10, 14, "candidateRep-J" }, { 11, 14, "candidateRep-K" }, { 12, 14, "candidateRep-L" } }; static const unsigned int asn_MAP_CQI_NPDCCH_NB_r14_enum2value_1[] = { 1, /* candidateRep-A(1) */ 2, /* candidateRep-B(2) */ 3, /* candidateRep-C(3) */ 4, /* candidateRep-D(4) */ 5, /* candidateRep-E(5) */ 6, /* candidateRep-F(6) */ 7, /* candidateRep-G(7) */ 8, /* candidateRep-H(8) */ 9, /* candidateRep-I(9) */ 10, /* candidateRep-J(10) */ 11, /* candidateRep-K(11) */ 12, /* candidateRep-L(12) */ 0 /* noMeasurements(0) */ }; const asn_INTEGER_specifics_t asn_SPC_CQI_NPDCCH_NB_r14_specs_1 = { asn_MAP_CQI_NPDCCH_NB_r14_value2enum_1, /* "tag" => N; sorted by tag */ asn_MAP_CQI_NPDCCH_NB_r14_enum2value_1, /* N => "tag"; sorted by N */ 13, /* Number of elements in the maps */ 0, /* Enumeration is not extensible */ 1, /* Strict enumeration */ 0, /* Native long size */ 0 }; static const ber_tlv_tag_t asn_DEF_CQI_NPDCCH_NB_r14_tags_1[] = { (ASN_TAG_CLASS_UNIVERSAL | (10 << 2)) }; asn_TYPE_descriptor_t asn_DEF_CQI_NPDCCH_NB_r14 = { "CQI-NPDCCH-NB-r14", "CQI-NPDCCH-NB-r14", &asn_OP_NativeEnumerated, asn_DEF_CQI_NPDCCH_NB_r14_tags_1, sizeof(asn_DEF_CQI_NPDCCH_NB_r14_tags_1) /sizeof(asn_DEF_CQI_NPDCCH_NB_r14_tags_1[0]), /* 1 */ asn_DEF_CQI_NPDCCH_NB_r14_tags_1, /* Same as above */ sizeof(asn_DEF_CQI_NPDCCH_NB_r14_tags_1) /sizeof(asn_DEF_CQI_NPDCCH_NB_r14_tags_1[0]), /* 1 */ { 0, &asn_PER_type_CQI_NPDCCH_NB_r14_constr_1, NativeEnumerated_constraint }, 0, 0, /* Defined elsewhere */ &asn_SPC_CQI_NPDCCH_NB_r14_specs_1 /* Additional specs */ };
368776.c
#include <stdio.h> #ifdef _OPENMP #include <omp.h> #endif int main() { int a, b, c; #pragma omp parallel reduction (user_iden:a, b) reduction (user_iden:a, c) { printf("This is for testing parser and AST construction, which could be only syntax correct.\n"); } #pragma omp parallel reduction (inscan, user_iden:a, b) reduction (user_iden:a, c) { printf("This is for testing parser and AST construction, which could be only syntax correct.\n"); } return 0; }
128524.c
/* * Copyright (c) 2012-2016 Israel Jacquez * See LICENSE for details. * * Israel Jacquez <[email protected]> */ #include <scu/timer.h> #include <scu-internal.h> void scu_timer_1_mode_set(bool sp_line) { uint32_t t1md; t1md = (uint32_t)(sp_line << 8); /* Write to memory */ MEMORY_WRITE(32, SCU(T1MD), t1md); }
600569.c
#define thisprog "xe-math_doublet" #define TITLE_STRING thisprog" v 3: 20.January.2019 [JRH]" #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> /* <TAGS>math </TAGS> v 3: 20.January.2019 [JRH] - major overhaul, now allows outputting of other columns v 2: 1.December.2014 [JRH] - now all lines inpurt have a corresponding output - nan is output as required */ /* external functions start */ char *xf_lineread1(char *line, long *maxlinelen, FILE *fpin); long *xf_lineparse2(char *line,char *delimiters, long *nwords); /* external functions end */ int main(int argc, char *argv[]) { /****************************************************************************** Initialise variables ******************************************************************************/ char infile[256],message[256],*line=NULL,*templine=NULL; int x,y,z,col,decimals; long ii,jj,kk,nn,mm,sizeoftempline=sizeof(*templine),maxlinelen=0,prevlinelen=0,nwords=0,*iword=NULL; float a,b,c; double aa,bb,cc,dd,resultd[64]; FILE *fpin; /* program-specific */ long colx,coly,jj2; double bb2; /* arguments */ int settype=1,setlong=0, setoutall=0; long setcolx=1,setcoly=2; /****************************************************************************** If only one argument (executable's name) print instructions ******************************************************************************/ if(argc<2) { fprintf(stderr,"\n"); fprintf(stderr,"----------------------------------------------------------------------\n"); fprintf(stderr,"%s\n",TITLE_STRING); fprintf(stderr,"----------------------------------------------------------------------\n"); fprintf(stderr,"Modify column-y by column-x\n"); fprintf(stderr,"Non-numeric or non-finite fields produce NAN output (line-count preserved)\n"); fprintf(stderr,"USAGE:\n"); fprintf(stderr," %s [input] [options]\n",thisprog); fprintf(stderr," [input]: file name or \"stdin\" in format <col1> <col2>\n"); fprintf(stderr,"VALID OPTIONS: defaults in []:\n"); fprintf(stderr," -cx: column containing the modifier [%ld]\n",setcolx); fprintf(stderr," -cy: column to be modified [%ld]\n",setcoly); fprintf(stderr," -long: assume input is long-integers (0=NO 1=YES) [%d]\n",setlong); fprintf(stderr," -t type of operation[%d]\n",settype); fprintf(stderr," 1: y+x addition\n"); fprintf(stderr," 2: y-x subtraction\n"); fprintf(stderr," 3: y*x multiplication\n"); fprintf(stderr," 4: y/x division\n"); fprintf(stderr," -out: output modified column (0) or all columns (1) [%d]\n",setoutall); fprintf(stderr,"EXAMPLES:\n"); fprintf(stderr," cat datafile.txt | %s stdin -t 2\n",thisprog); fprintf(stderr," %s datafile.txt -t 1\n",thisprog); fprintf(stderr,"OUTPUT:\n"); fprintf(stderr," single column result\n"); fprintf(stderr,"----------------------------------------------------------------------\n"); fprintf(stderr,"\n"); exit(0); } /* READ THE FILENAME AND OPTIONAL ARGUMENTS */ sprintf(infile,"%s",argv[1]); for(ii=2;ii<argc;ii++) { if( *(argv[ii]+0) == '-') { if((ii+1)>=argc) {fprintf(stderr,"\n--- Error [%s]: missing value for argument \"%s\"\n\n",thisprog,argv[ii]); exit(1);} else if(strcmp(argv[ii],"-cx")==0) setcolx= atol(argv[++ii]); else if(strcmp(argv[ii],"-cy")==0) setcoly= atol(argv[++ii]); else if(strcmp(argv[ii],"-t")==0) settype= atoi(argv[++ii]); else if(strcmp(argv[ii],"-long")==0) setlong= atoi(argv[++ii]); else if(strcmp(argv[ii],"-out")==0) setoutall= atoi(argv[++ii]); else {fprintf(stderr,"\n--- Error [%s]: invalid command line argument \"%s\"\n\n",thisprog,argv[ii]); exit(1);} }} if(setcolx<1) {fprintf(stderr,"\n--- Error [%s]: invalid input column (-cx %ld) - must be >=1\n\n",thisprog,setcolx);exit(1);} if(setcoly<1) {fprintf(stderr,"\n--- Error [%s]: invalid input column (-cy %ld) - must be >=1\n\n",thisprog,setcoly);exit(1);} if(settype<1||settype>4) {fprintf(stderr,"\n--- Error [%s]: invalid operation type (-t %d): must be 1-4\n\n",thisprog,settype);exit(1);} if(setlong!=0&&setlong!=1) {fprintf(stderr,"\n--- Error [%s]: invalid -long (%d): must be 0 or 1\n\n",thisprog,setlong);exit(1);} if(setoutall!=0&&setoutall!=1) {fprintf(stderr,"\n--- Error [%s]: invalid -out (%d): must be 0 or 1\n\n",thisprog,setoutall);exit(1);} /* SET COLUMNS TO ZERO-OFFSET REFERENCE */ colx= setcolx-1; coly= setcoly-1; /* STAR TSCANNING TTHE INPUT */ if(strcmp(infile,"stdin")==0) fpin=stdin; else if((fpin=fopen(infile,"r"))==0) {fprintf(stderr,"\n--- Error [%s]: file \"%s\" not found\n\n",thisprog,infile);exit(1);} while((line=xf_lineread1(line,&maxlinelen,fpin))!=NULL) { if(maxlinelen==-1) {fprintf(stderr,"\n--- Error [%s]: readline function encountered insufficient memory\n\n",thisprog);exit(1);} /* make a temporary copy of the line before parsing it */ if(maxlinelen>prevlinelen) { prevlinelen= maxlinelen; templine= realloc(templine,(maxlinelen+1)*sizeoftempline); if(templine==NULL) {fprintf(stderr,"\n--- Error [%s]: insufficient memory\n\n",thisprog);exit(1);}} strcpy(templine,line); /* parse the line */ iword= xf_lineparse2(line,"\t",&nwords); if(nwords<0) {fprintf(stderr,"\n--- Error [%s]: lineparse function encountered insufficient memory\n\n",thisprog);exit(1);}; /* if missing coly, output nan */ if(nwords<setcolx || nwords<setcoly) { //TEST: printf("nwords=%ld setcoly=%ld\n",nwords,setcoly); if(setoutall==0) printf("nan\n"); else {for(ii=0;ii<nwords;ii++) {if(ii>0) printf("\t");if(ii==coly) printf("nan"); else printf("%s",(line+iword[ii]));} printf("\n");} continue; } /* OPTION-1: IF BOTH COLUMNS ARE FOUND, OUTPUT FOR FLOATING-POINT */ mm= 2; if(setlong==0) { if(sscanf(line+iword[colx],"%lf",&aa)==1) mm--; if(sscanf(line+iword[coly],"%lf",&bb)==1) mm--; //TEST: printf("%s %s mm=%ld\n",(line+iword[colx]),(line+iword[coly]),mm); if(mm!=0) { //TEST: printf("header\n"); if(setoutall==0) printf("%s\n",(line+iword[coly])); else printf("%s",templine); continue; } /* detemine converted output (bb2) */ if(!isfinite(aa) || !isfinite(bb)) bb2=NAN; else if(settype==1) bb2= bb+aa; else if(settype==2) bb2= bb-aa; else if(settype==3) bb2= bb*aa; else if(settype==4) { if(aa==0.0) bb2= NAN; else if(bb==0.0) bb2= INFINITY; else bb2= bb/aa; } /* output */ if(setoutall==0) printf("%lf\n",bb2); else { for(ii=0;ii<nwords;ii++) { if(ii>0) printf("\t"); if(ii==coly) printf("%lf",bb2); else printf("%s",(line+iword[ii])); } printf("\n"); } } /* OPTION-2: IF BOTH COLUMNS ARE FOUND, OUTPUT FOR LONG-INTEGERS */ if(setlong==1) { if(sscanf(line+iword[colx],"%ld",&ii)==1) mm--; if(sscanf(line+iword[coly],"%ld",&jj)==1) mm--; if(mm!=0) { if(setoutall==0) printf("%s\n",(line+iword[coly])); else printf("%s",templine); continue; } /* detemine converted output (jj2) */ else if(settype==1) jj2= jj+ii; else if(settype==2) jj2= jj-ii; else if(settype==3) jj2= jj*ii; else if(settype==4) { if(ii==0) jj2= LONG_MAX; else if(jj==0) jj2= 0; else jj2= jj/ii; } /* output */ if(setoutall==0) { if(jj2!=LONG_MAX) printf("%ld\n",jj2); else printf("inf\n"); } else { for(ii=0;ii<nwords;ii++) { if(ii>0) printf("\t"); if(ii==coly) { if(jj2!=LONG_MAX) printf("%ld",jj2); else printf("inf"); } else printf("%s",(line+iword[ii])); } printf("\n"); } } } // end of while lineread if(strcmp(infile,"stdin")!=0) fclose(fpin); /* CLEANUP AND EXIT */ if(iword!=NULL) free(iword); if(line!=NULL) free(line); if(templine!=NULL) free(templine); exit(0); }
746818.c
#include "e.h" #include "e_mod_main.h" static void _battery_dbus_battery_props(void *data, void *reply_data, DBusError *error); static void _battery_dbus_ac_adapter_props(void *data, void *reply_data, DBusError *error); static void _battery_dbus_battery_property_changed(void *data, DBusMessage *msg); static void _battery_dbus_battery_add(const char *udi); static void _battery_dbus_battery_del(const char *udi); static void _battery_dbus_ac_adapter_add(const char *udi); static void _battery_dbus_ac_adapter_del(const char *udi); static void _battery_dbus_find_battery(void *user_data, void *reply_data, DBusError *err); static void _battery_dbus_find_ac(void *user_data, void *reply_data, DBusError *err); static void _battery_dbus_is_battery(void *user_data, void *reply_data, DBusError *err); static void _battery_dbus_is_ac_adapter(void *user_data, void *reply_data, DBusError *err); static void _battery_dbus_dev_add(void *data, DBusMessage *msg); static void _battery_dbus_dev_del(void *data, DBusMessage *msg); extern Eina_List *device_batteries; extern Eina_List *device_ac_adapters; extern double init_time; static E_DBus_Connection *e_dbus_conn = NULL; int _battery_dbus_start(void) { e_dbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM); if (!e_dbus_conn) return 0; // FIXME: e_dbus doesn't allow us to track this pending call e_hal_manager_find_device_by_capability (e_dbus_conn, "battery", _battery_dbus_find_battery, NULL); e_hal_manager_find_device_by_capability (e_dbus_conn, "ac_adapter", _battery_dbus_find_ac, NULL); battery_config->dbus.dev_add = e_dbus_signal_handler_add(e_dbus_conn, E_HAL_SENDER, E_HAL_MANAGER_PATH, E_HAL_MANAGER_INTERFACE, "DeviceAdded", _battery_dbus_dev_add, NULL); battery_config->dbus.dev_del = e_dbus_signal_handler_add(e_dbus_conn, E_HAL_SENDER, E_HAL_MANAGER_PATH, E_HAL_MANAGER_INTERFACE, "DeviceRemoved", _battery_dbus_dev_del, NULL); init_time = ecore_time_get(); return 1; } void _battery_dbus_stop(void) { Ac_Adapter *ac; Battery *bat; if (!e_dbus_conn) return; if (battery_config->dbus.have) { dbus_pending_call_cancel(battery_config->dbus.have); battery_config->dbus.have = NULL; } if (battery_config->dbus.dev_add) { e_dbus_signal_handler_del(e_dbus_conn, battery_config->dbus.dev_add); battery_config->dbus.dev_add = NULL; } if (battery_config->dbus.dev_del) { e_dbus_signal_handler_del(e_dbus_conn, battery_config->dbus.dev_del); battery_config->dbus.dev_del = NULL; } EINA_LIST_FREE(device_ac_adapters, ac) { e_dbus_signal_handler_del(e_dbus_conn, ac->prop_change); eina_stringshare_del(ac->udi); eina_stringshare_del(ac->product); free(ac); } EINA_LIST_FREE(device_batteries, bat) { e_dbus_signal_handler_del(e_dbus_conn, bat->prop_change); eina_stringshare_del(bat->udi); eina_stringshare_del(bat->technology); eina_stringshare_del(bat->type); eina_stringshare_del(bat->charge_units); eina_stringshare_del(bat->model); eina_stringshare_del(bat->vendor); free(bat); } e_dbus_connection_close(e_dbus_conn); e_dbus_conn = NULL; } static void _battery_dbus_battery_props(void *data, void *reply_data, DBusError *error __UNUSED__) { E_Hal_Properties *ret = reply_data; Battery *bat = data; int err = 0; const char *str; if (dbus_error_is_set(error)) { dbus_error_free(error); return; } if (!ret) return; #undef GET_BOOL #undef GET_INT #undef GET_STR #define GET_BOOL(val, s) bat->val = e_hal_property_bool_get(ret, s, &err) #define GET_INT(val, s) bat->val = e_hal_property_int_get(ret, s, &err) #define GET_STR(val, s) \ if (bat->val) eina_stringshare_del(bat->val); \ bat->val = NULL; \ str = e_hal_property_string_get(ret, s, &err); \ if (str) \ { \ bat->val = eina_stringshare_ref(str); \ } GET_BOOL(present, "battery.present"); GET_STR(technology, "battery.reporting.technology"); GET_STR(model, "battery.model"); GET_STR(vendor, "battery.vendor"); GET_STR(type, "battery.type"); GET_STR(charge_units, "battery.reporting.unit"); GET_INT(percent, "battery.charge_level.percentage"); GET_BOOL(can_charge, "battery.is_rechargeable"); GET_INT(current_charge, "battery.charge_level.current"); GET_INT(charge_rate, "battery.charge_level.rate"); GET_INT(design_charge, "battery.charge_level.design"); GET_INT(last_full_charge, "battery.charge_level.last_full"); if (e_hal_property_bool_get(ret, "battery.rechargeable.is_charging", &err)) { bat->charging = 1; GET_INT(time_full, "battery.remaining_time"); bat->time_left = -1; } else { bat->charging = 0; GET_INT(time_left, "battery.remaining_time"); bat->time_full = -1; } bat->got_prop = 1; _battery_device_update(); } static void _battery_dbus_ac_adapter_props(void *data, void *reply_data, DBusError *error __UNUSED__) { E_Hal_Properties *ret = reply_data; Ac_Adapter *ac = data; int err = 0; const char *str; if (dbus_error_is_set(error)) { dbus_error_free(error); return; } if (!ret) return; #undef GET_BOOL #undef GET_STR #define GET_BOOL(val, s) ac->val = e_hal_property_bool_get(ret, s, &err) #define GET_STR(val, s) \ if (ac->val) eina_stringshare_del(ac->val); \ ac->val = NULL; \ str = e_hal_property_string_get(ret, s, &err); \ if (str) \ { \ ac->val = eina_stringshare_ref(str); \ } GET_BOOL(present, "ac_adapter.present"); GET_STR(product, "info.product"); _battery_device_update(); } static void _battery_dbus_battery_property_changed(void *data, DBusMessage *msg __UNUSED__) { // FIXME: e_dbus doesn't allow us to track this pending call e_hal_device_get_all_properties(e_dbus_conn, ((Battery *)data)->udi, _battery_dbus_battery_props, data); } static void _battery_dbus_ac_adapter_property_changed(void *data, DBusMessage *msg __UNUSED__) { // FIXME: e_dbus doesn't allow us to track this pending call e_hal_device_get_all_properties(e_dbus_conn, ((Ac_Adapter *)data)->udi, _battery_dbus_ac_adapter_props, data); } static void _battery_dbus_battery_add(const char *udi) { Battery *bat; bat = _battery_battery_find(udi); if (!bat) { bat = E_NEW(Battery, 1); if (!bat) return; bat->udi = eina_stringshare_add(udi); device_batteries = eina_list_append(device_batteries, bat); bat->prop_change = e_dbus_signal_handler_add(e_dbus_conn, E_HAL_SENDER, udi, E_HAL_DEVICE_INTERFACE, "PropertyModified", _battery_dbus_battery_property_changed, bat); } // FIXME: e_dbus doesn't allow us to track this pending call e_hal_device_get_all_properties(e_dbus_conn, udi, _battery_dbus_battery_props, bat); _battery_device_update(); } static void _battery_dbus_battery_del(const char *udi) { Battery *bat; bat = _battery_battery_find(udi); if (bat) { e_dbus_signal_handler_del(e_dbus_conn, bat->prop_change); device_batteries = eina_list_remove(device_batteries, bat); eina_stringshare_del(bat->udi); eina_stringshare_del(bat->technology); eina_stringshare_del(bat->type); eina_stringshare_del(bat->charge_units); eina_stringshare_del(bat->model); eina_stringshare_del(bat->vendor); free(bat); return; } _battery_device_update(); } static void _battery_dbus_ac_adapter_add(const char *udi) { Ac_Adapter *ac; ac = E_NEW(Ac_Adapter, 1); if (!ac) return; ac->udi = eina_stringshare_add(udi); device_ac_adapters = eina_list_append(device_ac_adapters, ac); ac->prop_change = e_dbus_signal_handler_add(e_dbus_conn, E_HAL_SENDER, udi, E_HAL_DEVICE_INTERFACE, "PropertyModified", _battery_dbus_ac_adapter_property_changed, ac); // FIXME: e_dbus doesn't allow us to track this pending call e_hal_device_get_all_properties(e_dbus_conn, udi, _battery_dbus_ac_adapter_props, ac); _battery_device_update(); } static void _battery_dbus_ac_adapter_del(const char *udi) { Ac_Adapter *ac; ac = _battery_ac_adapter_find(udi); if (ac) { e_dbus_signal_handler_del(e_dbus_conn, ac->prop_change); device_ac_adapters = eina_list_remove(device_ac_adapters, ac); eina_stringshare_del(ac->udi); eina_stringshare_del(ac->product); free(ac); return; } _battery_device_update(); } static void _battery_dbus_find_battery(void *user_data __UNUSED__, void *reply_data, DBusError *err __UNUSED__) { Eina_List *l; char *device; E_Hal_Manager_Find_Device_By_Capability_Return *ret; ret = reply_data; if (dbus_error_is_set(err)) { dbus_error_free(err); return; } if (!ret) return; if (eina_list_count(ret->strings) < 1) return; EINA_LIST_FOREACH(ret->strings, l, device) _battery_dbus_battery_add(device); } static void _battery_dbus_find_ac(void *user_data __UNUSED__, void *reply_data, DBusError *err __UNUSED__) { Eina_List *l; char *device; E_Hal_Manager_Find_Device_By_Capability_Return *ret; ret = reply_data; if (dbus_error_is_set(err)) { dbus_error_free(err); return; } if (!ret) return; if (eina_list_count(ret->strings) < 1) return; EINA_LIST_FOREACH(ret->strings, l, device) _battery_dbus_ac_adapter_add(device); } static void _battery_dbus_is_battery(void *user_data, void *reply_data, DBusError *err) { char *udi = user_data; E_Hal_Device_Query_Capability_Return *ret; ret = reply_data; if (dbus_error_is_set(err)) { dbus_error_free(err); goto error; } if (!ret) goto error; if (ret->boolean) _battery_dbus_battery_add(udi); error: eina_stringshare_del(udi); } static void _battery_dbus_is_ac_adapter(void *user_data, void *reply_data, DBusError *err) { char *udi = user_data; E_Hal_Device_Query_Capability_Return *ret; ret = reply_data; if (dbus_error_is_set(err)) { dbus_error_free(err); goto error; } if (!ret) goto error; if (ret->boolean) _battery_dbus_ac_adapter_add(udi); error: eina_stringshare_del(udi); } static void _battery_dbus_dev_add(void *data __UNUSED__, DBusMessage *msg) { DBusError err; char *udi = NULL; dbus_error_init(&err); dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID); if (!udi) return; // FIXME: e_dbus doesn't allow us to track this pending call e_hal_device_query_capability(e_dbus_conn, udi, "battery", _battery_dbus_is_battery, (void*)eina_stringshare_add(udi)); e_hal_device_query_capability(e_dbus_conn, udi, "ac_adapter", _battery_dbus_is_ac_adapter, (void*)eina_stringshare_add(udi)); } static void _battery_dbus_dev_del(void *data __UNUSED__, DBusMessage *msg) { DBusError err; char *udi = NULL; dbus_error_init(&err); dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID); if (!udi) return; _battery_dbus_battery_del(udi); _battery_dbus_ac_adapter_del(udi); }
708694.c
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "lily.h" extern StructCode *code; extern int code_line; extern int main_enter; extern int main_stack; static int bp; //base pointer static int sp; //stack pointer static int *mem; //memory void init_vm() { mem = malloc(sizeof(int)*MEMORY_TOP); if(!mem){ fprintf(stderr,"malloc memory error\n"); exit(0); } sp = main_stack; bp = STACK_BASE; } #define IN_JUMP(x) \ x == OP_UJP || \ x == OP_FJP || \ x == OP_LEQ || \ x == OP_LES || \ x == OP_GRT || \ x == OP_GEQ || \ x == OP_EQU || x == OP_NEQ #define JMP 1 // i = code[i].value #define INC4(x) do{ \ x += 4; \ } while ( 0 ) #define DEC4(x) do { \ x -= 4; \ } while ( 0 ) typedef struct PointerStack{ int bp; int sp; }PointerStack; int ptop = 0; PointerStack pstack[100]; void start_vm() { int i = main_enter; int old_bp, old_sp, param_offset, auto_offset; int stack[100];//stack for save args int return_value, not_main_return = false; int j, top, x, offset_addr; int current_code = -1; while(code[i].op != OP_STP) { if(IN_JUMP(code[i].op) || code[i].op == OP_CAL){ if(code[i].op == OP_CAL){ if(code[i].value == -11){ scanf("%d", &mem[mem[bp+sp-1]]); sp-=1; i++; }else if(code[i].value == -12){ if(code[i-1].op == OP_LDC || code[i-1].op == OP_IND){ printf("%d", mem[bp+sp-1]); }else{ printf("%d", mem[mem[bp+sp-1]]); } sp-=1; i++; }else{ /* save current code */ current_code = i; not_main_return = true; /* save args */ top = 0; j = param_offset; while(j--){ stack[top++] = mem[bp+sp-1]; sp--; } /* for(j = i-1, top = 0; code[j].op != OP_MST; j--){ if(code[j].op == OP_LOD){ if(code[j].value >= STACK_BASE){ offset_addr = code[j].value - STACK_BASE; } stack[top++] = mem[bp+offset_addr]; }else{ // OP_LDA // not support yet } sp--; }*/ /* save old stack bp sp*/ pstack[ptop].bp = bp; pstack[ptop].sp = sp; ptop++; /* change stack */ bp += FUNCTION_SEGMENT; /* args to param */ x = bp; while(top){ mem[x++] = stack[top-1]; top--; } /* change sp */ sp = auto_offset + param_offset; /* jump to function code */ i = code[i].value; } }else{ switch(code[i].op) { case OP_UJP: i = code[i].value; break; case OP_FJP: if(!mem[bp+sp-1]){ i = code[i].value; }else{ i++; } sp -= 1; break; case OP_LEQ: if(mem[bp+sp-2] <= mem[bp+sp-1]){ i = code[i].value; }else{ i++; } sp -= 2; break; case OP_LES:// if(mem[bp+sp-2] < mem[bp+sp-1]){ i = code[i].value; }else{ i++; } sp -= 2; break; case OP_GRT: if(mem[bp+sp-2] > mem[bp+sp-1]){ i = code[i].value; }else{ i++; } sp -= 2; break; case OP_GEQ: if(mem[bp+sp-2] >= mem[bp+sp-1]){ i = code[i].value; }else{ i++; } sp -= 2; break; case OP_EQU: if(mem[bp+sp-2] == mem[bp+sp-1]){ i = code[i].value; }else{ i++; } sp -= 2; break; case OP_NEQ: if(mem[bp+sp-2] != mem[bp+sp-1]){ i = code[i].value; }else{ i++; } sp -= 2; break; default: break; } } } else { switch(code[i].op) { case OP_LDA: if(code[i].value >= STACK_BASE){ offset_addr = code[i].value - STACK_BASE; mem[bp+sp] = bp + offset_addr; }else{ mem[bp+sp] = code[i].value; } sp++; break; case OP_LDC: mem[bp+sp] = code[i].value; sp++; break; case OP_LOD: if(code[i].value >= STACK_BASE){ offset_addr = code[i].value - STACK_BASE; mem[bp+sp] = mem[bp+offset_addr]; }else{ mem[bp+sp] = mem[code[i].value]; } sp++; break; case OP_STO: mem[mem[bp+sp-2]] = mem[bp+sp-1]; sp-=2; break; case OP_STN: mem[mem[bp+sp-2]] = mem[bp+sp-1]; sp--; break; case OP_IND: mem[bp+sp-1] = mem[mem[bp+sp-1]+code[i].value]; break; case OP_IXA: mem[bp+sp-2] += (code[i].value * mem[bp+sp-1]); sp--; break; case OP_MPI: mem[bp+sp-2] = mem[bp+sp-2] * mem[bp+sp-1]; sp-=1; break; case OP_SBI: mem[bp+sp-2] = mem[bp+sp-2] - mem[bp+sp-1]; sp-=1; break; case OP_ADI: mem[bp+sp-2] = mem[bp+sp-2] + mem[bp+sp-1]; sp-=1; break; case OP_DVI: mem[bp+sp-2] = mem[bp+sp-2] / mem[bp+sp-1]; sp-=1; break; case OP_LAB: //do nothing break; case OP_ENT: //sp = code[i].value; break; case OP_MST: auto_offset = code[i].value / 10000; param_offset = code[i].value % 10000; break; case OP_RET: return_value = mem[bp+sp-1]; bp = pstack[ptop-1].bp; sp = pstack[ptop-1].sp; ptop--; mem[bp+sp] = return_value; sp++; if(not_main_return){ i = current_code; not_main_return = false; } break; default: fprintf(stderr, "Not exist OP\n"); break; } i++; } } }
281245.c
#include <avr/io.h> #include <avr/interrupt.h> unsigned int cnt = 0; ISR(TIMER1_OVF_vect) { cnt++; if(cnt>100) { cnt=0; PORTB ^= 0x01; // Toggle the LED connected to pin 14 } } int main(void) { // Set PORTB 0 pin as output, turn it off DDRB = 0x01; PORTB = 0x00; // Turn on timer with no prescaler on the clock for fastest // triggering of the interrupt service routine. TCCR1B |= _BV(CS10); TIMSK1 |= _BV(TOIE1); sei(); // Turn interrupts on. while (1) { } }