RFR: 8262491: AArch64: CPU description should contain compatible board list [v6]
Yasumasa Suenaga
ysuenaga at openjdk.java.net
Wed Mar 10 23:52:06 UTC 2021
On Wed, 10 Mar 2021 18:00:10 GMT, Andrew Haley <aph at openjdk.org> wrote:
>> Thanks for your comment! I pushed new commit.
>>
>> I issue `read()` with `buflen - 1` bytes, then I set `\0' to tail of `buf` after `read()`. And also `\0` will be converted to blank will happen when `read()` return 1 or greater. How about it?
>
> I think you need this to cope with errors, empty files, and so on:
>
> void VM_Version::get_compatible_board(char *buf, int buflen) {
> assert(buf != NULL, "invalid argument");
> assert(buflen >= 1, "invalid argument");
> *buf = '\0';
> int fd = open("/proc/device-tree/compatible", O_RDONLY);
> ssize_t read_sz = read(fd, buf, buflen - 1);
> if (read_sz >= 0) {
> buf[read_sz] = '\0';
> // Replace '\0' to ' '
> for (char *ch = buf; ch < buf + read_sz; ch++) {
> if (*ch == '\0') {
> *ch = ' ';
> }
> }
> } else { // read() retuned an error
> buf[0] = '\0';
> }
> =>close(fd);
> }
I updated PR, but it is different from your suggestion a bit. This version would return empty string when `open()` or `read()` returns error, and also `close()` would be called when `open()` succeeded.
Did you say we can call `read()` and `close()` even if `open()` failed? According to manpage, it seems to work (just return EBADF), but I feel strange a bit. If it is ok, I will do so.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2759
More information about the hotspot-dev
mailing list