this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Simplifying handle_features and replacing sprintf with copyout_string

+36 -35
+36 -35
src/kernel/emulation/linux/misc/sysctl_machdep.c
··· 57 57 unsigned int ecx 58 58 #endif 59 59 60 + 61 + inline void copyout_int(int value, char* to_copy, int to_copy_leng) 62 + { 63 + char tmp[64]; 64 + __simple_sprintf(tmp, "%d", value); 65 + copyout_string(tmp, to_copy, to_copy_leng); 66 + } 67 + 68 + 60 69 sysctl_handler(handle_vendor) 61 70 { 62 71 unsigned int level = 0; ··· 88 97 __cpuid(level, eax, ebx, ecx, edx); 89 98 90 99 91 - sprintf(old,"%d",eax); 100 + 101 + 102 + copyout_int(eax, (char*)old,oldlen); 92 103 93 104 return 0; 94 105 } ··· 102 113 eax = eax >> 7; 103 114 eax &= 15; 104 115 105 - sprintf(old,"%d",eax); 116 + copyout_string(old,"%d",eax); 106 117 107 118 return 0; 108 119 } ··· 116 127 eax = eax >> 3; 117 128 eax &= 15; 118 129 119 - __simple_sprintf(old,"%d",eax); 130 + copyout_int(eax,(char*)old, oldlen); 120 131 121 132 return 0; 122 133 } ··· 129 140 130 141 eax &= 15; 131 142 132 - sprintf(old,"%d",eax); 143 + copyout_int(eax,(char*)old, oldlen); 133 144 134 145 return 0; 135 146 } ··· 168 179 } 169 180 sysctl_handler(handle_features) 170 181 { 171 - setup(1); 172 182 173 - char *features[] = {"FPU","VME", "DE", "PSE", "TSC", "MSR", "PAE", "MCE", "CX8", "APIC", NULL,"SEP","MTRR","PGE", 174 - "MCA", "CMOV", "PSE-36", "PSN", "CLFSH", NULL, "DS", "ACPI", "MMX", "FXSR", "SSE", "SSE2", "SS", 175 - "HTT", "TM","IA64","PBE"}; 183 + if(old != NULL) 184 + { 185 + setup(1); 176 186 177 - char *out = ""; //"worst" case: we have all of it plus null termination 187 + char features[][] = {"FPU","VME", "DE", "PSE", "TSC", "MSR", "PAE", "MCE", "CX8", "APIC", "","SEP","MTRR","PGE", 188 + "MCA", "CMOV", "PAT", "PSE-36", "PSN", "CLFSH", "", "DS", "ACPI", "MMX", "FXSR", "SSE", "SSE2", "SS", 189 + "HTT", "TM","IA64","PBE"}; 178 190 179 - __cpuid(0,eax,ebx,ecx,edx); 191 + __cpuid(0,eax,ebx,ecx,edx); 180 192 181 - int j = 0; 182 - int counter = 0; 193 + int counter = 0; 194 + int current_old_len = __simple_strlen(old); 183 195 184 - for (int i = 0; i < 32; i++) 185 - { 186 - if(edx>>i&1) 196 + for (int i = 0; i < 32; i++) 187 197 { 188 - int len = __simple_strlen(features[i]); 189 - int out_len = ____simple_strlen(out); 190 - char *new_out = alloca((len+out_len+1)*sizeof(char)) 191 - for(j=0; j < out_len; j++) 192 - { 193 - new_out[j] = out[j]; 194 - } 198 + 199 + if(i == 10 || i == 20) 200 + continue; 195 201 196 - for(j=0; j < len; j++) 202 + if(edx>>i&1 && current_old_len < oldlen) 197 203 { 198 - new_out[counter+j] = features[i][j]; 199 - } 204 + int len = __simple_strlen(features[i]); 205 + __simple_sprintf(old,"%s %s",old,features[i]); 200 206 201 - counter = counter + j; 207 + counter = counter + len + 1; 202 208 203 - new_out[counter] = ' '; 209 + current_old_len = __simple_strlen(old); 204 210 205 - out=new_out; 211 + } 212 + } 206 213 207 - counter++; 208 - 209 - } 214 + 210 215 } 211 - 212 - out[counter] = 0; 213 - 214 - copyout_string(out,(char*) old, oldlen); 215 216 216 217 return 0; 217 218