Differences between Hongmeng Kernel Standard Library and Linux Standard Library

This article describes the key differences between the standard library hosted by the OpenHarmony kernel and the Linux standard library.

process

  1. OpenHarmony user mode process priority only supports static priority and the user mode configurable priority range is 10 (highest priority)-31 (lowest priority).
  2. OpenHarmony user mode thread priority only supports static priority and the user mode configurable priority range is 0 (highest priority)-31 (lowest priority).
  3. The OpenHarmony scheduling strategy supports SCHED_RR and SCHED_FIFO.
  4. sched_yield() is the process actively giving up the CPU; thrd_yield() is the thread actively giving up the CPU.

RAM

Differences with Linux mmap

The prototype of mmap interface is: void *mmap (void *addr, size_t length, int prot, int flags, int fd, off_t offset).

Among them, the life cycle of the parameter fd is different from that of Linux glibc. Specifically, glibc can release the fd handle immediately after successfully calling mmap for mapping. In the OpenHarmony kernel, users are not allowed to close the related fd immediately after the mapping is successful, and only allow the close operation of fd after unmapping munmap. If the user does not perform the close operation of fd, the operating system will reclaim the fd when the process exits.

Code example

Linux currently supports the following conditions:

int main(int argc, char *argv[])
{
    int fd;
    void *addr = NULL;
    ...
    fd = open(argv[1], O_RDONLY);
    if (fd == -1){
        perror("open");
        exit(EXIT_FAILURE);
    }
    addr = mmap(NULL, length, PROT_READ, MAP_PRIVATE, fd, offset);
    if (addr == MAP_FAILED) {
        perror("mmap");
        exit(EXIT_FAILURE);
    }
    close(fd); /* close immediately, OpenHarmony do not support this way */ 
    ...
    exit(EXIT_SUCCESS);
}

OpenHarmony supports the following situations:

int main(int argc, char *argv[])
{
    int fd;
    void *addr = NULL;
    ...
    fd = open(argv[1], O_RDONLY);
    if (fd == -1){
        perror("open");
        exit(EXIT_FAILURE);
    }
    addr = mmap(NULL, length, PROT_READ, MAP_PRIVATE, fd, offset);
    if (addr == MAP_FAILED) {
        perror("mmap");
        exit(EXIT_FAILURE);
    }
    ...
    munmap(addr, length);
    close(fd); /* close after munmap */
    exit(EXIT_SUCCESS);
}

File system

**System Directory: **Users cannot modify it or mount the device. Contains /dev, /proc, /app, /bin, /data, /etc, /lib, /system, /usr directories.

User directory: The user can create, read and write files in this directory, but cannot mount the device . The user directory refers to the /storage directory.

In addition to system directories and user directories , users can create folders by themselves to mount devices. However, please note that the mounted folder and its subfolders are not allowed to be mounted repeatedly or nested, and non-empty folders are not allowed to be mounted.

signal

  • The default behavior of the signal does not support STOP, CONTINUE, and COREDUMP functions.
  • It is not possible to wake up a process that is sleeping (for example: the process calls the sleep function to enter sleep) through a signal. Reason: The signal mechanism has no wake-up function, and the signal content can be processed if and only when the process is scheduled to run by the CPU.
  • After the process exits, SIGCHLD will be sent to the parent process, and the sending action cannot be cancelled.
  • The signal only supports signals 1-30. The receiver receives the same signal multiple times and only executes the callback function once.

Time

The current time accuracy of OpenHarmony is calculated in tick, and the system defaults to 10ms/tick. The time error of sleep and timeout series functions is <=20ms.

Guess you like

Origin blog.csdn.net/qq_46388795/article/details/108532557