Example #1
0
  // sceKernelAllocMemoryBlock (internal name)
  @HLEFunction(nid = 0xFE707FDF, version = 352)
  public int SysMemUserForUser_FE707FDF(
      @StringInfo(maxLength = 32) PspString name,
      int type,
      int size,
      @CanBeNull TPointer paramsAddr) {
    if (paramsAddr.isNotNull()) {
      int length = paramsAddr.getValue32();
      if (length != 4) {
        log.warn(
            String.format("SysMemUserForUser_FE707FDF: unknown parameters with length=%d", length));
      }
    }

    if (type < PSP_SMEM_Low || type > PSP_SMEM_High) {
      return SceKernelErrors.ERROR_KERNEL_ILLEGAL_MEMBLOCK_ALLOC_TYPE;
    }

    // Always allocate memory in user area (partitionid == 2).
    SysMemInfo info = malloc(SysMemUserForUser.USER_PARTITION_ID, name.getString(), type, size, 0);
    if (info == null) {
      return SceKernelErrors.ERROR_KERNEL_FAILED_ALLOC_MEMBLOCK;
    }

    return info.uid;
  }
Example #2
0
  public int hleKernelPrintf(
      CpuState cpu, PspString formatString, Logger logger, String sceFunctionName) {
    // Format and print the message to stdout
    if (logger.isInfoEnabled()) {
      String formattedMsg = formatString.getString();
      try {
        // For now, use only the 7 register parameters: $a1-$a3, $t0-$t3
        // Further parameters should be retrieved from the stack.
        Object[] formatParameters =
            new Object[] {cpu._a1, cpu._a2, cpu._a3, cpu._t0, cpu._t1, cpu._t2, cpu._t3};

        // Translate the C-like format string to a Java format string:
        // - %u or %i -> %d
        // - %4u -> %4d
        // - %lld or %ld -> %d
        // - %p -> %08X
        String javaMsg = formatString.getString();
        javaMsg = javaMsg.replaceAll("\\%(\\d*)l?l?[uid]", "%$1d");
        javaMsg = javaMsg.replaceAll("\\%p", "%08X");

        // Support for "%s" (at any place and can occur multiple times)
        int index = -1;
        for (int parameterIndex = 0; parameterIndex < formatParameters.length; parameterIndex++) {
          index = javaMsg.indexOf('%', index + 1);
          if (index < 0) {
            break;
          }
          String parameterFormat = javaMsg.substring(index);
          if (parameterFormat.startsWith("%s")) {
            // Convert an integer address to a String by reading
            // the String at the given address
            formatParameters[parameterIndex] =
                Utilities.readStringZ(((Integer) formatParameters[parameterIndex]).intValue());
          }
        }

        // String.format: If there are more arguments than format specifiers, the extra arguments
        // are ignored.
        formattedMsg = String.format(javaMsg, formatParameters);
      } catch (Exception e) {
        // Ignore formatting exception
      }
      logger.info(formattedMsg);
    }

    return 0;
  }