4673 return 0;
4674 }
4675 *bytes = end - cur;
4676 return 1;
4677 }
4678
4679 int os::socket_available(int fd, jint *pbytes) {
4680 // Linux doc says EINTR not returned, unlike Solaris
4681 int ret = ::ioctl(fd, FIONREAD, pbytes);
4682
4683 //%% note ioctl can return 0 when successful, JVM_SocketAvailable
4684 // is expected to return 0 on failure and 1 on success to the jdk.
4685 return (ret < 0) ? 0 : 1;
4686 }
4687
4688 // Map a block of memory.
4689 char* os::map_memory(int fd, const char* file_name, size_t file_offset,
4690 char *addr, size_t bytes, bool read_only,
4691 bool allow_exec) {
4692 int prot;
4693 int flags;
4694
4695 if (read_only) {
4696 prot = PROT_READ;
4697 flags = MAP_SHARED;
4698 } else {
4699 prot = PROT_READ | PROT_WRITE;
4700 flags = MAP_PRIVATE;
4701 }
4702
4703 if (allow_exec) {
4704 prot |= PROT_EXEC;
4705 }
4706
4707 if (addr != NULL) {
4708 flags |= MAP_FIXED;
4709 }
4710
4711 char* mapped_address = (char*)mmap(addr, (size_t)bytes, prot, flags,
4712 fd, file_offset);
4713 if (mapped_address == MAP_FAILED) {
4714 return NULL;
4715 }
4716 return mapped_address;
4717 }
4718
4719
4720 // Remap a block of memory.
|
4673 return 0;
4674 }
4675 *bytes = end - cur;
4676 return 1;
4677 }
4678
4679 int os::socket_available(int fd, jint *pbytes) {
4680 // Linux doc says EINTR not returned, unlike Solaris
4681 int ret = ::ioctl(fd, FIONREAD, pbytes);
4682
4683 //%% note ioctl can return 0 when successful, JVM_SocketAvailable
4684 // is expected to return 0 on failure and 1 on success to the jdk.
4685 return (ret < 0) ? 0 : 1;
4686 }
4687
4688 // Map a block of memory.
4689 char* os::map_memory(int fd, const char* file_name, size_t file_offset,
4690 char *addr, size_t bytes, bool read_only,
4691 bool allow_exec) {
4692 int prot;
4693 int flags = MAP_PRIVATE;
4694
4695 if (read_only) {
4696 prot = PROT_READ;
4697 } else {
4698 prot = PROT_READ | PROT_WRITE;
4699 }
4700
4701 if (allow_exec) {
4702 prot |= PROT_EXEC;
4703 }
4704
4705 if (addr != NULL) {
4706 flags |= MAP_FIXED;
4707 }
4708
4709 char* mapped_address = (char*)mmap(addr, (size_t)bytes, prot, flags,
4710 fd, file_offset);
4711 if (mapped_address == MAP_FAILED) {
4712 return NULL;
4713 }
4714 return mapped_address;
4715 }
4716
4717
4718 // Remap a block of memory.
|