VirtualBox

Ignore:
Timestamp:
Feb 12, 2024 3:57:56 PM (12 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
161613
Message:

libpng-1.6.42: Applied and adjusted our libpng changes to 1.6.42. bugref:8515

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/libpng-1.6.42/contrib/mips-msa/linux.c

    r96425 r103316  
     1
    12/* contrib/mips-msa/linux.c
    23 *
     4 * Copyright (c) 2020-2023 Cosmin Truta
    35 * Copyright (c) 2016 Glenn Randers-Pehrson
    46 * Written by Mandar Sahastrabuddhe, 2016.
    5  * Last changed in libpng 1.6.25beta03 [August 29, 2016]
     7 * Updated by Sui Jingfeng, 2021.
    68 *
    79 * This code is released under the libpng license.
     
    911 * and license in png.h
    1012 *
    11  * SEE contrib/mips-msa/README before reporting bugs
     13 * On Linux, png_have_msa is implemented by reading the pseudo-file
     14 * "/proc/self/auxv".
     15 *
     16 * See contrib/mips-msa/README before reporting bugs.
    1217 *
    1318 * STATUS: SUPPORTED
    1419 * BUG REPORTS: [email protected]
    15  *
    16  * png_have_msa implemented for Linux by reading the widely available
    17  * pseudo-file /proc/cpuinfo.
    18  *
    19  * This code is strict ANSI-C and is probably moderately portable; it does
    20  * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.
    2120 */
    2221
    23 #include <stdio.h>
    24 #include <string.h>
     22#include <elf.h>
     23#include <fcntl.h>
    2524#include <stdlib.h>
     25#include <unistd.h>
    2626
    2727static int
    2828png_have_msa(png_structp png_ptr)
    2929{
    30    FILE *f = fopen("/proc/cpuinfo", "rb");
     30   Elf64_auxv_t aux;
     31   int fd;
     32   int has_msa = 0;
    3133
    32    char *string = "msa";
    33    char word[10];
     34   fd = open("/proc/self/auxv", O_RDONLY);
     35   if (fd >= 0)
     36   {
     37      while (read(fd, &aux, sizeof(Elf64_auxv_t)) == sizeof(Elf64_auxv_t))
     38      {
     39         if (aux.a_type == AT_HWCAP)
     40         {
     41            uint64_t hwcap = aux.a_un.a_val;
    3442
    35    if (f != NULL)
    36    {
    37       while(!feof(f))
    38       {
    39          int ch = fgetc(f);
    40          static int i = 0;
    41 
    42          while(!(ch <= 32))
    43          {
    44             word[i++] = ch;
    45             ch = fgetc(f);
     43            has_msa = (hwcap >> 1) & 1;
     44            break;
    4645         }
    47 
    48          int val = strcmp(string, word);
    49 
    50          if (val == 0)
    51             return 1;
    52 
    53          i = 0;
    54          memset(word, 0, 10);
    5546      }
    56 
    57       fclose(f);
     47      close(fd);
    5848   }
    5949#ifdef PNG_WARNINGS_SUPPORTED
    6050   else
    61       png_warning(png_ptr, "/proc/cpuinfo open failed");
     51      png_warning(png_ptr, "/proc/self/auxv open failed");
    6252#endif
    63    return 0;
     53
     54   return has_msa;
    6455}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette